Search in sources :

Example 1 with IAggregatableStream

use of org.apache.storm.trident.fluent.IAggregatableStream in project storm by apache.

the class QueryPlanner method compile.

public AbstractTridentProcessor compile(Map<String, ISqlTridentDataSource> sources, String query) throws Exception {
    TridentRel relNode = getPlan(query);
    TridentPlanCreator tridentPlanCreator = new TridentPlanCreator(sources, new RexBuilder(typeFactory));
    relNode.tridentPlan(tridentPlanCreator);
    final TridentTopology topology = tridentPlanCreator.getTopology();
    final IAggregatableStream lastStream = tridentPlanCreator.pop();
    final DataContext dc = tridentPlanCreator.getDataContext();
    final List<CompilingClassLoader> cls = tridentPlanCreator.getClassLoaders();
    return new AbstractTridentProcessor() {

        @Override
        public TridentTopology build() {
            return topology;
        }

        @Override
        public Stream outputStream() {
            return lastStream.toStream();
        }

        @Override
        public DataContext getDataContext() {
            return dc;
        }

        @Override
        public List<CompilingClassLoader> getClassLoaders() {
            return cls;
        }
    };
}
Also used : AbstractTridentProcessor(org.apache.storm.sql.AbstractTridentProcessor) IAggregatableStream(org.apache.storm.trident.fluent.IAggregatableStream) DataContext(org.apache.calcite.DataContext) CompilingClassLoader(org.apache.storm.sql.javac.CompilingClassLoader) TridentTopology(org.apache.storm.trident.TridentTopology) RexBuilder(org.apache.calcite.rex.RexBuilder) TridentRel(org.apache.storm.sql.planner.trident.rel.TridentRel)

Example 2 with IAggregatableStream

use of org.apache.storm.trident.fluent.IAggregatableStream 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 3 with IAggregatableStream

use of org.apache.storm.trident.fluent.IAggregatableStream in project storm by apache.

the class TridentStreamInsertRel 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);
    Preconditions.checkArgument(isInsert(), "Only INSERT statement is supported.");
    List<String> inputFields = this.input.getRowType().getFieldNames();
    List<String> outputFields = getRowType().getFieldNames();
    // FIXME: this should be really different...
    String tableName = Joiner.on('.').join(getTable().getQualifiedName());
    ISqlTridentDataSource.SqlTridentConsumer consumer = planCreator.getSources().get(tableName).getConsumer();
    // In fact this is normally the end of stream, but I'm still not sure so I open new streams based on State values
    IAggregatableStream finalStream = inputStream.partitionPersist(consumer.getStateFactory(), new Fields(inputFields), consumer.getStateUpdater(), new Fields(outputFields)).newValuesStream().name(stageName);
    planCreator.addStream(finalStream);
}
Also used : IAggregatableStream(org.apache.storm.trident.fluent.IAggregatableStream) Fields(org.apache.storm.tuple.Fields) RelNode(org.apache.calcite.rel.RelNode) ISqlTridentDataSource(org.apache.storm.sql.runtime.ISqlTridentDataSource) IAggregatableStream(org.apache.storm.trident.fluent.IAggregatableStream) Stream(org.apache.storm.trident.Stream)

Example 4 with IAggregatableStream

use of org.apache.storm.trident.fluent.IAggregatableStream in project storm by apache.

the class TridentStreamScanRel method tridentPlan.

@Override
public void tridentPlan(TridentPlanCreator planCreator) throws Exception {
    String sourceName = Joiner.on('.').join(getTable().getQualifiedName());
    // FIXME: this should be really different...
    Map<String, ISqlTridentDataSource> sources = planCreator.getSources();
    if (!sources.containsKey(sourceName)) {
        throw new RuntimeException("Cannot find table " + sourceName);
    }
    String stageName = StormRelUtils.getStageName(this);
    IAggregatableStream finalStream = planCreator.getTopology().newStream(stageName, sources.get(sourceName).getProducer()).parallelismHint(parallelismHint);
    planCreator.addStream(finalStream);
}
Also used : IAggregatableStream(org.apache.storm.trident.fluent.IAggregatableStream) ISqlTridentDataSource(org.apache.storm.sql.runtime.ISqlTridentDataSource)

Aggregations

IAggregatableStream (org.apache.storm.trident.fluent.IAggregatableStream)4 RelNode (org.apache.calcite.rel.RelNode)2 ISqlTridentDataSource (org.apache.storm.sql.runtime.ISqlTridentDataSource)2 Stream (org.apache.storm.trident.Stream)2 DataContext (org.apache.calcite.DataContext)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 RexBuilder (org.apache.calcite.rex.RexBuilder)1 RexNode (org.apache.calcite.rex.RexNode)1 AbstractTridentProcessor (org.apache.storm.sql.AbstractTridentProcessor)1 CompilingClassLoader (org.apache.storm.sql.javac.CompilingClassLoader)1 TridentRel (org.apache.storm.sql.planner.trident.rel.TridentRel)1 ExecutableExpression (org.apache.storm.sql.runtime.calcite.ExecutableExpression)1 EvaluationFilter (org.apache.storm.sql.runtime.trident.functions.EvaluationFilter)1 TridentTopology (org.apache.storm.trident.TridentTopology)1 Fields (org.apache.storm.tuple.Fields)1