Search in sources :

Example 1 with StateInputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.StateInputStream in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitEvery_sequence_source_chain.

@Override
public Object visitEvery_sequence_source_chain(SiddhiQLParser.Every_sequence_source_chainContext ctx) {
    // every_sequence_source_chain
    // : EVERY? sequence_source  within_time?  ',' sequence_source_chain
    // ;
    StateElement stateElement1;
    if (ctx.EVERY() != null) {
        stateElement1 = new EveryStateElement((StateElement) visit(ctx.sequence_source()));
    } else {
        stateElement1 = (StateElement) visit(ctx.sequence_source());
    }
    if (ctx.within_time() != null) {
        stateElement1.setWithin((TimeConstant) visit(ctx.within_time()));
    }
    populateQueryContext(stateElement1, ctx);
    NextStateElement nextStateElement = new NextStateElement(stateElement1, ((StateElement) visit(ctx.sequence_source_chain())));
    populateQueryContext(nextStateElement, ctx);
    StateInputStream stateInputStream = new StateInputStream(StateInputStream.Type.SEQUENCE, nextStateElement);
    populateQueryContext(stateInputStream, ctx);
    return stateInputStream;
}
Also used : NextStateElement(org.wso2.siddhi.query.api.execution.query.input.state.NextStateElement) EveryStateElement(org.wso2.siddhi.query.api.execution.query.input.state.EveryStateElement) StreamStateElement(org.wso2.siddhi.query.api.execution.query.input.state.StreamStateElement) NextStateElement(org.wso2.siddhi.query.api.execution.query.input.state.NextStateElement) StateElement(org.wso2.siddhi.query.api.execution.query.input.state.StateElement) CountStateElement(org.wso2.siddhi.query.api.execution.query.input.state.CountStateElement) AbsentStreamStateElement(org.wso2.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement) StateInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.StateInputStream) EveryStateElement(org.wso2.siddhi.query.api.execution.query.input.state.EveryStateElement)

Example 2 with StateInputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.StateInputStream in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitEvery_absent_sequence_source_chain.

@Override
public Object visitEvery_absent_sequence_source_chain(SiddhiQLParser.Every_absent_sequence_source_chainContext ctx) {
    // every_absent_sequence_source_chain
    // : EVERY? absent_sequence_source_chain  within_time? ',' sequence_source_chain
    // | EVERY? sequence_source  within_time? ',' absent_sequence_source_chain
    // ;
    StateElement stateElement1;
    StateElement stateElement2;
    if (ctx.EVERY() != null) {
        stateElement1 = new EveryStateElement((StateElement) visit(ctx.getChild(1)));
    } else {
        stateElement1 = (StateElement) visit(ctx.getChild(0));
    }
    if (ctx.within_time() != null) {
        stateElement1.setWithin((TimeConstant) visit(ctx.within_time()));
    }
    stateElement2 = (StateElement) visit(ctx.getChild(ctx.getChildCount() - 1));
    populateQueryContext(stateElement1, ctx);
    populateQueryContext(stateElement2, ctx);
    NextStateElement nextStateElement = new NextStateElement(stateElement1, stateElement2);
    populateQueryContext(nextStateElement, ctx);
    StateInputStream stateInputStream = new StateInputStream(StateInputStream.Type.SEQUENCE, nextStateElement);
    populateQueryContext(stateInputStream, ctx);
    return stateInputStream;
}
Also used : NextStateElement(org.wso2.siddhi.query.api.execution.query.input.state.NextStateElement) EveryStateElement(org.wso2.siddhi.query.api.execution.query.input.state.EveryStateElement) StreamStateElement(org.wso2.siddhi.query.api.execution.query.input.state.StreamStateElement) NextStateElement(org.wso2.siddhi.query.api.execution.query.input.state.NextStateElement) StateElement(org.wso2.siddhi.query.api.execution.query.input.state.StateElement) CountStateElement(org.wso2.siddhi.query.api.execution.query.input.state.CountStateElement) AbsentStreamStateElement(org.wso2.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement) StateInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.StateInputStream) EveryStateElement(org.wso2.siddhi.query.api.execution.query.input.state.EveryStateElement)

Example 3 with StateInputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.StateInputStream in project siddhi by wso2.

the class InputStreamParser method parse.

/**
 * Parse an InputStream returning corresponding StreamRuntime
 *
 * @param inputStream                input stream to be parsed
 * @param siddhiAppContext           associated siddhi siddhiAppContext
 * @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 latencyTracker             latency tracker
 * @param outputExpectsExpiredEvents is output expects ExpiredEvents
 * @param queryName                  query name of input stream belongs to.
 * @return StreamRuntime
 */
public static StreamRuntime parse(InputStream inputStream, SiddhiAppContext siddhiAppContext, 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, LatencyTracker latencyTracker, boolean outputExpectsExpiredEvents, String queryName) {
    if (inputStream instanceof BasicSingleInputStream || inputStream instanceof SingleInputStream) {
        SingleInputStream singleInputStream = (SingleInputStream) inputStream;
        Window window = windowMap.get(singleInputStream.getStreamId());
        // If stream is from window, allow batch
        boolean batchProcessingAllowed = window != null;
        // processing
        ProcessStreamReceiver processStreamReceiver = new ProcessStreamReceiver(singleInputStream.getStreamId(), latencyTracker, queryName, siddhiAppContext);
        processStreamReceiver.setBatchProcessingAllowed(batchProcessingAllowed);
        return SingleInputStreamParser.parseInputStream((SingleInputStream) inputStream, siddhiAppContext, executors, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, new MetaStreamEvent(), processStreamReceiver, true, outputExpectsExpiredEvents, queryName);
    } else if (inputStream instanceof JoinInputStream) {
        return JoinInputStreamParser.parseInputStream(((JoinInputStream) inputStream), siddhiAppContext, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, windowMap, aggregationMap, executors, latencyTracker, outputExpectsExpiredEvents, queryName);
    } else if (inputStream instanceof StateInputStream) {
        MetaStateEvent metaStateEvent = new MetaStateEvent(inputStream.getAllStreamIds().size());
        return StateInputStreamParser.parseInputStream(((StateInputStream) inputStream), siddhiAppContext, metaStateEvent, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, executors, latencyTracker, queryName);
    } else {
        throw new OperationNotSupportedException();
    }
}
Also used : Window(org.wso2.siddhi.core.window.Window) OperationNotSupportedException(org.wso2.siddhi.core.exception.OperationNotSupportedException) ProcessStreamReceiver(org.wso2.siddhi.core.query.input.ProcessStreamReceiver) SingleInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.SingleInputStream) BasicSingleInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) JoinInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.JoinInputStream) BasicSingleInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) StateInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.StateInputStream) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(org.wso2.siddhi.core.event.state.MetaStateEvent)

Example 4 with StateInputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.StateInputStream in project siddhi by wso2.

the class StateInputStreamParser method parseInputStream.

public static StateStreamRuntime parseInputStream(StateInputStream stateInputStream, SiddhiAppContext siddhiAppContext, 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, LatencyTracker latencyTracker, String queryName) {
    Map<String, ProcessStreamReceiver> processStreamReceiverMap = new HashMap<String, ProcessStreamReceiver>();
    StateStreamRuntime stateStreamRuntime = new StateStreamRuntime(siddhiAppContext, metaStateEvent);
    String defaultLockKey = "";
    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, defaultLockKey, latencyTracker, queryName, siddhiAppContext));
            } else {
                processStreamReceiverMap.put(streamId, new PatternSingleProcessStreamReceiver(streamId, defaultLockKey, latencyTracker, queryName, siddhiAppContext));
            }
        } else {
            if (stateInputStream.getStateType() == StateInputStream.Type.SEQUENCE) {
                processStreamReceiverMap.put(streamId, new SequenceMultiProcessStreamReceiver(streamId, streamCount, stateStreamRuntime, latencyTracker, queryName, siddhiAppContext));
            } else {
                processStreamReceiverMap.put(streamId, new PatternMultiProcessStreamReceiver(streamId, streamCount, latencyTracker, queryName, siddhiAppContext));
            }
        }
    }
    StateElement stateElement = stateInputStream.getStateElement();
    InnerStateRuntime innerStateRuntime = parse(stateElement, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, siddhiAppContext, variableExpressionExecutors, processStreamReceiverMap, null, null, stateInputStream.getStateType(), new ArrayList<Map.Entry<Long, Set<Integer>>>(), latencyTracker, queryName);
    stateStreamRuntime.setInnerStateRuntime(innerStateRuntime);
    ((StreamPreStateProcessor) innerStateRuntime.getFirstProcessor()).setThisLastProcessor((StreamPostStateProcessor) innerStateRuntime.getLastProcessor());
    return stateStreamRuntime;
}
Also used : ProcessStreamReceiver(org.wso2.siddhi.core.query.input.ProcessStreamReceiver) PatternSingleProcessStreamReceiver(org.wso2.siddhi.core.query.input.stream.state.receiver.PatternSingleProcessStreamReceiver) PatternMultiProcessStreamReceiver(org.wso2.siddhi.core.query.input.stream.state.receiver.PatternMultiProcessStreamReceiver) SequenceSingleProcessStreamReceiver(org.wso2.siddhi.core.query.input.stream.state.receiver.SequenceSingleProcessStreamReceiver) SequenceMultiProcessStreamReceiver(org.wso2.siddhi.core.query.input.stream.state.receiver.SequenceMultiProcessStreamReceiver) PatternSingleProcessStreamReceiver(org.wso2.siddhi.core.query.input.stream.state.receiver.PatternSingleProcessStreamReceiver) HashMap(java.util.HashMap) LogicalStateElement(org.wso2.siddhi.query.api.execution.query.input.state.LogicalStateElement) EveryStateElement(org.wso2.siddhi.query.api.execution.query.input.state.EveryStateElement) StreamStateElement(org.wso2.siddhi.query.api.execution.query.input.state.StreamStateElement) NextStateElement(org.wso2.siddhi.query.api.execution.query.input.state.NextStateElement) StateElement(org.wso2.siddhi.query.api.execution.query.input.state.StateElement) CountStateElement(org.wso2.siddhi.query.api.execution.query.input.state.CountStateElement) AbsentStreamStateElement(org.wso2.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement) StreamPreStateProcessor(org.wso2.siddhi.core.query.input.stream.state.StreamPreStateProcessor) AbsentStreamPreStateProcessor(org.wso2.siddhi.core.query.input.stream.state.AbsentStreamPreStateProcessor) SequenceSingleProcessStreamReceiver(org.wso2.siddhi.core.query.input.stream.state.receiver.SequenceSingleProcessStreamReceiver) SequenceMultiProcessStreamReceiver(org.wso2.siddhi.core.query.input.stream.state.receiver.SequenceMultiProcessStreamReceiver) PatternMultiProcessStreamReceiver(org.wso2.siddhi.core.query.input.stream.state.receiver.PatternMultiProcessStreamReceiver) StreamInnerStateRuntime(org.wso2.siddhi.core.query.input.stream.state.runtime.StreamInnerStateRuntime) NextInnerStateRuntime(org.wso2.siddhi.core.query.input.stream.state.runtime.NextInnerStateRuntime) LogicalInnerStateRuntime(org.wso2.siddhi.core.query.input.stream.state.runtime.LogicalInnerStateRuntime) InnerStateRuntime(org.wso2.siddhi.core.query.input.stream.state.runtime.InnerStateRuntime) EveryInnerStateRuntime(org.wso2.siddhi.core.query.input.stream.state.runtime.EveryInnerStateRuntime) CountInnerStateRuntime(org.wso2.siddhi.core.query.input.stream.state.runtime.CountInnerStateRuntime) StateStreamRuntime(org.wso2.siddhi.core.query.input.stream.state.StateStreamRuntime)

Example 5 with StateInputStream

use of org.wso2.siddhi.query.api.execution.query.input.stream.StateInputStream in project siddhi by wso2.

the class PartitionRuntime method addPartitionReceiver.

public void addPartitionReceiver(QueryRuntime queryRuntime, List<VariableExpressionExecutor> executors, MetaStateEvent metaEvent) {
    Query query = queryRuntime.getQuery();
    List<List<PartitionExecutor>> partitionExecutors = new StreamPartitioner(query.getInputStream(), partition, metaEvent, executors, siddhiAppContext, null).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(org.wso2.siddhi.query.api.execution.query.Query) SingleStreamRuntime(org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime) SingleInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.SingleInputStream) JoinStreamRuntime(org.wso2.siddhi.core.query.input.stream.join.JoinStreamRuntime) JoinInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.JoinInputStream) StateElement(org.wso2.siddhi.query.api.execution.query.input.state.StateElement) CountStateElement(org.wso2.siddhi.query.api.execution.query.input.state.CountStateElement) LogicalStateElement(org.wso2.siddhi.query.api.execution.query.input.state.LogicalStateElement) EveryStateElement(org.wso2.siddhi.query.api.execution.query.input.state.EveryStateElement) StreamStateElement(org.wso2.siddhi.query.api.execution.query.input.state.StreamStateElement) NextStateElement(org.wso2.siddhi.query.api.execution.query.input.state.NextStateElement) ArrayList(java.util.ArrayList) List(java.util.List) StateInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.StateInputStream) StateStreamRuntime(org.wso2.siddhi.core.query.input.stream.state.StateStreamRuntime)

Aggregations

StateInputStream (org.wso2.siddhi.query.api.execution.query.input.stream.StateInputStream)6 CountStateElement (org.wso2.siddhi.query.api.execution.query.input.state.CountStateElement)5 EveryStateElement (org.wso2.siddhi.query.api.execution.query.input.state.EveryStateElement)5 NextStateElement (org.wso2.siddhi.query.api.execution.query.input.state.NextStateElement)5 StateElement (org.wso2.siddhi.query.api.execution.query.input.state.StateElement)5 StreamStateElement (org.wso2.siddhi.query.api.execution.query.input.state.StreamStateElement)5 AbsentStreamStateElement (org.wso2.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement)4 ProcessStreamReceiver (org.wso2.siddhi.core.query.input.ProcessStreamReceiver)2 StateStreamRuntime (org.wso2.siddhi.core.query.input.stream.state.StateStreamRuntime)2 LogicalStateElement (org.wso2.siddhi.query.api.execution.query.input.state.LogicalStateElement)2 JoinInputStream (org.wso2.siddhi.query.api.execution.query.input.stream.JoinInputStream)2 SingleInputStream (org.wso2.siddhi.query.api.execution.query.input.stream.SingleInputStream)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)1 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)1 OperationNotSupportedException (org.wso2.siddhi.core.exception.OperationNotSupportedException)1 JoinStreamRuntime (org.wso2.siddhi.core.query.input.stream.join.JoinStreamRuntime)1 SingleStreamRuntime (org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime)1