Search in sources :

Example 6 with ExecutableExpression

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);
}
Also used : ArrayList(java.util.ArrayList) Values(org.apache.storm.tuple.Values) RelDataType(org.apache.calcite.rel.type.RelDataType) RelNode(org.apache.calcite.rel.RelNode) EvaluationCalc(org.apache.storm.sql.runtime.streams.functions.EvaluationCalc) RexLocalRef(org.apache.calcite.rex.RexLocalRef) Stream(org.apache.storm.streams.Stream) ExecutableExpression(org.apache.storm.sql.runtime.calcite.ExecutableExpression) RexNode(org.apache.calcite.rex.RexNode)

Example 7 with ExecutableExpression

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

Example 8 with ExecutableExpression

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);
}
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 9 with ExecutableExpression

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);
}
Also used : Fields(org.apache.storm.tuple.Fields) RelNode(org.apache.calcite.rel.RelNode) EvaluationFunction(org.apache.storm.sql.runtime.trident.functions.EvaluationFunction) 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 10 with ExecutableExpression

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