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);
}
Aggregations