use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project calcite by apache.
the class JdbcTest method testCloneSchema.
@Test
public void testCloneSchema() throws ClassNotFoundException, SQLException {
final Connection connection = CalciteAssert.that(CalciteAssert.Config.JDBC_FOODMART).connect();
final CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
final SchemaPlus rootSchema = calciteConnection.getRootSchema();
final SchemaPlus foodmart = rootSchema.getSubSchema("foodmart");
rootSchema.add("foodmart2", new CloneSchema(foodmart));
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("select count(*) from \"foodmart2\".\"time_by_day\"");
assertTrue(resultSet.next());
assertEquals(730, resultSet.getInt(1));
resultSet.close();
connection.close();
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project calcite by apache.
the class JdbcTest method testSimpleCalciteSchemaWithView.
@Test
public void testSimpleCalciteSchemaWithView() throws Exception {
final SchemaPlus rootSchema = CalciteSchema.createRootSchema(false, false).plus();
final Multimap<String, org.apache.calcite.schema.Function> functionMap = LinkedListMultimap.create();
// create schema "/a"
final SchemaPlus aSchema = rootSchema.add("a", new AbstractSchema() {
@Override
protected Multimap<String, org.apache.calcite.schema.Function> getFunctionMultimap() {
return functionMap;
}
});
// add view definition
final String viewName = "V";
final org.apache.calcite.schema.Function view = ViewTable.viewMacro(rootSchema.getSubSchema("a"), "values('1', '2')", null, null, false);
functionMap.put(viewName, view);
final CalciteSchema calciteSchema = CalciteSchema.from(aSchema);
assertThat(calciteSchema.getTableBasedOnNullaryFunction(viewName, true), notNullValue());
assertThat(calciteSchema.getTableBasedOnNullaryFunction(viewName, false), notNullValue());
assertThat(calciteSchema.getTableBasedOnNullaryFunction("V1", true), nullValue());
assertThat(calciteSchema.getTableBasedOnNullaryFunction("V1", false), nullValue());
assertThat(calciteSchema.getFunctions(viewName, true), hasItem(view));
assertThat(calciteSchema.getFunctions(viewName, false), hasItem(view));
assertThat(calciteSchema.getFunctions("V1", true), not(hasItem(view)));
assertThat(calciteSchema.getFunctions("V1", false), not(hasItem(view)));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project calcite by apache.
the class JdbcTest method testSimpleCalciteSchema.
@Test
public void testSimpleCalciteSchema() throws Exception {
final SchemaPlus rootSchema = CalciteSchema.createRootSchema(false, false).plus();
// create schema "/a"
final Map<String, Schema> aSubSchemaMap = new HashMap<>();
final SchemaPlus aSchema = rootSchema.add("a", new AbstractSchema() {
@Override
protected Map<String, Schema> getSubSchemaMap() {
return aSubSchemaMap;
}
});
// add explicit schema "/a/b".
aSchema.add("b", new AbstractSchema());
// add implicit schema "/a/c"
aSubSchemaMap.put("c", new AbstractSchema());
assertThat(aSchema.getSubSchema("c"), notNullValue());
assertThat(aSchema.getSubSchema("b"), notNullValue());
// add implicit schema "/a/b"
aSubSchemaMap.put("b", new AbstractSchema());
// explicit should win implicit.
assertThat(aSchema.getSubSchemaNames().size(), is(2));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project calcite by apache.
the class LinqFrontJdbcBackTest method testTableWhere.
@Test
public void testTableWhere() throws SQLException, ClassNotFoundException {
final Connection connection = CalciteAssert.that(CalciteAssert.Config.JDBC_FOODMART).connect();
final CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
final SchemaPlus rootSchema = calciteConnection.getRootSchema();
ParameterExpression c = Expressions.parameter(JdbcTest.Customer.class, "c");
String s = Schemas.queryable(Schemas.createDataContext(connection, rootSchema), rootSchema.getSubSchema("foodmart"), JdbcTest.Customer.class, "customer").where(Expressions.<Predicate1<JdbcTest.Customer>>lambda(Expressions.lessThan(Expressions.field(c, "customer_id"), Expressions.constant(5)), c)).toList().toString();
Util.discard(s);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project calcite by apache.
the class MultiJdbcSchemaJoinTest method setup.
private Connection setup() throws SQLException {
// Create a jdbc database & table
final String db = TempDb.INSTANCE.getUrl();
Connection c1 = DriverManager.getConnection(db, "", "");
Statement stmt1 = c1.createStatement();
// This is a table we can join with the emps from the hr schema
stmt1.execute("create table table1(id integer not null primary key, " + "field1 varchar(10))");
stmt1.execute("insert into table1 values(100, 'foo')");
stmt1.execute("insert into table1 values(200, 'bar')");
c1.close();
// Make a Calcite schema with both a jdbc schema and a non-jdbc schema
Connection connection = DriverManager.getConnection("jdbc:calcite:");
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
SchemaPlus rootSchema = calciteConnection.getRootSchema();
rootSchema.add("DB", JdbcSchema.create(rootSchema, "DB", JdbcSchema.dataSource(db, "org.hsqldb.jdbcDriver", "", ""), null, null));
rootSchema.add("hr", new ReflectiveSchema(new JdbcTest.HrSchema()));
return connection;
}
Aggregations