Search in sources :

Example 6 with RelNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project storm by apache.

the class QueryPlanner method validateAndConvert.

private RelNode validateAndConvert(SqlNode sqlNode) throws ValidationException, RelConversionException {
    SqlNode validated = validateNode(sqlNode);
    RelNode relNode = convertToRelNode(validated);
    return convertToStormRel(relNode);
}
Also used : RelNode(org.apache.calcite.rel.RelNode) SqlNode(org.apache.calcite.sql.SqlNode)

Example 7 with RelNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project storm by apache.

the class TridentCalcRel method tridentPlan.

@Override
public void tridentPlan(TridentPlanCreator planCreator) throws Exception {
    // SingleRel
    RelNode input = getInput();
    StormRelUtils.getStormRelInput(input).tridentPlan(planCreator);
    Stream inputStream = planCreator.pop().toStream();
    String stageName = StormRelUtils.getStageName(this);
    RelDataType inputRowType = getInput(0).getRowType();
    List<String> outputFieldNames = getRowType().getFieldNames();
    int outputCount = outputFieldNames.size();
    // filter
    ExecutableExpression filterInstance = null;
    RexLocalRef condition = program.getCondition();
    if (condition != null) {
        RexNode conditionNode = program.expandLocalRef(condition);
        filterInstance = planCreator.createScalarInstance(Lists.newArrayList(conditionNode), inputRowType, StormRelUtils.getClassName(this));
    }
    // projection
    ExecutableExpression projectionInstance = null;
    List<RexLocalRef> projectList = program.getProjectList();
    if (projectList != null && !projectList.isEmpty()) {
        List<RexNode> expandedNodes = new ArrayList<>();
        for (RexLocalRef project : projectList) {
            expandedNodes.add(program.expandLocalRef(project));
        }
        projectionInstance = planCreator.createScalarInstance(expandedNodes, inputRowType, StormRelUtils.getClassName(this));
    }
    if (projectionInstance == null && filterInstance == null) {
        // it shouldn't be happen
        throw new IllegalStateException("Either projection or condition, or both should be provided.");
    }
    final Stream finalStream = inputStream.flatMap(new EvaluationCalc(filterInstance, projectionInstance, outputCount, planCreator.getDataContext()), new Fields(outputFieldNames)).name(stageName);
    planCreator.addStream(finalStream);
}
Also used : ArrayList(java.util.ArrayList) RelDataType(org.apache.calcite.rel.type.RelDataType) Fields(org.apache.storm.tuple.Fields) RelNode(org.apache.calcite.rel.RelNode) EvaluationCalc(org.apache.storm.sql.runtime.trident.functions.EvaluationCalc) RexLocalRef(org.apache.calcite.rex.RexLocalRef) Stream(org.apache.storm.trident.Stream) ExecutableExpression(org.apache.storm.sql.runtime.calcite.ExecutableExpression) RexNode(org.apache.calcite.rex.RexNode)

Example 8 with RelNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project storm by apache.

the class TridentFilterRel method tridentPlan.

@Override
public void tridentPlan(TridentPlanCreator planCreator) throws Exception {
    // SingleRel
    RelNode input = getInput();
    StormRelUtils.getStormRelInput(input).tridentPlan(planCreator);
    Stream inputStream = planCreator.pop().toStream();
    String stageName = StormRelUtils.getStageName(this);
    List<RexNode> childExps = getChildExps();
    RelDataType inputRowType = getInput(0).getRowType();
    String filterClassName = StormRelUtils.getClassName(this);
    ExecutableExpression filterInstance = planCreator.createScalarInstance(childExps, inputRowType, filterClassName);
    IAggregatableStream finalStream = inputStream.filter(new EvaluationFilter(filterInstance, planCreator.getDataContext())).name(stageName);
    planCreator.addStream(finalStream);
}
Also used : IAggregatableStream(org.apache.storm.trident.fluent.IAggregatableStream) RelNode(org.apache.calcite.rel.RelNode) EvaluationFilter(org.apache.storm.sql.runtime.trident.functions.EvaluationFilter) IAggregatableStream(org.apache.storm.trident.fluent.IAggregatableStream) Stream(org.apache.storm.trident.Stream) RelDataType(org.apache.calcite.rel.type.RelDataType) RexNode(org.apache.calcite.rex.RexNode) ExecutableExpression(org.apache.storm.sql.runtime.calcite.ExecutableExpression)

Example 9 with RelNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project storm by apache.

the class TridentStreamInsertRel method tridentPlan.

@Override
public void tridentPlan(TridentPlanCreator planCreator) throws Exception {
    // SingleRel
    RelNode input = getInput();
    StormRelUtils.getStormRelInput(input).tridentPlan(planCreator);
    Stream inputStream = planCreator.pop().toStream();
    String stageName = StormRelUtils.getStageName(this);
    Preconditions.checkArgument(isInsert(), "Only INSERT statement is supported.");
    List<String> inputFields = this.input.getRowType().getFieldNames();
    List<String> outputFields = getRowType().getFieldNames();
    // FIXME: this should be really different...
    String tableName = Joiner.on('.').join(getTable().getQualifiedName());
    ISqlTridentDataSource.SqlTridentConsumer consumer = planCreator.getSources().get(tableName).getConsumer();
    // In fact this is normally the end of stream, but I'm still not sure so I open new streams based on State values
    IAggregatableStream finalStream = inputStream.partitionPersist(consumer.getStateFactory(), new Fields(inputFields), consumer.getStateUpdater(), new Fields(outputFields)).newValuesStream().name(stageName);
    planCreator.addStream(finalStream);
}
Also used : IAggregatableStream(org.apache.storm.trident.fluent.IAggregatableStream) Fields(org.apache.storm.tuple.Fields) RelNode(org.apache.calcite.rel.RelNode) ISqlTridentDataSource(org.apache.storm.sql.runtime.ISqlTridentDataSource) IAggregatableStream(org.apache.storm.trident.fluent.IAggregatableStream) Stream(org.apache.storm.trident.Stream)

Example 10 with RelNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project storm by apache.

the class TestCompilerUtils method sqlOverDummyTable.

public static CalciteState sqlOverDummyTable(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("NAME", typeFactory.createType(String.class)).field("ADDR", typeFactory.createType(String.class)).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 : 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)

Aggregations

RelNode (org.apache.calcite.rel.RelNode)1562 RexNode (org.apache.calcite.rex.RexNode)472 ArrayList (java.util.ArrayList)398 Test (org.junit.jupiter.api.Test)389 RelBuilder (org.apache.calcite.tools.RelBuilder)342 RelDataType (org.apache.calcite.rel.type.RelDataType)237 RexBuilder (org.apache.calcite.rex.RexBuilder)210 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)207 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)207 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)166 RexInputRef (org.apache.calcite.rex.RexInputRef)160 RelMetadataQuery (org.apache.calcite.rel.metadata.RelMetadataQuery)156 Project (org.apache.calcite.rel.core.Project)154 TimestampString (org.apache.calcite.util.TimestampString)154 List (java.util.List)145 RelTraitSet (org.apache.calcite.plan.RelTraitSet)140 Pair (org.apache.calcite.util.Pair)127 ImmutableList (com.google.common.collect.ImmutableList)126 Nullable (org.checkerframework.checker.nullness.qual.Nullable)119 AggregateCall (org.apache.calcite.rel.core.AggregateCall)110