Search in sources :

Example 76 with CalciteConnection

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteConnection in project calcite by apache.

the class CsvTest method testPrepared.

/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-1031">[CALCITE-1031]
 * In prepared statement, CsvScannableTable.scan is called twice</a>. To see
 * the bug, place a breakpoint in CsvScannableTable.scan, and note that it is
 * called twice. It should only be called once.
 */
@Test
public void testPrepared() throws SQLException {
    final Properties properties = new Properties();
    properties.setProperty("caseSensitive", "true");
    try (final Connection connection = DriverManager.getConnection("jdbc:calcite:", properties)) {
        final CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
        final Schema schema = CsvSchemaFactory.INSTANCE.create(calciteConnection.getRootSchema(), null, ImmutableMap.<String, Object>of("directory", resourcePath("sales"), "flavor", "scannable"));
        calciteConnection.getRootSchema().add("TEST", schema);
        final String sql = "select * from \"TEST\".\"DEPTS\" where \"NAME\" = ?";
        final PreparedStatement statement2 = calciteConnection.prepareStatement(sql);
        statement2.setString(1, "Sales");
        final ResultSet resultSet1 = statement2.executeQuery();
        Function<ResultSet, Void> expect = expect("DEPTNO=10; NAME=Sales");
        expect.apply(resultSet1);
    }
}
Also used : Schema(org.apache.calcite.schema.Schema) Connection(java.sql.Connection) CalciteConnection(org.apache.calcite.jdbc.CalciteConnection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Properties(java.util.Properties) CalciteConnection(org.apache.calcite.jdbc.CalciteConnection) Test(org.junit.Test)

Aggregations

CalciteConnection (org.apache.calcite.jdbc.CalciteConnection)65 Test (org.junit.Test)52 Connection (java.sql.Connection)51 ResultSet (java.sql.ResultSet)42 SchemaPlus (org.apache.calcite.schema.SchemaPlus)42 Statement (java.sql.Statement)32 PreparedStatement (java.sql.PreparedStatement)24 AbstractSchema (org.apache.calcite.schema.impl.AbstractSchema)22 Properties (java.util.Properties)17 ReflectiveSchema (org.apache.calcite.adapter.java.ReflectiveSchema)17 SQLException (java.sql.SQLException)16 AvaticaConnection (org.apache.calcite.avatica.AvaticaConnection)12 CalciteConnection (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteConnection)11 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)11 TableFunction (org.apache.calcite.schema.TableFunction)10 AvaticaStatement (org.apache.calcite.avatica.AvaticaStatement)9 org.hsqldb.jdbcDriver (org.hsqldb.jdbcDriver)5 AssertThat (org.apache.calcite.test.CalciteAssert.AssertThat)4 IOException (java.io.IOException)3 ResultSetMetaData (java.sql.ResultSetMetaData)3