Search in sources :

Example 1 with EvaluationCalc

use of org.apache.storm.sql.runtime.trident.functions.EvaluationCalc 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)

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.trident.functions.EvaluationCalc)1 Stream (org.apache.storm.trident.Stream)1 Fields (org.apache.storm.tuple.Fields)1