use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteConnection in project calcite by apache.
the class CollectionTypeTest method setupConnectionWithNestedAnyTypeTable.
private Connection setupConnectionWithNestedAnyTypeTable() throws SQLException {
Connection connection = DriverManager.getConnection("jdbc:calcite:");
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
SchemaPlus rootSchema = calciteConnection.getRootSchema();
SchemaPlus schema = rootSchema.add("s", new AbstractSchema());
schema.add("nested", new NestedCollectionWithAnyTypeTable());
return connection;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteConnection in project calcite by apache.
the class JdbcAdapterTest method testTableModifyUpdate.
@Test
public void testTableModifyUpdate() throws Exception {
final AssertThat that = CalciteAssert.model(JdbcTest.FOODMART_MODEL).enable(CalciteAssert.DB == DatabaseInstance.HSQLDB);
that.doWithConnection(new Function<CalciteConnection, Void>() {
public Void apply(CalciteConnection connection) {
try (LockWrapper ignore = exclusiveCleanDb(connection)) {
final String sql = "UPDATE \"foodmart\".\"expense_fact\"\n" + " SET \"account_id\"=888\n" + " WHERE \"store_id\"=666\n";
final String explain = "PLAN=JdbcToEnumerableConverter\n" + " JdbcTableModify(table=[[foodmart, expense_fact]], operation=[UPDATE], updateColumnList=[[account_id]], sourceExpressionList=[[888]], flattened=[false])\n" + " JdbcProject(store_id=[$0], account_id=[$1], exp_date=[$2], time_id=[$3], category_id=[$4], currency_id=[$5], amount=[$6], EXPR$0=[888])\n" + " JdbcFilter(condition=[=($0, 666)])\n" + " JdbcTableScan(table=[[foodmart, expense_fact]])";
final String jdbcSql = "UPDATE \"foodmart\".\"expense_fact\"" + " SET \"account_id\" = 888\n" + "WHERE \"store_id\" = 666";
that.query(sql).explainContains(explain).planUpdateHasSql(jdbcSql, 1);
return null;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
});
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteConnection in project calcite by apache.
the class JdbcAdapterTest method testJdbcAggregate.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-657">[CALCITE-657]
* NullPointerException when executing JdbcAggregate implement method</a>.
*/
@Test
public void testJdbcAggregate() throws Exception {
final String url = MultiJdbcSchemaJoinTest.TempDb.INSTANCE.getUrl();
Connection baseConnection = DriverManager.getConnection(url);
Statement baseStmt = baseConnection.createStatement();
baseStmt.execute("CREATE TABLE T2 (\n" + "ID INTEGER,\n" + "VALS INTEGER)");
baseStmt.execute("INSERT INTO T2 VALUES (1, 1)");
baseStmt.execute("INSERT INTO T2 VALUES (2, null)");
baseStmt.close();
baseConnection.commit();
Properties info = new Properties();
info.put("model", "inline:" + "{\n" + " version: '1.0',\n" + " defaultSchema: 'BASEJDBC',\n" + " schemas: [\n" + " {\n" + " type: 'jdbc',\n" + " name: 'BASEJDBC',\n" + " jdbcDriver: '" + jdbcDriver.class.getName() + "',\n" + " jdbcUrl: '" + url + "',\n" + " jdbcCatalog: null,\n" + " jdbcSchema: null\n" + " }\n" + " ]\n" + "}");
final Connection calciteConnection = DriverManager.getConnection("jdbc:calcite:", info);
ResultSet rs = calciteConnection.prepareStatement("select 10 * count(ID) from t2").executeQuery();
assertThat(rs.next(), is(true));
assertThat((Long) rs.getObject(1), equalTo(20L));
assertThat(rs.next(), is(false));
rs.close();
calciteConnection.close();
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteConnection in project calcite by apache.
the class JdbcFrontLinqBackTest method makePostProcessor.
/**
* Creates the post processor routine to be applied against a Connection.
*
* <p>Table schema is based on JdbcTest#Employee
* (refer to {@link JdbcFrontLinqBackTest#mutable}).
*
* @param initialData records to be presented in table
* @return a connection post-processor
*/
private static CalciteAssert.ConnectionPostProcessor makePostProcessor(final List<JdbcTest.Employee> initialData) {
return new CalciteAssert.ConnectionPostProcessor() {
public Connection apply(final Connection connection) throws SQLException {
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
SchemaPlus rootSchema = calciteConnection.getRootSchema();
SchemaPlus mapSchema = rootSchema.add("foo", new AbstractSchema());
final String tableName = "bar";
final JdbcTest.AbstractModifiableTable table = mutable(tableName, initialData);
mapSchema.add(tableName, table);
return calciteConnection;
}
};
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteConnection in project calcite by apache.
the class SplunkDriver method connect.
@Override
public Connection connect(String url, Properties info) throws SQLException {
Connection connection = super.connect(url, info);
CalciteConnection calciteConnection = (CalciteConnection) connection;
SplunkConnection splunkConnection;
try {
String url1 = info.getProperty("url");
if (url1 == null) {
throw new IllegalArgumentException("Must specify 'url' property");
}
if (url1.equals("mock")) {
splunkConnection = new MockSplunkConnection();
} else {
String user = info.getProperty("user");
if (user == null) {
throw new IllegalArgumentException("Must specify 'user' property");
}
String password = info.getProperty("password");
if (password == null) {
throw new IllegalArgumentException("Must specify 'password' property");
}
URL url2 = new URL(url1);
splunkConnection = new SplunkConnectionImpl(url2, user, password);
}
} catch (Exception e) {
throw new SQLException("Cannot connect", e);
}
final SchemaPlus rootSchema = calciteConnection.getRootSchema();
rootSchema.add("splunk", new SplunkSchema(splunkConnection));
return connection;
}
Aggregations