use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project drill by axbaretto.
the class SchemaTreeProvider method close.
@Override
public void close() throws Exception {
List<AutoCloseable> toClose = Lists.newArrayList();
for (SchemaPlus tree : schemaTreesToClose) {
addSchemasToCloseList(tree, toClose);
}
AutoCloseables.close(toClose);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project streamline by hortonworks.
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.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project streamline by hortonworks.
the class RuleParser method parse.
public void parse() {
try {
SchemaPlus schema = Frameworks.createRootSchema(true);
FrameworkConfig config = Frameworks.newConfigBuilder().defaultSchema(schema).build();
Planner planner = Frameworks.getPlanner(config);
SqlSelect sqlSelect = (SqlSelect) planner.parse(sql);
// FROM
streams = parseStreams(sqlSelect);
// SELECT
projection = parseProjection(sqlSelect);
// WHERE
condition = parseCondition(sqlSelect);
// GROUP BY
groupBy = parseGroupBy(sqlSelect);
// HAVING
having = parseHaving(sqlSelect);
} catch (Exception ex) {
LOG.error("Got Exception while parsing rule {}", sql);
throw new RuntimeException(ex);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project drill by apache.
the class DrillHiveViewTable method expandViewForImpersonatedUser.
/**
* Because tables used by hive views, defined without name
* of storage plugin, we're making sure that storage plugin
* name will be taken into account for the special case,
* when hive storage based authorization is used, and user
* can query view, but doesn't have rights to access underlying
* table.
*
* @param context - to rel conversion context
* @param rowType - data type of requested columns
* @param workspaceSchemaPath - path to view in drill, for example: ["hive"]
* @param tokenSchemaTree - schema created for impersonated user
* @return - relational representation of expanded Hive view
*/
@Override
protected RelNode expandViewForImpersonatedUser(RelOptTable.ToRelContext context, RelDataType rowType, List<String> workspaceSchemaPath, SchemaPlus tokenSchemaTree) {
SchemaPlus drillHiveSchema = SchemaUtilites.findSchema(tokenSchemaTree, workspaceSchemaPath);
workspaceSchemaPath = ImmutableList.of();
return super.expandViewForImpersonatedUser(context, rowType, workspaceSchemaPath, drillHiveSchema);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project drill by apache.
the class QueryContext method getNewDefaultSchema.
/**
* Return reference to default schema instance in a schema tree. Each {@link org.apache.calcite.schema.SchemaPlus}
* instance can refer to its parent and its children. From the returned reference to default schema instance,
* clients can traverse the entire schema tree and know the default schema where to look up the tables first.
*
* @return Reference to default schema instance in a schema tree.
*/
public SchemaPlus getNewDefaultSchema() {
final SchemaPlus rootSchema = getRootSchema();
final SchemaPlus defaultSchema = session.getDefaultSchema(rootSchema);
if (defaultSchema == null) {
return rootSchema;
}
return defaultSchema;
}
Aggregations