Search in sources :

Example 31 with MetaStateEvent

use of io.siddhi.core.event.state.MetaStateEvent in project siddhi by wso2.

the class ExpressionWindowProcessor method process.

@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, WindowState state) {
    if (expressionStringExecutor == null && !init) {
        MetaStateEvent metaStateEvent = new MetaStateEvent(new MetaStreamEvent[] { metaStreamEvent, metaStreamEvent, metaStreamEvent });
        QueryParserHelper.updateVariablePosition(metaStateEvent, variableExpressionExecutors);
        init = true;
    }
    synchronized (state) {
        long currentTime = siddhiQueryContext.getSiddhiAppContext().getTimestampGenerator().currentTime();
        while (streamEventChunk.hasNext()) {
            StreamEvent streamEvent = streamEventChunk.next();
            if (expressionStringExecutor != null) {
                String expressionStringNew = (String) expressionStringExecutor.execute(streamEvent);
                if (!expressionStringNew.equals(expressionString)) {
                    expressionString = expressionStringNew;
                    processAllExpiredEvents(streamEventChunk, state, currentTime);
                }
            }
            StreamEvent clonedEvent = streamEventCloner.copyStreamEvent(streamEvent);
            clonedEvent.setType(StreamEvent.Type.EXPIRED);
            processStreamEvent(streamEventChunk, state, currentTime, clonedEvent);
        }
    }
    nextProcessor.process(streamEventChunk);
}
Also used : StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent)

Example 32 with MetaStateEvent

use of io.siddhi.core.event.state.MetaStateEvent in project siddhi by wso2.

the class OnDemandQueryParser method generateMatchingMetaInfoHolder.

private static MatchingMetaInfoHolder generateMatchingMetaInfoHolder(MetaStreamEvent metaStreamEvent, AbstractDefinition definition) {
    MetaStateEvent metaStateEvent = new MetaStateEvent(1);
    metaStateEvent.addEvent(metaStreamEvent);
    return new MatchingMetaInfoHolder(metaStateEvent, -1, 0, definition, definition, 0);
}
Also used : MatchingMetaInfoHolder(io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent)

Example 33 with MetaStateEvent

use of io.siddhi.core.event.state.MetaStateEvent in project siddhi by wso2.

the class SingleInputStreamParser method parseInputStream.

/**
 * Parse single InputStream and return SingleStreamRuntime
 *
 * @param inputStream                 single input stream to be parsed
 * @param variableExpressionExecutors List to hold VariableExpressionExecutors to update after query parsing
 * @param streamDefinitionMap         Stream Definition Map
 * @param tableDefinitionMap          Table Definition Map
 * @param windowDefinitionMap         window definition map
 * @param aggregationDefinitionMap    aggregation definition map
 * @param tableMap                    Table Map
 * @param metaComplexEvent            MetaComplexEvent
 * @param processStreamReceiver       ProcessStreamReceiver
 * @param supportsBatchProcessing     supports batch processing
 * @param outputExpectsExpiredEvents  is expired events sent as output
 * @param findToBeExecuted            find will be executed in the steam stores
 * @param multiValue                  event has the possibility to produce multiple values
 * @param siddhiQueryContext          @return SingleStreamRuntime
 */
public static SingleStreamRuntime parseInputStream(SingleInputStream inputStream, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, AbstractDefinition> streamDefinitionMap, Map<String, AbstractDefinition> tableDefinitionMap, Map<String, AbstractDefinition> windowDefinitionMap, Map<String, AbstractDefinition> aggregationDefinitionMap, Map<String, Table> tableMap, MetaComplexEvent metaComplexEvent, ProcessStreamReceiver processStreamReceiver, boolean supportsBatchProcessing, boolean outputExpectsExpiredEvents, boolean findToBeExecuted, boolean multiValue, SiddhiQueryContext siddhiQueryContext) {
    Processor processor = null;
    EntryValveProcessor entryValveProcessor = null;
    ProcessingMode processingMode = ProcessingMode.BATCH;
    boolean first = true;
    MetaStreamEvent metaStreamEvent;
    if (metaComplexEvent instanceof MetaStateEvent) {
        metaStreamEvent = new MetaStreamEvent();
        ((MetaStateEvent) metaComplexEvent).addEvent(metaStreamEvent);
        initMetaStreamEvent(inputStream, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, multiValue, metaStreamEvent);
    } else {
        metaStreamEvent = (MetaStreamEvent) metaComplexEvent;
        initMetaStreamEvent(inputStream, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, multiValue, metaStreamEvent);
    }
    // A window cannot be defined for a window stream
    if (!inputStream.getStreamHandlers().isEmpty() && windowDefinitionMap != null && windowDefinitionMap.containsKey(inputStream.getStreamId())) {
        for (StreamHandler handler : inputStream.getStreamHandlers()) {
            if (handler instanceof Window) {
                throw new OperationNotSupportedException("Cannot create " + ((Window) handler).getName() + " " + "window for the window stream " + inputStream.getStreamId());
            }
        }
    }
    if (!inputStream.getStreamHandlers().isEmpty()) {
        for (StreamHandler handler : inputStream.getStreamHandlers()) {
            Processor currentProcessor = generateProcessor(handler, metaComplexEvent, variableExpressionExecutors, tableMap, supportsBatchProcessing, outputExpectsExpiredEvents, findToBeExecuted, siddhiQueryContext);
            if (currentProcessor instanceof SchedulingProcessor) {
                if (entryValveProcessor == null) {
                    entryValveProcessor = new EntryValveProcessor(siddhiQueryContext.getSiddhiAppContext());
                    if (first) {
                        processor = entryValveProcessor;
                        first = false;
                    } else {
                        processor.setToLast(entryValveProcessor);
                    }
                }
                Scheduler scheduler = SchedulerParser.parse(entryValveProcessor, siddhiQueryContext);
                ((SchedulingProcessor) currentProcessor).setScheduler(scheduler);
            }
            if (currentProcessor instanceof AbstractStreamProcessor) {
                processingMode = ProcessingMode.findUpdatedProcessingMode(processingMode, ((AbstractStreamProcessor) currentProcessor).getProcessingMode());
            }
            if (first) {
                processor = currentProcessor;
                first = false;
            } else {
                processor.setToLast(currentProcessor);
            }
        }
    }
    metaStreamEvent.initializeOnAfterWindowData();
    return new SingleStreamRuntime(processStreamReceiver, processor, processingMode, metaComplexEvent);
}
Also used : Window(io.siddhi.query.api.execution.query.input.handler.Window) OperationNotSupportedException(io.siddhi.core.exception.OperationNotSupportedException) FilterProcessor(io.siddhi.core.query.processor.filter.FilterProcessor) WindowProcessor(io.siddhi.core.query.processor.stream.window.WindowProcessor) EntryValveProcessor(io.siddhi.core.query.input.stream.single.EntryValveProcessor) AbstractStreamProcessor(io.siddhi.core.query.processor.stream.AbstractStreamProcessor) StreamProcessor(io.siddhi.core.query.processor.stream.StreamProcessor) StreamFunctionProcessor(io.siddhi.core.query.processor.stream.function.StreamFunctionProcessor) Processor(io.siddhi.core.query.processor.Processor) SchedulingProcessor(io.siddhi.core.query.processor.SchedulingProcessor) AbstractStreamProcessor(io.siddhi.core.query.processor.stream.AbstractStreamProcessor) Scheduler(io.siddhi.core.util.Scheduler) SingleStreamRuntime(io.siddhi.core.query.input.stream.single.SingleStreamRuntime) ProcessingMode(io.siddhi.core.query.processor.ProcessingMode) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) SchedulingProcessor(io.siddhi.core.query.processor.SchedulingProcessor) StreamHandler(io.siddhi.query.api.execution.query.input.handler.StreamHandler) EntryValveProcessor(io.siddhi.core.query.input.stream.single.EntryValveProcessor) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 34 with MetaStateEvent

use of io.siddhi.core.event.state.MetaStateEvent in project siddhi by wso2.

the class QueryParserHelper method initStreamRuntime.

public static void initStreamRuntime(StreamRuntime runtime, MetaComplexEvent metaComplexEvent, LockWrapper lockWrapper, String queryName) {
    if (runtime instanceof SingleStreamRuntime) {
        initSingleStreamRuntime((SingleStreamRuntime) runtime, 0, metaComplexEvent, null, lockWrapper, queryName);
    } else {
        MetaStateEvent metaStateEvent = (MetaStateEvent) metaComplexEvent;
        StateEventFactory stateEventFactory = new StateEventFactory(metaStateEvent);
        MetaStreamEvent[] metaStreamEvents = metaStateEvent.getMetaStreamEvents();
        for (int i = 0, metaStreamEventsLength = metaStreamEvents.length; i < metaStreamEventsLength; i++) {
            initSingleStreamRuntime(runtime.getSingleStreamRuntimes().get(i), i, metaStateEvent, stateEventFactory, lockWrapper, queryName);
        }
    }
}
Also used : SingleStreamRuntime(io.siddhi.core.query.input.stream.single.SingleStreamRuntime) StateEventFactory(io.siddhi.core.event.state.StateEventFactory) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent)

Example 35 with MetaStateEvent

use of io.siddhi.core.event.state.MetaStateEvent in project siddhi by wso2.

the class QueryParserHelper method initSingleStreamRuntime.

private static void initSingleStreamRuntime(SingleStreamRuntime singleStreamRuntime, int streamEventChainIndex, MetaComplexEvent metaComplexEvent, StateEventFactory stateEventFactory, LockWrapper lockWrapper, String queryName) {
    MetaStreamEvent metaStreamEvent;
    if (metaComplexEvent instanceof MetaStateEvent) {
        metaStreamEvent = ((MetaStateEvent) metaComplexEvent).getMetaStreamEvent(streamEventChainIndex);
    } else {
        metaStreamEvent = (MetaStreamEvent) metaComplexEvent;
    }
    StreamEventFactory streamEventFactory = new StreamEventFactory(metaStreamEvent);
    ProcessStreamReceiver processStreamReceiver = singleStreamRuntime.getProcessStreamReceiver();
    processStreamReceiver.setMetaStreamEvent(metaStreamEvent);
    processStreamReceiver.setStreamEventFactory(streamEventFactory);
    processStreamReceiver.setLockWrapper(lockWrapper);
    processStreamReceiver.init();
    Processor processor = singleStreamRuntime.getProcessorChain();
    while (processor != null) {
        if (processor instanceof SchedulingProcessor) {
            ((SchedulingProcessor) processor).getScheduler().setStreamEventFactory(streamEventFactory);
            ((SchedulingProcessor) processor).getScheduler().init(lockWrapper, queryName);
        }
        if (processor instanceof AbstractStreamProcessor) {
            ((AbstractStreamProcessor) processor).setStreamEventCloner(new StreamEventCloner(metaStreamEvent, streamEventFactory));
            ((AbstractStreamProcessor) processor).constructStreamEventPopulater(metaStreamEvent, streamEventChainIndex);
        }
        if (stateEventFactory != null && processor instanceof JoinProcessor) {
            if (((JoinProcessor) processor).getCompiledCondition() instanceof IncrementalAggregateCompileCondition) {
                IncrementalAggregateCompileCondition compiledCondition = (IncrementalAggregateCompileCondition) ((JoinProcessor) processor).getCompiledCondition();
                compiledCondition.init();
                ComplexEventPopulater complexEventPopulater = StreamEventPopulaterFactory.constructEventPopulator(metaStreamEvent, 0, compiledCondition.getAdditionalAttributes());
                compiledCondition.setComplexEventPopulater(complexEventPopulater);
            }
            ((JoinProcessor) processor).setStateEventFactory(stateEventFactory);
        }
        if (stateEventFactory != null && processor instanceof StreamPreStateProcessor) {
            ((StreamPreStateProcessor) processor).setStateEventFactory(stateEventFactory);
            ((StreamPreStateProcessor) processor).setStreamEventFactory(streamEventFactory);
            ((StreamPreStateProcessor) processor).setStreamEventCloner(new StreamEventCloner(metaStreamEvent, streamEventFactory));
            if (metaComplexEvent instanceof MetaStateEvent) {
                ((StreamPreStateProcessor) processor).setStateEventCloner(new StateEventCloner(((MetaStateEvent) metaComplexEvent), stateEventFactory));
            }
        }
        processor = processor.getNextProcessor();
    }
}
Also used : ProcessStreamReceiver(io.siddhi.core.query.input.ProcessStreamReceiver) AbstractStreamProcessor(io.siddhi.core.query.processor.stream.AbstractStreamProcessor) Processor(io.siddhi.core.query.processor.Processor) SchedulingProcessor(io.siddhi.core.query.processor.SchedulingProcessor) StreamPreStateProcessor(io.siddhi.core.query.input.stream.state.StreamPreStateProcessor) JoinProcessor(io.siddhi.core.query.input.stream.join.JoinProcessor) AbstractStreamProcessor(io.siddhi.core.query.processor.stream.AbstractStreamProcessor) StreamEventFactory(io.siddhi.core.event.stream.StreamEventFactory) IncrementalAggregateCompileCondition(io.siddhi.core.util.collection.operator.IncrementalAggregateCompileCondition) ComplexEventPopulater(io.siddhi.core.event.stream.populater.ComplexEventPopulater) StreamPreStateProcessor(io.siddhi.core.query.input.stream.state.StreamPreStateProcessor) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) SchedulingProcessor(io.siddhi.core.query.processor.SchedulingProcessor) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) JoinProcessor(io.siddhi.core.query.input.stream.join.JoinProcessor) StateEventCloner(io.siddhi.core.event.state.StateEventCloner) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Aggregations

MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)37 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)32 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)16 Attribute (io.siddhi.query.api.definition.Attribute)16 MatchingMetaInfoHolder (io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)13 ArrayList (java.util.ArrayList)12 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)9 Variable (io.siddhi.query.api.expression.Variable)9 AbstractDefinition (io.siddhi.query.api.definition.AbstractDefinition)8 Expression (io.siddhi.query.api.expression.Expression)8 StreamEvent (io.siddhi.core.event.stream.StreamEvent)6 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)6 QuerySelector (io.siddhi.core.query.selector.QuerySelector)6 ReturnStream (io.siddhi.query.api.execution.query.output.stream.ReturnStream)5 ConstantExpressionExecutor (io.siddhi.core.executor.ConstantExpressionExecutor)4 SingleStreamRuntime (io.siddhi.core.query.input.stream.single.SingleStreamRuntime)4 CompiledSelection (io.siddhi.core.util.collection.operator.CompiledSelection)4 SiddhiQueryContext (io.siddhi.core.config.SiddhiQueryContext)3 StateEventFactory (io.siddhi.core.event.state.StateEventFactory)3 StateEventPopulatorFactory (io.siddhi.core.event.state.populater.StateEventPopulatorFactory)3