Search in sources :

Example 26 with MetaStateEvent

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

the class InputStreamParser method parse.

/**
 * Parse an InputStream returning corresponding StreamRuntime
 *
 * @param inputStream                input stream to be parsed
 * @param streamDefinitionMap        map containing user given stream definitions
 * @param tableDefinitionMap         table definition map
 * @param windowDefinitionMap        window definition map
 * @param aggregationDefinitionMap   aggregation definition map
 * @param tableMap                   Table Map
 * @param windowMap                  event window map
 * @param aggregationMap             aggregator map
 * @param executors                  List to hold VariableExpressionExecutors to update after query parsing
 * @param outputExpectsExpiredEvents is expired events sent as output
 * @param siddhiQueryContext         Siddhi query context.
 * @return StreamRuntime
 */
public static StreamRuntime parse(InputStream inputStream, Query query, Map<String, AbstractDefinition> streamDefinitionMap, Map<String, AbstractDefinition> tableDefinitionMap, Map<String, AbstractDefinition> windowDefinitionMap, Map<String, AbstractDefinition> aggregationDefinitionMap, Map<String, Table> tableMap, Map<String, Window> windowMap, Map<String, AggregationRuntime> aggregationMap, List<VariableExpressionExecutor> executors, boolean outputExpectsExpiredEvents, SiddhiQueryContext siddhiQueryContext) {
    if (inputStream instanceof BasicSingleInputStream || inputStream instanceof SingleInputStream) {
        SingleInputStream singleInputStream = (SingleInputStream) inputStream;
        ProcessStreamReceiver processStreamReceiver = new ProcessStreamReceiver(singleInputStream.getStreamId(), siddhiQueryContext);
        return SingleInputStreamParser.parseInputStream((SingleInputStream) inputStream, executors, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, new MetaStreamEvent(), processStreamReceiver, true, outputExpectsExpiredEvents, false, false, siddhiQueryContext);
    } else if (inputStream instanceof JoinInputStream) {
        return JoinInputStreamParser.parseInputStream(((JoinInputStream) inputStream), query, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, windowMap, aggregationMap, executors, outputExpectsExpiredEvents, siddhiQueryContext);
    } else if (inputStream instanceof StateInputStream) {
        MetaStateEvent metaStateEvent = new MetaStateEvent(inputStream.getAllStreamIds().size());
        return StateInputStreamParser.parseInputStream(((StateInputStream) inputStream), metaStateEvent, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, executors, siddhiQueryContext);
    } else {
        throw new OperationNotSupportedException();
    }
}
Also used : OperationNotSupportedException(io.siddhi.core.exception.OperationNotSupportedException) ProcessStreamReceiver(io.siddhi.core.query.input.ProcessStreamReceiver) SingleInputStream(io.siddhi.query.api.execution.query.input.stream.SingleInputStream) BasicSingleInputStream(io.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) JoinInputStream(io.siddhi.query.api.execution.query.input.stream.JoinInputStream) BasicSingleInputStream(io.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) StateInputStream(io.siddhi.query.api.execution.query.input.stream.StateInputStream) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent)

Example 27 with MetaStateEvent

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

the class MatcherParser method constructMatchingMetaStateHolder.

public static MatchingMetaInfoHolder constructMatchingMetaStateHolder(MetaComplexEvent matchingMetaComplexEvent, int defaultStreamEventIndex, AbstractDefinition candsidateDefinition, int currentState) {
    int storeEventIndex = 0;
    MetaStreamEvent tableStreamEvent = new MetaStreamEvent();
    tableStreamEvent.setEventType(MetaStreamEvent.EventType.TABLE);
    tableStreamEvent.addInputDefinition(candsidateDefinition);
    for (Attribute attribute : candsidateDefinition.getAttributeList()) {
        tableStreamEvent.addOutputData(attribute);
    }
    MetaStateEvent metaStateEvent = null;
    if (matchingMetaComplexEvent instanceof MetaStreamEvent) {
        metaStateEvent = new MetaStateEvent(2);
        metaStateEvent.addEvent(((MetaStreamEvent) matchingMetaComplexEvent));
        metaStateEvent.addEvent(tableStreamEvent);
        storeEventIndex = 1;
        defaultStreamEventIndex = 0;
        if (currentState == SiddhiConstants.UNKNOWN_STATE) {
            currentState = defaultStreamEventIndex;
        }
    } else {
        MetaStreamEvent[] metaStreamEvents = ((MetaStateEvent) matchingMetaComplexEvent).getMetaStreamEvents();
        // for join
        for (; storeEventIndex < metaStreamEvents.length; storeEventIndex++) {
            MetaStreamEvent metaStreamEvent = metaStreamEvents[storeEventIndex];
            if (storeEventIndex != defaultStreamEventIndex && metaStreamEvent.getLastInputDefinition().equalsIgnoreAnnotations(candsidateDefinition)) {
                metaStateEvent = ((MetaStateEvent) matchingMetaComplexEvent);
                break;
            }
        }
        if (metaStateEvent == null) {
            metaStateEvent = new MetaStateEvent(metaStreamEvents.length + 1);
            for (MetaStreamEvent metaStreamEvent : metaStreamEvents) {
                metaStateEvent.addEvent(metaStreamEvent);
            }
            metaStateEvent.addEvent(tableStreamEvent);
            storeEventIndex = metaStreamEvents.length;
        }
    }
    return new MatchingMetaInfoHolder(metaStateEvent, defaultStreamEventIndex, storeEventIndex, metaStateEvent.getMetaStreamEvent(defaultStreamEventIndex).getLastInputDefinition(), candsidateDefinition, currentState);
}
Also used : Attribute(io.siddhi.query.api.definition.Attribute) MatchingMetaInfoHolder(io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent)

Example 28 with MetaStateEvent

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

the class ExpressionBatchWindowProcessor method processAllExpiredEvents.

private void processAllExpiredEvents(StreamEventCloner streamEventCloner, WindowState state, long currentTime, List<ComplexEventChunk<StreamEvent>> streamEventChunks) {
    MetaStateEvent metaStateEvent = constructExpression(metaStreamEvent, siddhiQueryContext);
    QueryParserHelper.updateVariablePosition(metaStateEvent, variableExpressionExecutors);
    if (!streamInputEvents) {
        StreamEvent expiredEvent = state.currentEventQueue.getFirst();
        state.currentEventQueue.clear();
        while (expiredEvent != null) {
            StreamEvent aExpiredEvent = expiredEvent;
            expiredEvent = expiredEvent.getNext();
            aExpiredEvent.setNext(null);
            processStreamEvent(state, currentTime, aExpiredEvent, streamEventCloner, streamEventChunks);
        }
        state.currentEventQueue.reset();
    } else {
        StreamEvent expiredEvent = state.expiredEventQueue.getFirst();
        state.expiredEventQueue.clear();
        while (expiredEvent != null) {
            StreamEvent aExpiredEvent = expiredEvent;
            expiredEvent = expiredEvent.getNext();
            aExpiredEvent.setNext(null);
            processStreamEventAsStream(state, currentTime, aExpiredEvent, streamEventCloner, streamEventChunks, false);
        }
        state.expiredEventQueue.reset();
    }
}
Also used : StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent)

Example 29 with MetaStateEvent

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

the class ExpressionBatchWindowProcessor 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;
    }
    List<ComplexEventChunk<StreamEvent>> streamEventChunks = new ArrayList<>();
    synchronized (state) {
        long currentTime = siddhiQueryContext.getSiddhiAppContext().getTimestampGenerator().currentTime();
        while (streamEventChunk.hasNext()) {
            StreamEvent streamEvent = streamEventChunk.next();
            streamEventChunk.remove();
            if (expressionStringExecutor != null) {
                String expressionStringNew = (String) expressionStringExecutor.execute(streamEvent);
                if (!expressionStringNew.equals(expressionString)) {
                    expressionString = expressionStringNew;
                    processAllExpiredEvents(streamEventCloner, state, currentTime, streamEventChunks);
                }
            }
            if (!streamInputEvents) {
                processStreamEvent(state, currentTime, streamEvent, streamEventCloner, streamEventChunks);
            } else {
                processStreamEventAsStream(state, currentTime, streamEvent, streamEventCloner, streamEventChunks, true);
            }
        }
    }
    for (ComplexEventChunk<StreamEvent> outputStreamEventChunk : streamEventChunks) {
        nextProcessor.process(outputStreamEventChunk);
    }
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) ArrayList(java.util.ArrayList) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent)

Example 30 with MetaStateEvent

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

the class ExpressionWindowProcessor method processAllExpiredEvents.

private void processAllExpiredEvents(ComplexEventChunk<StreamEvent> streamEventChunk, WindowState state, long currentTime) {
    MetaStateEvent metaStateEvent = constructExpression(metaStreamEvent, siddhiQueryContext);
    QueryParserHelper.updateVariablePosition(metaStateEvent, variableExpressionExecutors);
    StreamEvent expiredEvent = state.expiredEventQueue.getFirst();
    state.expiredEventQueue.clear();
    while (expiredEvent != null) {
        StreamEvent aExpiredEvent = expiredEvent;
        expiredEvent = expiredEvent.getNext();
        aExpiredEvent.setNext(null);
        processStreamEvent(streamEventChunk, state, currentTime, aExpiredEvent);
    }
    state.expiredEventQueue.reset();
}
Also used : StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent)

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