Search in sources :

Example 6 with Schema

use of org.apache.calcite.schema.Schema in project drill by axbaretto.

the class DynamicSchema method getImplicitSubSchema.

@Override
protected CalciteSchema getImplicitSubSchema(String schemaName, boolean caseSensitive) {
    Schema s = schema.getSubSchema(schemaName);
    if (s != null) {
        return new DynamicSchema(this, s, schemaName);
    }
    CalciteSchema ret = getSubSchemaMap().get(schemaName);
    return ret;
}
Also used : Schema(org.apache.calcite.schema.Schema)

Example 7 with Schema

use of org.apache.calcite.schema.Schema in project drill by axbaretto.

the class DynamicSchema method getSubSchema.

@Override
public CalciteSchema getSubSchema(String schemaName, boolean caseSensitive) {
    Schema s = schema.getSubSchema(schemaName);
    if (s != null) {
        return new DynamicSchema(this, s, schemaName);
    }
    CalciteSchema ret = getSubSchemaMap().get(schemaName);
    return ret;
}
Also used : CalciteSchema(org.apache.calcite.jdbc.CalciteSchema) SimpleCalciteSchema(org.apache.calcite.jdbc.SimpleCalciteSchema) Schema(org.apache.calcite.schema.Schema) CalciteSchema(org.apache.calcite.jdbc.CalciteSchema) SimpleCalciteSchema(org.apache.calcite.jdbc.SimpleCalciteSchema)

Example 8 with Schema

use of org.apache.calcite.schema.Schema in project calcite by apache.

the class CalciteSchema method createRootSchema.

/**
 * Creates a root schema.
 *
 * @param addMetadataSchema Whether to add a "metadata" schema containing
 *              definitions of tables, columns etc.
 * @param cache If true create {@link CachingCalciteSchema};
 *                if false create {@link SimpleCalciteSchema}
 * @param name Schema name
 */
public static CalciteSchema createRootSchema(boolean addMetadataSchema, boolean cache, String name) {
    CalciteSchema rootSchema;
    final Schema schema = new CalciteConnectionImpl.RootSchema();
    if (cache) {
        rootSchema = new CachingCalciteSchema(null, schema, name);
    } else {
        rootSchema = new SimpleCalciteSchema(null, schema, name);
    }
    if (addMetadataSchema) {
        rootSchema.add("metadata", MetadataSchema.INSTANCE);
    }
    return rootSchema;
}
Also used : Schema(org.apache.calcite.schema.Schema)

Example 9 with Schema

use of org.apache.calcite.schema.Schema in project calcite by apache.

the class JdbcTest method testExplicitImplicitSchemaSameName.

@Test
public void testExplicitImplicitSchemaSameName() throws Exception {
    final SchemaPlus rootSchema = CalciteSchema.createRootSchema(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/b"
    aSubSchemaMap.put("b", new AbstractSchema());
    aSchema.setCacheEnabled(true);
    // explicit should win implicit.
    assertThat(aSchema.getSubSchemaNames().size(), is(1));
}
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 10 with Schema

use of org.apache.calcite.schema.Schema in project calcite by apache.

the class ScannableTableTest method testPrepared2.

/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-1031">[CALCITE-1031]
 * In prepared statement, CsvScannableTable.scan is called twice</a>.
 */
@Test
public void testPrepared2() throws SQLException {
    final Properties properties = new Properties();
    properties.setProperty("caseSensitive", "true");
    try (final Connection connection = DriverManager.getConnection("jdbc:calcite:", properties)) {
        final CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
        final AtomicInteger scanCount = new AtomicInteger();
        final AtomicInteger enumerateCount = new AtomicInteger();
        final Schema schema = new AbstractSchema() {

            @Override
            protected Map<String, Table> getTableMap() {
                return ImmutableMap.<String, Table>of("TENS", new SimpleTable() {

                    private Enumerable<Object[]> superScan(DataContext root) {
                        return super.scan(root);
                    }

                    @Override
                    public Enumerable<Object[]> scan(final DataContext root) {
                        scanCount.incrementAndGet();
                        return new AbstractEnumerable<Object[]>() {

                            public Enumerator<Object[]> enumerator() {
                                enumerateCount.incrementAndGet();
                                return superScan(root).enumerator();
                            }
                        };
                    }
                });
            }
        };
        calciteConnection.getRootSchema().add("TEST", schema);
        final String sql = "select * from \"TEST\".\"TENS\" where \"i\" < ?";
        final PreparedStatement statement = calciteConnection.prepareStatement(sql);
        assertThat(scanCount.get(), is(0));
        assertThat(enumerateCount.get(), is(0));
        // First execute
        statement.setInt(1, 20);
        assertThat(scanCount.get(), is(0));
        ResultSet resultSet = statement.executeQuery();
        assertThat(scanCount.get(), is(1));
        assertThat(enumerateCount.get(), is(1));
        assertThat(resultSet, Matchers.returnsUnordered("i=0", "i=10"));
        assertThat(scanCount.get(), is(1));
        assertThat(enumerateCount.get(), is(1));
        // Second execute
        resultSet = statement.executeQuery();
        assertThat(scanCount.get(), is(2));
        assertThat(resultSet, Matchers.returnsUnordered("i=0", "i=10"));
        assertThat(scanCount.get(), is(2));
        // Third execute
        statement.setInt(1, 30);
        resultSet = statement.executeQuery();
        assertThat(scanCount.get(), is(3));
        assertThat(resultSet, Matchers.returnsUnordered("i=0", "i=10", "i=20"));
        assertThat(scanCount.get(), is(3));
    }
}
Also used : ProjectableFilterableTable(org.apache.calcite.schema.ProjectableFilterableTable) ScannableTable(org.apache.calcite.schema.ScannableTable) Table(org.apache.calcite.schema.Table) FilterableTable(org.apache.calcite.schema.FilterableTable) AbstractTable(org.apache.calcite.schema.impl.AbstractTable) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) Schema(org.apache.calcite.schema.Schema) AbstractSchema(org.apache.calcite.schema.impl.AbstractSchema) Connection(java.sql.Connection) CalciteConnection(org.apache.calcite.jdbc.CalciteConnection) PreparedStatement(java.sql.PreparedStatement) Properties(java.util.Properties) DataContext(org.apache.calcite.DataContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractSchema(org.apache.calcite.schema.impl.AbstractSchema) Enumerator(org.apache.calcite.linq4j.Enumerator) ResultSet(java.sql.ResultSet) Enumerable(org.apache.calcite.linq4j.Enumerable) AbstractEnumerable(org.apache.calcite.linq4j.AbstractEnumerable) CalciteConnection(org.apache.calcite.jdbc.CalciteConnection) Test(org.junit.Test)

Aggregations

Schema (org.apache.calcite.schema.Schema)16 CalciteSchema (org.apache.calcite.jdbc.CalciteSchema)7 SchemaPlus (org.apache.calcite.schema.SchemaPlus)7 AbstractSchema (org.apache.calcite.schema.impl.AbstractSchema)7 HashMap (java.util.HashMap)5 JdbcSchema (org.apache.calcite.adapter.jdbc.JdbcSchema)5 Test (org.junit.Test)5 Map (java.util.Map)4 Connection (java.sql.Connection)3 CloneSchema (org.apache.calcite.adapter.clone.CloneSchema)3 ReflectiveSchema (org.apache.calcite.adapter.java.ReflectiveSchema)3 CalciteConnection (org.apache.calcite.jdbc.CalciteConnection)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 Properties (java.util.Properties)2 SchemaFactory (org.apache.calcite.schema.SchemaFactory)2 Table (org.apache.calcite.schema.Table)2 Table (com.hazelcast.sql.impl.schema.Table)1 BenchmarkDataGenerator (io.druid.benchmark.datagen.BenchmarkDataGenerator)1