Search in sources :

Example 11 with StateElement

use of io.siddhi.query.api.execution.query.input.state.StateElement in project siddhi by wso2.

the class StateInputStreamParser method parseInputStream.

public static StateStreamRuntime parseInputStream(StateInputStream stateInputStream, MetaStateEvent metaStateEvent, Map<String, AbstractDefinition> streamDefinitionMap, Map<String, AbstractDefinition> tableDefinitionMap, Map<String, AbstractDefinition> windowDefinitionMap, Map<String, AbstractDefinition> aggregationDefinitionMap, Map<String, Table> tableMap, List<VariableExpressionExecutor> variableExpressionExecutors, SiddhiQueryContext siddhiQueryContext) {
    Map<String, ProcessStreamReceiver> processStreamReceiverMap = new HashMap<String, ProcessStreamReceiver>();
    StateStreamRuntime stateStreamRuntime = new StateStreamRuntime(siddhiQueryContext, metaStateEvent);
    Object patternSyncObject = new Object();
    for (String streamId : stateInputStream.getAllStreamIds()) {
        int streamCount = stateInputStream.getStreamCount(streamId);
        if (streamCount == 1) {
            if (stateInputStream.getStateType() == StateInputStream.Type.SEQUENCE) {
                processStreamReceiverMap.put(streamId, new SequenceSingleProcessStreamReceiver(streamId, stateStreamRuntime, patternSyncObject, siddhiQueryContext));
            } else {
                processStreamReceiverMap.put(streamId, new PatternSingleProcessStreamReceiver(streamId, patternSyncObject, siddhiQueryContext));
            }
        } else {
            if (stateInputStream.getStateType() == StateInputStream.Type.SEQUENCE) {
                processStreamReceiverMap.put(streamId, new SequenceMultiProcessStreamReceiver(streamId, streamCount, stateStreamRuntime, patternSyncObject, siddhiQueryContext));
            } else {
                processStreamReceiverMap.put(streamId, new PatternMultiProcessStreamReceiver(streamId, streamCount, patternSyncObject, siddhiQueryContext));
            }
        }
    }
    StateElement stateElement = stateInputStream.getStateElement();
    List<PreStateProcessor> preStateProcessors = new ArrayList<>();
    List<PreStateProcessor> startupPreStateProcessors = new ArrayList<>();
    InnerStateRuntime innerStateRuntime = parse(stateElement, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, variableExpressionExecutors, processStreamReceiverMap, null, null, stateInputStream.getStateType(), false, preStateProcessors, true, startupPreStateProcessors, siddhiQueryContext);
    stateStreamRuntime.setInnerStateRuntime(innerStateRuntime);
    stateStreamRuntime.setStartupPreStateProcessors(startupPreStateProcessors);
    for (ProcessStreamReceiver processStreamReceiver : processStreamReceiverMap.values()) {
        processStreamReceiver.setAllStatefulProcessors(preStateProcessors);
    }
    if (stateInputStream.getWithinTime() != null) {
        List<Integer> startStateIdList = new ArrayList<>();
        for (PreStateProcessor preStateProcessor : preStateProcessors) {
            if (preStateProcessor.isStartState()) {
                startStateIdList.add(preStateProcessor.getStateId());
            }
        }
        int[] startStateIds = Ints.toArray(startStateIdList);
        for (PreStateProcessor preStateProcessor : preStateProcessors) {
            preStateProcessor.setStartStateIds(startStateIds);
            preStateProcessor.setWithinTime(stateInputStream.getWithinTime().value());
        }
    }
    ((StreamPreStateProcessor) innerStateRuntime.getFirstProcessor()).setThisLastProcessor((StreamPostStateProcessor) innerStateRuntime.getLastProcessor());
    return stateStreamRuntime;
}
Also used : SequenceSingleProcessStreamReceiver(io.siddhi.core.query.input.stream.state.receiver.SequenceSingleProcessStreamReceiver) ProcessStreamReceiver(io.siddhi.core.query.input.ProcessStreamReceiver) PatternSingleProcessStreamReceiver(io.siddhi.core.query.input.stream.state.receiver.PatternSingleProcessStreamReceiver) PatternMultiProcessStreamReceiver(io.siddhi.core.query.input.stream.state.receiver.PatternMultiProcessStreamReceiver) SequenceMultiProcessStreamReceiver(io.siddhi.core.query.input.stream.state.receiver.SequenceMultiProcessStreamReceiver) PatternSingleProcessStreamReceiver(io.siddhi.core.query.input.stream.state.receiver.PatternSingleProcessStreamReceiver) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LogicalStateElement(io.siddhi.query.api.execution.query.input.state.LogicalStateElement) NextStateElement(io.siddhi.query.api.execution.query.input.state.NextStateElement) AbsentStreamStateElement(io.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement) EveryStateElement(io.siddhi.query.api.execution.query.input.state.EveryStateElement) StreamStateElement(io.siddhi.query.api.execution.query.input.state.StreamStateElement) StateElement(io.siddhi.query.api.execution.query.input.state.StateElement) CountStateElement(io.siddhi.query.api.execution.query.input.state.CountStateElement) AbsentStreamPreStateProcessor(io.siddhi.core.query.input.stream.state.AbsentStreamPreStateProcessor) StreamPreStateProcessor(io.siddhi.core.query.input.stream.state.StreamPreStateProcessor) SequenceSingleProcessStreamReceiver(io.siddhi.core.query.input.stream.state.receiver.SequenceSingleProcessStreamReceiver) SequenceMultiProcessStreamReceiver(io.siddhi.core.query.input.stream.state.receiver.SequenceMultiProcessStreamReceiver) PatternMultiProcessStreamReceiver(io.siddhi.core.query.input.stream.state.receiver.PatternMultiProcessStreamReceiver) InnerStateRuntime(io.siddhi.core.query.input.stream.state.runtime.InnerStateRuntime) StreamInnerStateRuntime(io.siddhi.core.query.input.stream.state.runtime.StreamInnerStateRuntime) EveryInnerStateRuntime(io.siddhi.core.query.input.stream.state.runtime.EveryInnerStateRuntime) LogicalInnerStateRuntime(io.siddhi.core.query.input.stream.state.runtime.LogicalInnerStateRuntime) NextInnerStateRuntime(io.siddhi.core.query.input.stream.state.runtime.NextInnerStateRuntime) CountInnerStateRuntime(io.siddhi.core.query.input.stream.state.runtime.CountInnerStateRuntime) LogicalPreStateProcessor(io.siddhi.core.query.input.stream.state.LogicalPreStateProcessor) CountPreStateProcessor(io.siddhi.core.query.input.stream.state.CountPreStateProcessor) AbsentStreamPreStateProcessor(io.siddhi.core.query.input.stream.state.AbsentStreamPreStateProcessor) AbsentLogicalPreStateProcessor(io.siddhi.core.query.input.stream.state.AbsentLogicalPreStateProcessor) PreStateProcessor(io.siddhi.core.query.input.stream.state.PreStateProcessor) StreamPreStateProcessor(io.siddhi.core.query.input.stream.state.StreamPreStateProcessor) StateStreamRuntime(io.siddhi.core.query.input.stream.state.StateStreamRuntime)

Example 12 with StateElement

use of io.siddhi.query.api.execution.query.input.state.StateElement in project siddhi by wso2.

the class PartitionRuntimeImpl method addPartitionReceiver.

public void addPartitionReceiver(QueryRuntimeImpl queryRuntime, List<VariableExpressionExecutor> executors, MetaStateEvent metaEvent) {
    Query query = queryRuntime.getQuery();
    List<List<PartitionExecutor>> partitionExecutors = new StreamPartitioner(query.getInputStream(), partition, metaEvent, executors, queryRuntime.getSiddhiQueryContext()).getPartitionExecutorLists();
    if (queryRuntime.getStreamRuntime() instanceof SingleStreamRuntime) {
        SingleInputStream singleInputStream = (SingleInputStream) query.getInputStream();
        addPartitionReceiver(singleInputStream.getStreamId(), singleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(0), partitionExecutors.get(0));
    } else if (queryRuntime.getStreamRuntime() instanceof JoinStreamRuntime) {
        SingleInputStream leftSingleInputStream = (SingleInputStream) ((JoinInputStream) query.getInputStream()).getLeftInputStream();
        addPartitionReceiver(leftSingleInputStream.getStreamId(), leftSingleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(0), partitionExecutors.get(0));
        SingleInputStream rightSingleInputStream = (SingleInputStream) ((JoinInputStream) query.getInputStream()).getRightInputStream();
        addPartitionReceiver(rightSingleInputStream.getStreamId(), rightSingleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(1), partitionExecutors.get(1));
    } else if (queryRuntime.getStreamRuntime() instanceof StateStreamRuntime) {
        StateElement stateElement = ((StateInputStream) query.getInputStream()).getStateElement();
        addPartitionReceiverForStateElement(stateElement, metaEvent, partitionExecutors, 0);
    }
}
Also used : Query(io.siddhi.query.api.execution.query.Query) SingleStreamRuntime(io.siddhi.core.query.input.stream.single.SingleStreamRuntime) SingleInputStream(io.siddhi.query.api.execution.query.input.stream.SingleInputStream) JoinStreamRuntime(io.siddhi.core.query.input.stream.join.JoinStreamRuntime) JoinInputStream(io.siddhi.query.api.execution.query.input.stream.JoinInputStream) EveryStateElement(io.siddhi.query.api.execution.query.input.state.EveryStateElement) StreamStateElement(io.siddhi.query.api.execution.query.input.state.StreamStateElement) LogicalStateElement(io.siddhi.query.api.execution.query.input.state.LogicalStateElement) NextStateElement(io.siddhi.query.api.execution.query.input.state.NextStateElement) StateElement(io.siddhi.query.api.execution.query.input.state.StateElement) CountStateElement(io.siddhi.query.api.execution.query.input.state.CountStateElement) List(java.util.List) ArrayList(java.util.ArrayList) StateInputStream(io.siddhi.query.api.execution.query.input.stream.StateInputStream) StateStreamRuntime(io.siddhi.core.query.input.stream.state.StateStreamRuntime)

Example 13 with StateElement

use of io.siddhi.query.api.execution.query.input.state.StateElement in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitRight_absent_sequence_source.

@Override
public Object visitRight_absent_sequence_source(SiddhiQLParser.Right_absent_sequence_sourceContext ctx) {
    if (ctx.right_absent_sequence_source().size() == 1 && ctx.basic_absent_pattern_source() == null && ctx.sequence_source_chain() == null) {
        // '('right_absent_pattern_source')'
        StateElement stateElement = (StateElement) visit(ctx.right_absent_sequence_source(0));
        populateQueryContext(stateElement, ctx);
        return stateElement;
    } else {
        NextStateElement nextStateElement = new NextStateElement((StateElement) visit(ctx.getChild(0)), (StateElement) visit(ctx.getChild(2)));
        populateQueryContext(nextStateElement, ctx);
        return nextStateElement;
    }
}
Also used : NextStateElement(io.siddhi.query.api.execution.query.input.state.NextStateElement) EveryStateElement(io.siddhi.query.api.execution.query.input.state.EveryStateElement) StreamStateElement(io.siddhi.query.api.execution.query.input.state.StreamStateElement) NextStateElement(io.siddhi.query.api.execution.query.input.state.NextStateElement) AbsentStreamStateElement(io.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement) StateElement(io.siddhi.query.api.execution.query.input.state.StateElement) CountStateElement(io.siddhi.query.api.execution.query.input.state.CountStateElement)

Example 14 with StateElement

use of io.siddhi.query.api.execution.query.input.state.StateElement in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitLogical_absent_stateful_source.

@Override
public Object visitLogical_absent_stateful_source(SiddhiQLParser.Logical_absent_stateful_sourceContext ctx) {
    // ;
    if (ctx.logical_absent_stateful_source() != null) {
        return visit(ctx.logical_absent_stateful_source());
    } else if (ctx.AND() != null) {
        if (ctx.basic_absent_pattern_source().size() == 2) {
            StateElement stateElement = State.logicalNotAnd((AbsentStreamStateElement) visit(ctx.basic_absent_pattern_source(0)), (AbsentStreamStateElement) visit(ctx.basic_absent_pattern_source(1)));
            populateQueryContext(stateElement, ctx);
            return stateElement;
        } else {
            StreamStateElement presentStreamState = (StreamStateElement) visit(ctx.standard_stateful_source());
            AbsentStreamStateElement absentStreamState;
            if (!ctx.basic_absent_pattern_source().isEmpty()) {
                absentStreamState = (AbsentStreamStateElement) visit(ctx.basic_absent_pattern_source(0));
            } else {
                absentStreamState = State.logicalNot(new StreamStateElement((BasicSingleInputStream) visit(ctx.basic_source())), null);
            }
            StateElement stateElement = State.logicalNotAnd(absentStreamState, presentStreamState);
            populateQueryContext(stateElement, ctx);
            return stateElement;
        }
    } else if (ctx.OR() != null) {
        if (ctx.basic_absent_pattern_source().size() == 2) {
            return State.logicalOr((AbsentStreamStateElement) visit(ctx.basic_absent_pattern_source(0)), (AbsentStreamStateElement) visit(ctx.basic_absent_pattern_source(1)));
        } else {
            StreamStateElement streamStateElement1 = (StreamStateElement) visit(ctx.standard_stateful_source());
            AbsentStreamStateElement streamStateElement2 = (AbsentStreamStateElement) visit(ctx.basic_absent_pattern_source(0));
            StateElement stateElement = State.logicalOr(streamStateElement2, streamStateElement1);
            populateQueryContext(stateElement, ctx);
            return stateElement;
        }
    } else {
        throw newSiddhiParserException(ctx);
    }
}
Also used : StreamStateElement(io.siddhi.query.api.execution.query.input.state.StreamStateElement) AbsentStreamStateElement(io.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement) BasicSingleInputStream(io.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) AbsentStreamStateElement(io.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement) EveryStateElement(io.siddhi.query.api.execution.query.input.state.EveryStateElement) StreamStateElement(io.siddhi.query.api.execution.query.input.state.StreamStateElement) NextStateElement(io.siddhi.query.api.execution.query.input.state.NextStateElement) AbsentStreamStateElement(io.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement) StateElement(io.siddhi.query.api.execution.query.input.state.StateElement) CountStateElement(io.siddhi.query.api.execution.query.input.state.CountStateElement)

Example 15 with StateElement

use of io.siddhi.query.api.execution.query.input.state.StateElement in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitAbsent_pattern_source_chain.

@Override
public Object visitAbsent_pattern_source_chain(SiddhiQLParser.Absent_pattern_source_chainContext ctx) {
    if (ctx.absent_pattern_source_chain() != null) {
        StateElement stateElement = (StateElement) visit(ctx.absent_pattern_source_chain());
        if (ctx.EVERY() != null) {
            stateElement = new EveryStateElement(stateElement);
        }
        populateQueryContext(stateElement, ctx);
        return stateElement;
    } else {
        return visit(ctx.getChild(0));
    }
}
Also used : EveryStateElement(io.siddhi.query.api.execution.query.input.state.EveryStateElement) StreamStateElement(io.siddhi.query.api.execution.query.input.state.StreamStateElement) NextStateElement(io.siddhi.query.api.execution.query.input.state.NextStateElement) AbsentStreamStateElement(io.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement) StateElement(io.siddhi.query.api.execution.query.input.state.StateElement) CountStateElement(io.siddhi.query.api.execution.query.input.state.CountStateElement) EveryStateElement(io.siddhi.query.api.execution.query.input.state.EveryStateElement)

Aggregations

CountStateElement (io.siddhi.query.api.execution.query.input.state.CountStateElement)19 EveryStateElement (io.siddhi.query.api.execution.query.input.state.EveryStateElement)19 NextStateElement (io.siddhi.query.api.execution.query.input.state.NextStateElement)19 StateElement (io.siddhi.query.api.execution.query.input.state.StateElement)19 StreamStateElement (io.siddhi.query.api.execution.query.input.state.StreamStateElement)19 AbsentStreamStateElement (io.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement)18 LogicalStateElement (io.siddhi.query.api.execution.query.input.state.LogicalStateElement)3 StateInputStream (io.siddhi.query.api.execution.query.input.stream.StateInputStream)3 ArrayList (java.util.ArrayList)3 SingleStreamRuntime (io.siddhi.core.query.input.stream.single.SingleStreamRuntime)2 AbsentLogicalPreStateProcessor (io.siddhi.core.query.input.stream.state.AbsentLogicalPreStateProcessor)2 AbsentStreamPreStateProcessor (io.siddhi.core.query.input.stream.state.AbsentStreamPreStateProcessor)2 CountPreStateProcessor (io.siddhi.core.query.input.stream.state.CountPreStateProcessor)2 LogicalPreStateProcessor (io.siddhi.core.query.input.stream.state.LogicalPreStateProcessor)2 PreStateProcessor (io.siddhi.core.query.input.stream.state.PreStateProcessor)2 StateStreamRuntime (io.siddhi.core.query.input.stream.state.StateStreamRuntime)2 StreamPreStateProcessor (io.siddhi.core.query.input.stream.state.StreamPreStateProcessor)2 CountInnerStateRuntime (io.siddhi.core.query.input.stream.state.runtime.CountInnerStateRuntime)2 EveryInnerStateRuntime (io.siddhi.core.query.input.stream.state.runtime.EveryInnerStateRuntime)2 InnerStateRuntime (io.siddhi.core.query.input.stream.state.runtime.InnerStateRuntime)2