Search in sources :

Example 1 with ExecutableExpression

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);
}
Also used : CompilingClassLoader(org.apache.storm.sql.javac.CompilingClassLoader) DebuggableExecutableExpression(org.apache.storm.sql.runtime.calcite.DebuggableExecutableExpression) DebuggableExecutableExpression(org.apache.storm.sql.runtime.calcite.DebuggableExecutableExpression) ExecutableExpression(org.apache.storm.sql.runtime.calcite.ExecutableExpression)

Example 2 with ExecutableExpression

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

Example 3 with ExecutableExpression

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);
}
Also used : IAggregatableStream(org.apache.storm.trident.fluent.IAggregatableStream) RelNode(org.apache.calcite.rel.RelNode) EvaluationFilter(org.apache.storm.sql.runtime.trident.functions.EvaluationFilter) IAggregatableStream(org.apache.storm.trident.fluent.IAggregatableStream) Stream(org.apache.storm.trident.Stream) RelDataType(org.apache.calcite.rel.type.RelDataType) RexNode(org.apache.calcite.rex.RexNode) ExecutableExpression(org.apache.storm.sql.runtime.calcite.ExecutableExpression)

Example 4 with ExecutableExpression

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);
}
Also used : ClassDeclaration(org.apache.calcite.linq4j.tree.ClassDeclaration) Expression(org.apache.calcite.linq4j.tree.Expression) ExecutableExpression(org.apache.storm.sql.runtime.calcite.ExecutableExpression) ParameterExpression(org.apache.calcite.linq4j.tree.ParameterExpression) MemberDeclaration(org.apache.calcite.linq4j.tree.MemberDeclaration) BlockBuilder(org.apache.calcite.linq4j.tree.BlockBuilder) ExecutableExpression(org.apache.storm.sql.runtime.calcite.ExecutableExpression)

Example 5 with ExecutableExpression

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);
}
Also used : CompilingClassLoader(org.apache.storm.sql.javac.CompilingClassLoader) DebuggableExecutableExpression(org.apache.storm.sql.runtime.calcite.DebuggableExecutableExpression) DebuggableExecutableExpression(org.apache.storm.sql.runtime.calcite.DebuggableExecutableExpression) ExecutableExpression(org.apache.storm.sql.runtime.calcite.ExecutableExpression)

Aggregations

ExecutableExpression (org.apache.storm.sql.runtime.calcite.ExecutableExpression)11 RelNode (org.apache.calcite.rel.RelNode)6 RelDataType (org.apache.calcite.rel.type.RelDataType)6 RexNode (org.apache.calcite.rex.RexNode)6 CompilingClassLoader (org.apache.storm.sql.javac.CompilingClassLoader)4 DebuggableExecutableExpression (org.apache.storm.sql.runtime.calcite.DebuggableExecutableExpression)4 Stream (org.apache.storm.trident.Stream)3 Values (org.apache.storm.tuple.Values)3 ArrayList (java.util.ArrayList)2 RexLocalRef (org.apache.calcite.rex.RexLocalRef)2 Fields (org.apache.storm.tuple.Fields)2 BlockBuilder (org.apache.calcite.linq4j.tree.BlockBuilder)1 ClassDeclaration (org.apache.calcite.linq4j.tree.ClassDeclaration)1 Expression (org.apache.calcite.linq4j.tree.Expression)1 MemberDeclaration (org.apache.calcite.linq4j.tree.MemberDeclaration)1 ParameterExpression (org.apache.calcite.linq4j.tree.ParameterExpression)1 EvaluationCalc (org.apache.storm.sql.runtime.streams.functions.EvaluationCalc)1 EvaluationFilter (org.apache.storm.sql.runtime.streams.functions.EvaluationFilter)1 EvaluationFunction (org.apache.storm.sql.runtime.streams.functions.EvaluationFunction)1 EvaluationCalc (org.apache.storm.sql.runtime.trident.functions.EvaluationCalc)1