Search in sources :

Example 1 with ResolvedQueryStmt

use of com.google.zetasql.resolvedast.ResolvedNodes.ResolvedQueryStmt in project beam by apache.

the class ZetaSQLPlannerImpl method rel.

public RelRoot rel(String sql, QueryParameters params) {
    RelOptCluster cluster = RelOptCluster.create(planner, new RexBuilder(typeFactory));
    AnalyzerOptions options = SqlAnalyzer.getAnalyzerOptions(params, defaultTimezone);
    BeamZetaSqlCatalog catalog = BeamZetaSqlCatalog.create(defaultSchemaPlus, (JavaTypeFactory) cluster.getTypeFactory(), options);
    // Set up table providers that need to be pre-registered
    SqlAnalyzer analyzer = new SqlAnalyzer();
    List<List<String>> tables = analyzer.extractTableNames(sql, options);
    TableResolution.registerTables(this.defaultSchemaPlus, tables);
    QueryTrait trait = new QueryTrait();
    catalog.addTables(tables, trait);
    ResolvedQueryStmt statement = analyzer.analyzeQuery(sql, options, catalog);
    ExpressionConverter expressionConverter = new ExpressionConverter(cluster, params, catalog.getUserFunctionDefinitions());
    ConversionContext context = ConversionContext.of(config, expressionConverter, cluster, trait);
    RelNode convertedNode = QueryStatementConverter.convertRootQuery(context, statement);
    return RelRoot.of(convertedNode, SqlKind.ALL);
}
Also used : RelOptCluster(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptCluster) ConversionContext(org.apache.beam.sdk.extensions.sql.zetasql.translation.ConversionContext) RelNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode) RexBuilder(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexBuilder) ExpressionConverter(org.apache.beam.sdk.extensions.sql.zetasql.translation.ExpressionConverter) List(java.util.List) ImmutableList(org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList) ResolvedQueryStmt(com.google.zetasql.resolvedast.ResolvedNodes.ResolvedQueryStmt) AnalyzerOptions(com.google.zetasql.AnalyzerOptions)

Aggregations

AnalyzerOptions (com.google.zetasql.AnalyzerOptions)1 ResolvedQueryStmt (com.google.zetasql.resolvedast.ResolvedNodes.ResolvedQueryStmt)1 List (java.util.List)1 ConversionContext (org.apache.beam.sdk.extensions.sql.zetasql.translation.ConversionContext)1 ExpressionConverter (org.apache.beam.sdk.extensions.sql.zetasql.translation.ExpressionConverter)1 ImmutableList (org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList)1 RelOptCluster (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptCluster)1 RelNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode)1 RexBuilder (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexBuilder)1