Search in sources :

Example 16 with SchemaPlus

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

the class KuduSchemaFactory method registerSchemas.

@Override
public void registerSchemas(SchemaConfig schemaConfig, SchemaPlus parent) throws IOException {
    KuduTables schema = new KuduTables(schemaName);
    SchemaPlus hPlus = parent.add(schemaName, schema);
    schema.setHolder(hPlus);
}
Also used : SchemaPlus(org.apache.calcite.schema.SchemaPlus)

Example 17 with SchemaPlus

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

the class SchemaUtilites method findSchema.

/**
   * Search and return schema with given schemaPath. First search in schema tree starting from defaultSchema,
   * if not found search starting from rootSchema. Root schema tree is derived from the defaultSchema reference.
   *
   * @param defaultSchema Reference to the default schema in complete schema tree.
   * @param schemaPath Schema path to search.
   * @return SchemaPlus object.
   */
public static SchemaPlus findSchema(final SchemaPlus defaultSchema, final List<String> schemaPath) {
    if (schemaPath.size() == 0) {
        return defaultSchema;
    }
    SchemaPlus schema;
    if ((schema = searchSchemaTree(defaultSchema, schemaPath)) != null) {
        return schema;
    }
    SchemaPlus rootSchema = defaultSchema;
    while (rootSchema.getParentSchema() != null) {
        rootSchema = rootSchema.getParentSchema();
    }
    if (rootSchema != defaultSchema && (schema = searchSchemaTree(rootSchema, schemaPath)) != null) {
        return schema;
    }
    return null;
}
Also used : SchemaPlus(org.apache.calcite.schema.SchemaPlus)

Example 18 with SchemaPlus

use of 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 19 with SchemaPlus

use of org.apache.calcite.schema.SchemaPlus in project storm by apache.

the class TestCompilerUtils method sqlOverNestedTable.

public static CalciteState sqlOverNestedTable(String sql) throws RelConversionException, ValidationException, SqlParseException {
    SchemaPlus schema = Frameworks.createRootSchema(true);
    JavaTypeFactory typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
    StreamableTable streamableTable = new CompilerUtil.TableBuilderInfo(typeFactory).field("ID", SqlTypeName.INTEGER).field("MAPFIELD", typeFactory.createTypeWithNullability(typeFactory.createMapType(typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.VARCHAR), true), typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER), true)), true)).field("NESTEDMAPFIELD", typeFactory.createTypeWithNullability(typeFactory.createMapType(typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.VARCHAR), true), typeFactory.createTypeWithNullability(typeFactory.createMapType(typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.VARCHAR), true), typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER), true)), true)), true)).field("ARRAYFIELD", typeFactory.createTypeWithNullability(typeFactory.createArrayType(typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER), true), -1L), true)).build();
    Table table = streamableTable.stream();
    schema.add("FOO", table);
    schema.add("BAR", table);
    schema.add("MYPLUS", ScalarFunctionImpl.create(MyPlus.class, "eval"));
    List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>();
    sqlOperatorTables.add(SqlStdOperatorTable.instance());
    sqlOperatorTables.add(new CalciteCatalogReader(CalciteSchema.from(schema), false, Collections.<String>emptyList(), typeFactory));
    SqlOperatorTable chainedSqlOperatorTable = new ChainedSqlOperatorTable(sqlOperatorTables);
    FrameworkConfig config = Frameworks.newConfigBuilder().defaultSchema(schema).operatorTable(chainedSqlOperatorTable).build();
    Planner planner = Frameworks.getPlanner(config);
    SqlNode parse = planner.parse(sql);
    SqlNode validate = planner.validate(parse);
    RelNode tree = planner.convert(validate);
    System.out.println(RelOptUtil.toString(tree, SqlExplainLevel.ALL_ATTRIBUTES));
    return new CalciteState(schema, tree);
}
Also used : CompilerUtil(org.apache.storm.sql.compiler.CompilerUtil) SqlOperatorTable(org.apache.calcite.sql.SqlOperatorTable) Table(org.apache.calcite.schema.Table) ChainedSqlOperatorTable(org.apache.calcite.sql.util.ChainedSqlOperatorTable) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) StreamableTable(org.apache.calcite.schema.StreamableTable) SchemaPlus(org.apache.calcite.schema.SchemaPlus) ArrayList(java.util.ArrayList) StreamableTable(org.apache.calcite.schema.StreamableTable) ChainedSqlOperatorTable(org.apache.calcite.sql.util.ChainedSqlOperatorTable) CalciteCatalogReader(org.apache.calcite.prepare.CalciteCatalogReader) RelNode(org.apache.calcite.rel.RelNode) JavaTypeFactoryImpl(org.apache.calcite.jdbc.JavaTypeFactoryImpl) SqlOperatorTable(org.apache.calcite.sql.SqlOperatorTable) ChainedSqlOperatorTable(org.apache.calcite.sql.util.ChainedSqlOperatorTable) JavaTypeFactory(org.apache.calcite.adapter.java.JavaTypeFactory) Planner(org.apache.calcite.tools.Planner) FrameworkConfig(org.apache.calcite.tools.FrameworkConfig) SqlNode(org.apache.calcite.sql.SqlNode)

Example 20 with SchemaPlus

use of org.apache.calcite.schema.SchemaPlus in project druid by druid-io.

the class Calcites method createRootSchema.

public static SchemaPlus createRootSchema(final Schema druidSchema) {
    final SchemaPlus rootSchema = CalciteSchema.createRootSchema(false, false).plus();
    rootSchema.add(DruidSchema.NAME, druidSchema);
    rootSchema.add(InformationSchema.NAME, new InformationSchema(rootSchema));
    return rootSchema;
}
Also used : SchemaPlus(org.apache.calcite.schema.SchemaPlus) InformationSchema(io.druid.sql.calcite.schema.InformationSchema)

Aggregations

SchemaPlus (org.apache.calcite.schema.SchemaPlus)33 Table (org.apache.calcite.schema.Table)8 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)6 JavaTypeFactoryImpl (org.apache.calcite.jdbc.JavaTypeFactoryImpl)6 DruidOperatorTable (io.druid.sql.calcite.planner.DruidOperatorTable)5 PlannerConfig (io.druid.sql.calcite.planner.PlannerConfig)5 PlannerFactory (io.druid.sql.calcite.planner.PlannerFactory)5 StreamableTable (org.apache.calcite.schema.StreamableTable)5 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)4 SqlNode (org.apache.calcite.sql.SqlNode)4 AbstractSchema (org.apache.drill.exec.store.AbstractSchema)4 QueryPlanner (org.apache.storm.sql.planner.trident.QueryPlanner)4 TridentRel (org.apache.storm.sql.planner.trident.rel.TridentRel)4 Before (org.junit.Before)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 CompilerUtil (org.apache.storm.sql.compiler.CompilerUtil)3 CalciteCatalogReader (org.apache.calcite.prepare.CalciteCatalogReader)2 UserSession (org.apache.drill.exec.rpc.user.UserSession)2 DrillFileSystem (org.apache.drill.exec.store.dfs.DrillFileSystem)2