Search in sources :

Example 1 with EvaluationCalc

use of org.apache.storm.sql.runtime.streams.functions.EvaluationCalc in project storm by apache.

the class StreamsCalcRel method streamsPlan.

@Override
public void streamsPlan(StreamsPlanCreator planCreator) throws Exception {
    // SingleRel
    RelNode input = getInput();
    StormRelUtils.getStormRelInput(input).streamsPlan(planCreator);
    RelDataType inputRowType = getInput(0).getRowType();
    // 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.");
    }
    List<String> outputFieldNames = getRowType().getFieldNames();
    int outputCount = outputFieldNames.size();
    EvaluationCalc evalCalc = new EvaluationCalc(filterInstance, projectionInstance, outputCount, planCreator.getDataContext());
    final Stream<Values> inputStream = planCreator.pop();
    final Stream finalStream = inputStream.flatMap(evalCalc);
    planCreator.addStream(finalStream);
}
Also used : ArrayList(java.util.ArrayList) Values(org.apache.storm.tuple.Values) RelDataType(org.apache.calcite.rel.type.RelDataType) RelNode(org.apache.calcite.rel.RelNode) EvaluationCalc(org.apache.storm.sql.runtime.streams.functions.EvaluationCalc) RexLocalRef(org.apache.calcite.rex.RexLocalRef) Stream(org.apache.storm.streams.Stream) ExecutableExpression(org.apache.storm.sql.runtime.calcite.ExecutableExpression) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

ArrayList (java.util.ArrayList)1 RelNode (org.apache.calcite.rel.RelNode)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 RexLocalRef (org.apache.calcite.rex.RexLocalRef)1 RexNode (org.apache.calcite.rex.RexNode)1 ExecutableExpression (org.apache.storm.sql.runtime.calcite.ExecutableExpression)1 EvaluationCalc (org.apache.storm.sql.runtime.streams.functions.EvaluationCalc)1 Stream (org.apache.storm.streams.Stream)1 Values (org.apache.storm.tuple.Values)1