Search in sources :

Example 1 with PersistedIncrementalExecutor

use of io.siddhi.core.aggregation.persistedaggregation.PersistedIncrementalExecutor in project siddhi by wso2.

the class AggregationParser method buildIncrementalExecutors.

private static Map<TimePeriod.Duration, Executor> buildIncrementalExecutors(MetaStreamEvent processedMetaStreamEvent, Map<TimePeriod.Duration, List<ExpressionExecutor>> processExpressionExecutorsMap, Map<TimePeriod.Duration, GroupByKeyGenerator> groupByKeyGeneratorList, List<TimePeriod.Duration> incrementalDurations, Map<TimePeriod.Duration, Table> aggregationTables, SiddhiQueryContext siddhiQueryContext, String aggregatorName, ExpressionExecutor shouldUpdateTimestamp, String timeZone, boolean isPersistedAggregation, StreamDefinition incomingOutputStreamDefinition, boolean isDistributed, String shardId, boolean isProcessingOnExternalTime, AggregationDefinition aggregationDefinition, ConfigManager configManager, List<Variable> groupByVariableList, boolean isReadOnly) {
    Map<TimePeriod.Duration, Executor> incrementalExecutorMap = new HashMap<>();
    Map<TimePeriod.Duration, Processor> cudProcessors = new HashMap<>();
    // Create incremental executors
    Executor child;
    Executor root = null;
    if (isPersistedAggregation) {
        if (!isReadOnly) {
            cudProcessors = initAggregateQueryExecutor(incrementalDurations, processExpressionExecutorsMap, incomingOutputStreamDefinition, isDistributed, shardId, isProcessingOnExternalTime, siddhiQueryContext, aggregationDefinition, configManager, aggregationTables, groupByVariableList);
        }
        CudStreamProcessorQueueManager queueManager = new CudStreamProcessorQueueManager();
        // initialize cud stream processor queue
        LinkedBlockingQueue<QueuedCudStreamProcessor> cudStreamProcessorQueue = queueManager.initializeAndGetCudStreamProcessorQueue();
        siddhiQueryContext.getSiddhiAppContext().getExecutorService().execute(queueManager);
        for (int i = incrementalDurations.size() - 1; i >= 0; i--) {
            // Base incremental expression executors created using new meta
            // Add an object to aggregationTable map inorder fill up the missing durations
            aggregationTables.putIfAbsent(incrementalDurations.get(i), null);
            boolean isRoot = i == 0;
            child = root;
            TimePeriod.Duration duration = incrementalDurations.get(i);
            Executor incrementalExecutor;
            if (duration == TimePeriod.Duration.SECONDS || duration == TimePeriod.Duration.MINUTES || duration == TimePeriod.Duration.HOURS) {
                incrementalExecutor = new IncrementalExecutor(aggregatorName, duration, processExpressionExecutorsMap.get(duration), shouldUpdateTimestamp, groupByKeyGeneratorList.get(duration), isRoot, aggregationTables.get(duration), child, siddhiQueryContext, processedMetaStreamEvent, timeZone, duration.equals(TimePeriod.Duration.HOURS));
            } else {
                incrementalExecutor = new PersistedIncrementalExecutor(aggregatorName, duration, processExpressionExecutorsMap.get(duration), child, siddhiQueryContext, generateCUDMetaStreamEvent(isProcessingOnExternalTime), timeZone, cudProcessors.get(duration), cudStreamProcessorQueue);
            }
            incrementalExecutorMap.put(duration, incrementalExecutor);
            root = incrementalExecutor;
        }
    } else {
        for (int i = incrementalDurations.size() - 1; i >= 0; i--) {
            // Base incremental expression executors created using new meta
            boolean isRoot = i == 0;
            child = root;
            TimePeriod.Duration duration = incrementalDurations.get(i);
            IncrementalExecutor incrementalExecutor = new IncrementalExecutor(aggregatorName, duration, processExpressionExecutorsMap.get(duration), shouldUpdateTimestamp, groupByKeyGeneratorList.get(duration), isRoot, aggregationTables.get(duration), child, siddhiQueryContext, processedMetaStreamEvent, timeZone, false);
            incrementalExecutorMap.put(duration, incrementalExecutor);
            root = incrementalExecutor;
        }
    }
    return incrementalExecutorMap;
}
Also used : PersistedAggregationResultsProcessor(io.siddhi.core.aggregation.persistedaggregation.config.PersistedAggregationResultsProcessor) QueryableProcessor(io.siddhi.core.query.processor.stream.window.QueryableProcessor) AbstractStreamProcessor(io.siddhi.core.query.processor.stream.AbstractStreamProcessor) QueuedCudStreamProcessor(io.siddhi.core.aggregation.persistedaggregation.QueuedCudStreamProcessor) StreamProcessor(io.siddhi.core.query.processor.stream.StreamProcessor) Processor(io.siddhi.core.query.processor.Processor) IncrementalAggregationProcessor(io.siddhi.core.aggregation.IncrementalAggregationProcessor) QueuedCudStreamProcessor(io.siddhi.core.aggregation.persistedaggregation.QueuedCudStreamProcessor) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) TimePeriod(io.siddhi.query.api.aggregation.TimePeriod) CudStreamProcessorQueueManager(io.siddhi.core.aggregation.persistedaggregation.CudStreamProcessorQueueManager) PersistedIncrementalExecutor(io.siddhi.core.aggregation.persistedaggregation.PersistedIncrementalExecutor) IncrementalExecutor(io.siddhi.core.aggregation.IncrementalExecutor) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) MaxAttributeAggregatorExecutor(io.siddhi.core.query.selector.attribute.aggregator.MaxAttributeAggregatorExecutor) IncrementalAggregateBaseTimeFunctionExecutor(io.siddhi.core.executor.incremental.IncrementalAggregateBaseTimeFunctionExecutor) ConstantExpressionExecutor(io.siddhi.core.executor.ConstantExpressionExecutor) PersistedIncrementalExecutor(io.siddhi.core.aggregation.persistedaggregation.PersistedIncrementalExecutor) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) SumAttributeAggregatorExecutor(io.siddhi.core.query.selector.attribute.aggregator.SumAttributeAggregatorExecutor) Executor(io.siddhi.core.aggregation.Executor) IncrementalExecutor(io.siddhi.core.aggregation.IncrementalExecutor) EntryValveExecutor(io.siddhi.core.query.input.stream.single.EntryValveExecutor) MinAttributeAggregatorExecutor(io.siddhi.core.query.selector.attribute.aggregator.MinAttributeAggregatorExecutor) PersistedIncrementalExecutor(io.siddhi.core.aggregation.persistedaggregation.PersistedIncrementalExecutor)

Aggregations

Executor (io.siddhi.core.aggregation.Executor)1 IncrementalAggregationProcessor (io.siddhi.core.aggregation.IncrementalAggregationProcessor)1 IncrementalExecutor (io.siddhi.core.aggregation.IncrementalExecutor)1 CudStreamProcessorQueueManager (io.siddhi.core.aggregation.persistedaggregation.CudStreamProcessorQueueManager)1 PersistedIncrementalExecutor (io.siddhi.core.aggregation.persistedaggregation.PersistedIncrementalExecutor)1 QueuedCudStreamProcessor (io.siddhi.core.aggregation.persistedaggregation.QueuedCudStreamProcessor)1 PersistedAggregationResultsProcessor (io.siddhi.core.aggregation.persistedaggregation.config.PersistedAggregationResultsProcessor)1 ConstantExpressionExecutor (io.siddhi.core.executor.ConstantExpressionExecutor)1 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)1 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)1 IncrementalAggregateBaseTimeFunctionExecutor (io.siddhi.core.executor.incremental.IncrementalAggregateBaseTimeFunctionExecutor)1 EntryValveExecutor (io.siddhi.core.query.input.stream.single.EntryValveExecutor)1 Processor (io.siddhi.core.query.processor.Processor)1 AbstractStreamProcessor (io.siddhi.core.query.processor.stream.AbstractStreamProcessor)1 StreamProcessor (io.siddhi.core.query.processor.stream.StreamProcessor)1 QueryableProcessor (io.siddhi.core.query.processor.stream.window.QueryableProcessor)1 MaxAttributeAggregatorExecutor (io.siddhi.core.query.selector.attribute.aggregator.MaxAttributeAggregatorExecutor)1 MinAttributeAggregatorExecutor (io.siddhi.core.query.selector.attribute.aggregator.MinAttributeAggregatorExecutor)1 SumAttributeAggregatorExecutor (io.siddhi.core.query.selector.attribute.aggregator.SumAttributeAggregatorExecutor)1 TimePeriod (io.siddhi.query.api.aggregation.TimePeriod)1