use of org.apache.storm.sql.runtime.calcite.ExecutableExpression 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);
}
use of org.apache.storm.sql.runtime.calcite.ExecutableExpression in project storm by apache.
the class StreamsFilterRel method streamsPlan.
@Override
public void streamsPlan(StreamsPlanCreator planCreator) throws Exception {
// SingleRel
RelNode input = getInput();
StormRelUtils.getStormRelInput(input).streamsPlan(planCreator);
Stream<Values> inputStream = planCreator.pop();
List<RexNode> childExps = getChildExps();
RelDataType inputRowType = getInput(0).getRowType();
String filterClassName = StormRelUtils.getClassName(this);
ExecutableExpression filterInstance = planCreator.createScalarInstance(childExps, inputRowType, filterClassName);
EvaluationFilter evalFilter = new EvaluationFilter(filterInstance, planCreator.getDataContext());
final Stream<Values> finalStream = inputStream.filter(evalFilter);
planCreator.addStream(finalStream);
}
use of org.apache.storm.sql.runtime.calcite.ExecutableExpression in project storm by apache.
the class TridentPlanCreator method createScalarInstance.
public ExecutableExpression createScalarInstance(RexProgram program, String className) throws CompilingClassLoader.CompilerException, ClassNotFoundException, IllegalAccessException, InstantiationException {
String expr = rexCompiler.compile(program, className);
CompilingClassLoader classLoader = new CompilingClassLoader(getLastClassLoader(), className, expr, null);
ExecutableExpression instance = (ExecutableExpression) classLoader.loadClass(className).newInstance();
addClassLoader(classLoader);
return new DebuggableExecutableExpression(instance, expr);
}
use of org.apache.storm.sql.runtime.calcite.ExecutableExpression in project storm by apache.
the class TridentProjectRel 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);
String projectionClassName = StormRelUtils.getClassName(this);
List<String> outputFieldNames = getRowType().getFieldNames();
int outputCount = outputFieldNames.size();
List<RexNode> childExps = getChildExps();
RelDataType inputRowType = getInput(0).getRowType();
ExecutableExpression projectionInstance = planCreator.createScalarInstance(childExps, inputRowType, projectionClassName);
Stream finalStream = inputStream.map(new EvaluationFunction(projectionInstance, outputCount, planCreator.getDataContext()), new Fields(outputFieldNames)).name(stageName);
planCreator.addStream(finalStream);
}
use of org.apache.storm.sql.runtime.calcite.ExecutableExpression in project storm by apache.
the class StreamsPlanCreator method createScalarInstance.
public ExecutableExpression createScalarInstance(RexProgram program, String className) throws CompilingClassLoader.CompilerException, ClassNotFoundException, IllegalAccessException, InstantiationException {
String expr = rexCompiler.compile(program, className);
CompilingClassLoader classLoader = new CompilingClassLoader(getLastClassLoader(), className, expr, null);
ExecutableExpression instance = (ExecutableExpression) classLoader.loadClass(className).newInstance();
addClassLoader(classLoader);
return new DebuggableExecutableExpression(instance, expr);
}
Aggregations