use of org.apache.storm.sql.runtime.calcite.ExecutableExpression in project storm by apache.
the class TridentPlanCreator method createScalarInstance.
public ExecutableExpression createScalarInstance(List<RexNode> nodes, RelDataType inputRowType, String className) throws CompilingClassLoader.CompilerException, ClassNotFoundException, IllegalAccessException, InstantiationException {
String expr = rexCompiler.compile(nodes, inputRowType, 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 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);
}
use of org.apache.storm.sql.runtime.calcite.ExecutableExpression 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);
}
use of org.apache.storm.sql.runtime.calcite.ExecutableExpression in project storm by apache.
the class RexNodeToJavaCodeCompiler method baz.
/**
* Given a method that implements {@link ExecutableExpression#execute(Context, Object[])}, adds a bridge method that
* implements {@link ExecutableExpression#execute(Context)}, and compiles.
*/
static String baz(ParameterExpression context, ParameterExpression outputValues, BlockStatement block, String className) {
final List<MemberDeclaration> declarations = Lists.newArrayList();
// public void execute(Context, Object[] outputValues)
declarations.add(Expressions.methodDecl(Modifier.PUBLIC, void.class, StormBuiltInMethod.EXPR_EXECUTE2.method.getName(), ImmutableList.of(context, outputValues), block));
// public Object execute(Context)
final BlockBuilder builder = new BlockBuilder();
final Expression values_ = builder.append("values", Expressions.newArrayBounds(Object.class, 1, Expressions.constant(1)));
builder.add(Expressions.statement(Expressions.call(Expressions.parameter(ExecutableExpression.class, "this"), StormBuiltInMethod.EXPR_EXECUTE2.method, context, values_)));
builder.add(Expressions.return_(null, Expressions.arrayIndex(values_, Expressions.constant(0))));
declarations.add(Expressions.methodDecl(Modifier.PUBLIC, Object.class, StormBuiltInMethod.EXPR_EXECUTE1.method.getName(), ImmutableList.of(context), builder.toBlock()));
final ClassDeclaration classDeclaration = Expressions.classDecl(Modifier.PUBLIC, className, null, ImmutableList.<Type>of(ExecutableExpression.class), declarations);
return Expressions.toString(Lists.newArrayList(classDeclaration), "\n", false);
}
use of org.apache.storm.sql.runtime.calcite.ExecutableExpression in project storm by apache.
the class StreamsPlanCreator method createScalarInstance.
public ExecutableExpression createScalarInstance(List<RexNode> nodes, RelDataType inputRowType, String className) throws CompilingClassLoader.CompilerException, ClassNotFoundException, IllegalAccessException, InstantiationException {
String expr = rexCompiler.compile(nodes, inputRowType, className);
CompilingClassLoader classLoader = new CompilingClassLoader(getLastClassLoader(), className, expr, null);
ExecutableExpression instance = (ExecutableExpression) classLoader.loadClass(className).newInstance();
addClassLoader(classLoader);
return new DebuggableExecutableExpression(instance, expr);
}
Aggregations