use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project calcite by apache.
the class MultiJdbcSchemaJoinTest method testSchemaConsistency.
@Test
public void testSchemaConsistency() throws Exception {
// Create a database
final String db = TempDb.INSTANCE.getUrl();
Connection c1 = DriverManager.getConnection(db, "", "");
Statement stmt1 = c1.createStatement();
stmt1.execute("create table table1(id varchar(10) not null primary key, " + "field1 varchar(10))");
// Connect via calcite to these databases
Connection connection = DriverManager.getConnection("jdbc:calcite:");
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
SchemaPlus rootSchema = calciteConnection.getRootSchema();
final DataSource ds = JdbcSchema.dataSource(db, "org.hsqldb.jdbcDriver", "", "");
rootSchema.add("DB", JdbcSchema.create(rootSchema, "DB", ds, null, null));
Statement stmt3 = connection.createStatement();
ResultSet rs;
// fails, table does not exist
try {
rs = stmt3.executeQuery("select * from db.table2");
fail("expected error, got " + rs);
} catch (SQLException e) {
assertThat(e.getCause().getCause().getMessage(), equalTo("Object 'TABLE2' not found within 'DB'"));
}
stmt1.execute("create table table2(id varchar(10) not null primary key, " + "field1 varchar(10))");
stmt1.execute("insert into table2 values('a', 'aaaa')");
PreparedStatement stmt2 = connection.prepareStatement("select * from db.table2");
stmt1.execute("alter table table2 add column field2 varchar(10)");
// "field2" not visible to stmt2
rs = stmt2.executeQuery();
assertThat(CalciteAssert.toString(rs), equalTo("ID=a; FIELD1=aaaa\n"));
// "field2" visible to a new query
rs = stmt3.executeQuery("select * from db.table2");
assertThat(CalciteAssert.toString(rs), equalTo("ID=a; FIELD1=aaaa; FIELD2=null\n"));
c1.close();
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus 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.schema.SchemaPlus 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.schema.SchemaPlus 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;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project calcite by apache.
the class SqlCreateSchema method execute.
public void execute(CalcitePrepare.Context context) {
final Pair<CalciteSchema, String> pair = SqlDdlNodes.schema(context, true, name);
final SchemaPlus subSchema0 = pair.left.plus().getSubSchema(pair.right);
if (subSchema0 != null) {
if (!getReplace() && !ifNotExists) {
throw SqlUtil.newContextException(name.getParserPosition(), RESOURCE.schemaExists(pair.right));
}
}
final Schema subSchema = new AbstractSchema();
pair.left.add(pair.right, subSchema);
}
Aggregations