Search in sources :

Example 11 with SchemaPlus

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project drill by apache.

the class SchemaUtilites method resolveToMutableDrillSchema.

/**
   * Given reference to default schema in schema tree, search for schema with given <i>schemaPath</i>. Once a schema is
   * found resolve it into a mutable <i>AbstractDrillSchema</i> instance. A {@link UserException} is throws when:
   *   <li>No schema for given <i>schemaPath</i> is found.</li>
   *   <li>Schema found for given <i>schemaPath</i> is a root schema.</li>
   *   <li>Resolved schema is not a mutable schema.</li>
   *
   * @param defaultSchema default schema
   * @param schemaPath current schema path
   * @return mutable schema, exception otherwise
   */
public static AbstractSchema resolveToMutableDrillSchema(final SchemaPlus defaultSchema, List<String> schemaPath) {
    final SchemaPlus schema = findSchema(defaultSchema, schemaPath);
    if (schema == null) {
        throwSchemaNotFoundException(defaultSchema, SCHEMA_PATH_JOINER.join(schemaPath));
    }
    if (isRootSchema(schema)) {
        throw UserException.validationError().message("Root schema is immutable. Creating or dropping tables/views is not allowed in root schema." + "Select a schema using 'USE schema' command.").build(logger);
    }
    final AbstractSchema drillSchema = unwrapAsDrillSchemaInstance(schema);
    if (!drillSchema.isMutable()) {
        throw UserException.validationError().message("Unable to create or drop tables/views. Schema [%s] is immutable.", getSchemaPath(schema)).build(logger);
    }
    return drillSchema;
}
Also used : AbstractSchema(org.apache.drill.exec.store.AbstractSchema) SchemaPlus(org.apache.calcite.schema.SchemaPlus)

Example 12 with SchemaPlus

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project herddb by diennea.

the class CalcitePlanner method getSchemaForTableSpace.

private SchemaPlus getSchemaForTableSpace(String defaultTableSpace) {
    long startTs = System.currentTimeMillis();
    while (true) {
        SchemaPlus schema = getRootSchema();
        SchemaPlus result = schema.getSubSchema(defaultTableSpace);
        if (result != null) {
            return result;
        }
        long delta = System.currentTimeMillis() - startTs;
        LOG.log(Level.FINE, "schema {0} not available yet, after waiting {1}/{2} ms", new Object[] { defaultTableSpace, delta, waitForSchemaTimeout });
        if (delta >= waitForSchemaTimeout) {
            return null;
        }
        clearCache();
        try {
            Thread.sleep(100);
        } catch (InterruptedException err) {
            Thread.currentThread().interrupt();
        }
    }
}
Also used : SchemaPlus(org.apache.calcite.schema.SchemaPlus)

Example 13 with SchemaPlus

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project herddb by diennea.

the class CalcitePlanner method getRootSchema.

private SchemaPlus getRootSchema() {
    if (rootSchema != null) {
        return rootSchema;
    }
    final SchemaPlus _rootSchema = Frameworks.createRootSchema(true);
    for (String tableSpace : manager.getLocalTableSpaces()) {
        TableSpaceManager tableSpaceManager = manager.getTableSpaceManager(tableSpace);
        SchemaPlus schema = _rootSchema.add(tableSpace, new AbstractSchema());
        List<Table> tables = tableSpaceManager.getAllTablesForPlanner();
        for (Table table : tables) {
            AbstractTableManager tableManager = tableSpaceManager.getTableManager(table.name);
            TableImpl tableDef = new TableImpl(tableManager);
            schema.add(table.name, tableDef);
        }
    }
    rootSchema = _rootSchema;
    return _rootSchema;
}
Also used : Table(herddb.model.Table) ShowCreateTableCalculator.calculateShowCreateTable(herddb.sql.functions.ShowCreateTableCalculator.calculateShowCreateTable) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) RelOptTable(org.apache.calcite.plan.RelOptTable) ProjectableFilterableTable(org.apache.calcite.schema.ProjectableFilterableTable) ScannableTable(org.apache.calcite.schema.ScannableTable) AbstractTable(org.apache.calcite.schema.impl.AbstractTable) ModifiableTable(org.apache.calcite.schema.ModifiableTable) AbstractSchema(org.apache.calcite.schema.impl.AbstractSchema) AbstractTableManager(herddb.core.AbstractTableManager) SchemaPlus(org.apache.calcite.schema.SchemaPlus) TableSpaceManager(herddb.core.TableSpaceManager)

Example 14 with SchemaPlus

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project calcite by apache.

the class ModelHandler method visit.

public void visit(JsonMapSchema jsonSchema) {
    checkRequiredAttributes(jsonSchema, "name");
    final SchemaPlus parentSchema = currentMutableSchema("schema");
    final SchemaPlus schema = parentSchema.add(jsonSchema.name, new AbstractSchema());
    if (jsonSchema.path != null) {
        schema.setPath(stringListList(jsonSchema.path));
    }
    populateSchema(jsonSchema, schema);
}
Also used : AbstractSchema(org.apache.calcite.schema.impl.AbstractSchema) SchemaPlus(org.apache.calcite.schema.SchemaPlus)

Example 15 with SchemaPlus

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project calcite by apache.

the class ModelHandler method visit.

public void visit(JsonCustomTable jsonTable) {
    try {
        checkRequiredAttributes(jsonTable, "name", "factory");
        final SchemaPlus schema = currentMutableSchema("table");
        final TableFactory tableFactory = AvaticaUtils.instantiatePlugin(TableFactory.class, jsonTable.factory);
        final Table table = tableFactory.create(schema, jsonTable.name, operandMap(null, jsonTable.operand), null);
        for (JsonColumn column : jsonTable.columns) {
            column.accept(this);
        }
        schema.add(jsonTable.name, table);
    } catch (Exception e) {
        throw new RuntimeException("Error instantiating " + jsonTable, e);
    }
}
Also used : ViewTable(org.apache.calcite.schema.impl.ViewTable) MaterializedViewTable(org.apache.calcite.schema.impl.MaterializedViewTable) Table(org.apache.calcite.schema.Table) TableFactory(org.apache.calcite.schema.TableFactory) SchemaPlus(org.apache.calcite.schema.SchemaPlus) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Aggregations

SchemaPlus (org.apache.calcite.schema.SchemaPlus)182 Test (org.junit.Test)57 CalciteConnection (org.apache.calcite.jdbc.CalciteConnection)42 Connection (java.sql.Connection)39 AbstractSchema (org.apache.calcite.schema.impl.AbstractSchema)33 ResultSet (java.sql.ResultSet)26 ReflectiveSchema (org.apache.calcite.adapter.java.ReflectiveSchema)24 RelNode (org.apache.calcite.rel.RelNode)21 Table (org.apache.calcite.schema.Table)20 SqlNode (org.apache.calcite.sql.SqlNode)19 IOException (java.io.IOException)17 Statement (java.sql.Statement)17 PreparedStatement (java.sql.PreparedStatement)16 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)15 AbstractSchema (org.apache.drill.exec.store.AbstractSchema)15 ArrayList (java.util.ArrayList)14 JavaTypeFactoryImpl (org.apache.calcite.jdbc.JavaTypeFactoryImpl)14 SQLException (java.sql.SQLException)13 Properties (java.util.Properties)13 SchemaPlus (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus)13