use of org.apache.calcite.jdbc.Driver in project calcite by apache.
the class JdbcTest method testStatementCloseOnCompletion.
/**
* Tests {@link java.sql.Statement}.{@code closeOnCompletion()}.
*/
@Test
public void testStatementCloseOnCompletion() throws Exception {
String javaVersion = System.getProperty("java.version");
if (javaVersion.compareTo("1.7") < 0) {
// Statement.closeOnCompletion was introduced in JDK 1.7.
return;
}
final Driver driver = new Driver();
CalciteConnection connection = (CalciteConnection) driver.connect("jdbc:calcite:", new Properties());
SchemaPlus rootSchema = connection.getRootSchema();
rootSchema.add("hr", new ReflectiveSchema(new HrSchema()));
connection.setSchema("hr");
final Statement statement = connection.createStatement();
assertFalse((Boolean) CalciteAssert.call(statement, "isCloseOnCompletion"));
CalciteAssert.call(statement, "closeOnCompletion");
assertTrue((Boolean) CalciteAssert.call(statement, "isCloseOnCompletion"));
final ResultSet resultSet = statement.executeQuery("select * from \"emps\"");
assertFalse(resultSet.isClosed());
assertFalse(statement.isClosed());
assertFalse(connection.isClosed());
// when result set is closed, statement is closed automatically
resultSet.close();
assertTrue(resultSet.isClosed());
assertTrue(statement.isClosed());
assertFalse(connection.isClosed());
connection.close();
assertTrue(resultSet.isClosed());
assertTrue(statement.isClosed());
assertTrue(connection.isClosed());
}
use of org.apache.calcite.jdbc.Driver in project calcite by apache.
the class ReflectiveSchemaTest method testReflectiveSchemaInUnnamedPackage.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-281">[CALCITE-1919]
* NPE when target in ReflectiveSchema belongs to the unnamed package</a>.
*/
@Test
public void testReflectiveSchemaInUnnamedPackage() throws Exception {
final Driver driver = new Driver();
try (CalciteConnection connection = (CalciteConnection) driver.connect("jdbc:calcite:", new Properties())) {
SchemaPlus rootSchema = connection.getRootSchema();
final Class<?> c = Class.forName("RootHr");
final Object o = c.getDeclaredConstructor().newInstance();
rootSchema.add("hr", new ReflectiveSchema(o));
connection.setSchema("hr");
final Statement statement = connection.createStatement();
final String sql = "select * from \"emps\"";
final ResultSet resultSet = statement.executeQuery(sql);
final String expected = "empid=100; name=Bill\n" + "empid=200; name=Eric\n" + "empid=150; name=Sebastian\n";
assertThat(CalciteAssert.toString(resultSet), is(expected));
}
}
use of org.apache.calcite.jdbc.Driver in project calcite by apache.
the class JdbcTest method testAggMultipleMeasures.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-1097">[CALCITE-1097]
* Exception when executing query with too many aggregation columns</a>.
*/
@Test
public void testAggMultipleMeasures() throws SQLException {
final Driver driver = new Driver();
CalciteConnection connection = (CalciteConnection) driver.connect("jdbc:calcite:", new Properties());
SchemaPlus rootSchema = connection.getRootSchema();
rootSchema.add("sale", new ReflectiveSchema(new Smalls.WideSaleSchema()));
connection.setSchema("sale");
final Statement statement = connection.createStatement();
// 200 columns: sum(sale0) + ... sum(sale199)
ResultSet resultSet = statement.executeQuery("select s.\"prodId\"" + sums(200, true) + "\n" + "from \"sale\".\"prod\" as s group by s.\"prodId\"\n");
assertThat(resultSet.next(), is(true));
assertThat(resultSet.getInt(1), is(100));
assertThat(resultSet.getInt(2), is(10));
assertThat(resultSet.getInt(200), is(10));
assertThat(resultSet.next(), is(false));
// 800 columns:
// sum(sale0 + 0) + ... + sum(sale0 + 100) + ... sum(sale99 + 799)
final int n = 800;
resultSet = statement.executeQuery("select s.\"prodId\"" + sums(n, false) + "\n" + "from \"sale\".\"prod\" as s group by s.\"prodId\"\n");
assertThat(resultSet.next(), is(true));
assertThat(resultSet.getInt(1), is(100));
assertThat(resultSet.getInt(2), is(10));
assertThat(resultSet.getInt(n), is(n + 8));
assertThat(resultSet.next(), is(false));
connection.close();
}
Aggregations