Search in sources :

Example 16 with Schema

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

the class HazelcastSchemaUtils method createRootSchema.

/**
 * Construct a schema from the given table resolvers.
 * <p>
 * Currently we assume that all tables are resolved upfront by querying a table resolver. It works well for predefined
 * objects such as IMap and ReplicatedMap as well as external tables created by Jet. This approach will not work well
 * should we need a relaxed/dynamic object resolution at some point in future.
 *
 * @return Top-level schema.
 */
public static HazelcastSchema createRootSchema(SqlCatalog catalog) {
    // Create schemas.
    Map<String, Schema> schemaMap = new HashMap<>();
    for (Map.Entry<String, Map<String, Table>> currentSchemaEntry : catalog.getSchemas().entrySet()) {
        String schemaName = currentSchemaEntry.getKey();
        Map<String, org.apache.calcite.schema.Table> schemaTables = new HashMap<>();
        for (Map.Entry<String, Table> tableEntry : currentSchemaEntry.getValue().entrySet()) {
            String tableName = tableEntry.getKey();
            Table table = tableEntry.getValue();
            HazelcastTable convertedTable = new HazelcastTable(table, createTableStatistic(table));
            schemaTables.put(tableName, convertedTable);
        }
        HazelcastSchema currentSchema = new HazelcastSchema(Collections.emptyMap(), schemaTables);
        schemaMap.put(schemaName, currentSchema);
    }
    HazelcastSchema rootSchema = new HazelcastSchema(schemaMap, Collections.emptyMap());
    return createCatalog(rootSchema);
}
Also used : Table(com.hazelcast.sql.impl.schema.Table) HashMap(java.util.HashMap) Schema(org.apache.calcite.schema.Schema) Map(java.util.Map) HashMap(java.util.HashMap)

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