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);
}
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;
}
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;
}
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);
}
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;
}
Aggregations