Search in sources :

Example 6 with AbstractSchema

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)));
}
Also used : SchemaPlus(org.apache.calcite.schema.SchemaPlus) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) TableFunction(org.apache.calcite.schema.TableFunction) SqlAdvisorGetHintsFunction(org.apache.calcite.sql.advise.SqlAdvisorGetHintsFunction) Function(com.google.common.base.Function) LinkedListMultimap(com.google.common.collect.LinkedListMultimap) Multimap(com.google.common.collect.Multimap) AbstractSchema(org.apache.calcite.schema.impl.AbstractSchema) CalciteSchema(org.apache.calcite.jdbc.CalciteSchema) Test(org.junit.Test)

Example 7 with AbstractSchema

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));
}
Also used : HashMap(java.util.HashMap) AbstractSchema(org.apache.calcite.schema.impl.AbstractSchema) Schema(org.apache.calcite.schema.Schema) CalciteSchema(org.apache.calcite.jdbc.CalciteSchema) JdbcSchema(org.apache.calcite.adapter.jdbc.JdbcSchema) ReflectiveSchema(org.apache.calcite.adapter.java.ReflectiveSchema) CloneSchema(org.apache.calcite.adapter.clone.CloneSchema) AbstractSchema(org.apache.calcite.schema.impl.AbstractSchema) SchemaPlus(org.apache.calcite.schema.SchemaPlus) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 8 with AbstractSchema

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;
}
Also used : AbstractSchema(org.apache.calcite.schema.impl.AbstractSchema) Connection(java.sql.Connection) CalciteConnection(org.apache.calcite.jdbc.CalciteConnection) SchemaPlus(org.apache.calcite.schema.SchemaPlus) CalciteConnection(org.apache.calcite.jdbc.CalciteConnection)

Example 9 with AbstractSchema

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;
        }
    };
}
Also used : AbstractSchema(org.apache.calcite.schema.impl.AbstractSchema) Connection(java.sql.Connection) CalciteConnection(org.apache.calcite.jdbc.CalciteConnection) SchemaPlus(org.apache.calcite.schema.SchemaPlus) CalciteConnection(org.apache.calcite.jdbc.CalciteConnection)

Example 10 with AbstractSchema

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);
}
Also used : AbstractSchema(org.apache.calcite.schema.impl.AbstractSchema) CalciteSchema(org.apache.calcite.jdbc.CalciteSchema) CalciteSchema(org.apache.calcite.jdbc.CalciteSchema) Schema(org.apache.calcite.schema.Schema) AbstractSchema(org.apache.calcite.schema.impl.AbstractSchema) SchemaPlus(org.apache.calcite.schema.SchemaPlus)

Aggregations

AbstractSchema (org.apache.calcite.schema.impl.AbstractSchema)33 SchemaPlus (org.apache.calcite.schema.SchemaPlus)30 Connection (java.sql.Connection)22 CalciteConnection (org.apache.calcite.jdbc.CalciteConnection)22 Test (org.junit.Test)20 ResultSet (java.sql.ResultSet)15 ReflectiveSchema (org.apache.calcite.adapter.java.ReflectiveSchema)10 TableFunction (org.apache.calcite.schema.TableFunction)10 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)8 Schema (org.apache.calcite.schema.Schema)6 PreparedStatement (java.sql.PreparedStatement)5 CalciteSchema (org.apache.calcite.jdbc.CalciteSchema)5 Statement (java.sql.Statement)4 CloneSchema (org.apache.calcite.adapter.clone.CloneSchema)4 AvaticaConnection (org.apache.calcite.avatica.AvaticaConnection)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 JdbcSchema (org.apache.calcite.adapter.jdbc.JdbcSchema)3 ProjectableFilterableTable (org.apache.calcite.schema.ProjectableFilterableTable)3 Table (org.apache.calcite.schema.Table)3