use of org.apache.calcite.schema.impl.AbstractSchema 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.calcite.schema.impl.AbstractSchema 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.calcite.schema.impl.AbstractSchema 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.calcite.schema.impl.AbstractSchema 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.calcite.schema.impl.AbstractSchema 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