Search in sources :

Example 1 with StateInputStream

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

the class SiddhiQLBaseVisitorImpl method visitSequence_stream.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public StateInputStream visitSequence_stream(@NotNull SiddhiQLParser.Sequence_streamContext ctx) {
    // sequence_stream
    // :every_sequence_source_chain within_time?
    // |every_absent_sequence_source_chain within_time?
    // ;
    StateInputStream stateInputStream;
    TimeConstant within = null;
    if (ctx.within_time() != null) {
        within = (TimeConstant) visit(ctx.within_time());
    }
    if (ctx.every_sequence_source_chain() != null) {
        stateInputStream = new StateInputStream(StateInputStream.Type.SEQUENCE, (StateElement) visitEvery_sequence_source_chain(ctx.every_sequence_source_chain()), within);
    } else {
        stateInputStream = new StateInputStream(StateInputStream.Type.SEQUENCE, (StateElement) visitEvery_absent_sequence_source_chain(ctx.every_absent_sequence_source_chain()), within);
    }
    populateQueryContext(stateInputStream, ctx);
    return stateInputStream;
}
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) StateInputStream(io.siddhi.query.api.execution.query.input.stream.StateInputStream) TimeConstant(io.siddhi.query.api.expression.constant.TimeConstant)

Example 2 with StateInputStream

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

the class SiddhiQLBaseVisitorImpl method visitPattern_stream.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public Object visitPattern_stream(@NotNull SiddhiQLParser.Pattern_streamContext ctx) {
    // pattern_stream
    // : every_pattern_source_chain within_time?
    // | every_absent_pattern_source_chain within_time?
    // ;
    StateElement stateElement;
    if (ctx.every_pattern_source_chain() != null) {
        stateElement = ((StateElement) visit(ctx.every_pattern_source_chain()));
    } else {
        stateElement = ((StateElement) visit(ctx.absent_pattern_source_chain()));
    }
    TimeConstant within = null;
    if (ctx.within_time() != null) {
        within = (TimeConstant) visit(ctx.within_time());
    }
    StateInputStream stateInputStream = new StateInputStream(StateInputStream.Type.PATTERN, stateElement, within);
    populateQueryContext(stateInputStream, ctx);
    return stateInputStream;
}
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) StateInputStream(io.siddhi.query.api.execution.query.input.stream.StateInputStream) TimeConstant(io.siddhi.query.api.expression.constant.TimeConstant)

Example 3 with StateInputStream

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

the class SiddhiAppParser method getFindExecutedElements.

private static List<String> getFindExecutedElements(SiddhiApp siddhiApp) {
    List<String> findExecutedElements = new ArrayList<>();
    for (ExecutionElement executionElement : siddhiApp.getExecutionElementList()) {
        if (executionElement instanceof Query) {
            List<StreamHandler> streamHandlers = new ArrayList<>();
            if (((Query) executionElement).getInputStream() instanceof JoinInputStream) {
                findExecutedElements.addAll(((Query) executionElement).getInputStream().getAllStreamIds());
                streamHandlers.addAll(((SingleInputStream) ((JoinInputStream) ((Query) executionElement).getInputStream()).getLeftInputStream()).getStreamHandlers());
                streamHandlers.addAll(((SingleInputStream) ((JoinInputStream) ((Query) executionElement).getInputStream()).getRightInputStream()).getStreamHandlers());
            } else if (((Query) executionElement).getInputStream() instanceof SingleInputStream) {
                streamHandlers.addAll(((SingleInputStream) ((Query) executionElement).getInputStream()).getStreamHandlers());
            } else if (((Query) executionElement).getInputStream() instanceof StateInputStream) {
                streamHandlers.addAll((((StateInputStream) ((Query) executionElement).getInputStream()).getStreamHandlers()));
            }
            for (StreamHandler streamHandler : streamHandlers) {
                if (streamHandler instanceof In) {
                    findExecutedElements.add(((In) streamHandler).getSourceId());
                }
            }
        } else {
            List<Query> queries = ((Partition) executionElement).getQueryList();
            for (Query query : queries) {
                List<StreamHandler> streamHandlers = new ArrayList<>();
                if (query.getInputStream() instanceof JoinInputStream) {
                    findExecutedElements.addAll(query.getInputStream().getAllStreamIds());
                    streamHandlers.addAll(((SingleInputStream) ((JoinInputStream) query.getInputStream()).getLeftInputStream()).getStreamHandlers());
                    streamHandlers.addAll(((SingleInputStream) ((JoinInputStream) query.getInputStream()).getRightInputStream()).getStreamHandlers());
                } else if (query.getInputStream() instanceof SingleInputStream) {
                    streamHandlers.addAll(((SingleInputStream) query.getInputStream()).getStreamHandlers());
                } else if (query.getInputStream() instanceof StateInputStream) {
                    streamHandlers.addAll((((StateInputStream) query.getInputStream()).getStreamHandlers()));
                }
                for (StreamHandler streamHandler : streamHandlers) {
                    if (streamHandler instanceof In) {
                        findExecutedElements.add(((In) streamHandler).getSourceId());
                    }
                }
            }
        }
    }
    return findExecutedElements;
}
Also used : Partition(io.siddhi.query.api.execution.partition.Partition) Query(io.siddhi.query.api.execution.query.Query) In(io.siddhi.query.api.expression.condition.In) ArrayList(java.util.ArrayList) ExecutionElement(io.siddhi.query.api.execution.ExecutionElement) JoinInputStream(io.siddhi.query.api.execution.query.input.stream.JoinInputStream) SingleInputStream(io.siddhi.query.api.execution.query.input.stream.SingleInputStream) StreamHandler(io.siddhi.query.api.execution.query.input.handler.StreamHandler) StateInputStream(io.siddhi.query.api.execution.query.input.stream.StateInputStream)

Example 4 with StateInputStream

use of io.siddhi.query.api.execution.query.input.stream.StateInputStream 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 5 with StateInputStream

use of io.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 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)

Aggregations

StateInputStream (io.siddhi.query.api.execution.query.input.stream.StateInputStream)5 CountStateElement (io.siddhi.query.api.execution.query.input.state.CountStateElement)3 EveryStateElement (io.siddhi.query.api.execution.query.input.state.EveryStateElement)3 NextStateElement (io.siddhi.query.api.execution.query.input.state.NextStateElement)3 StateElement (io.siddhi.query.api.execution.query.input.state.StateElement)3 StreamStateElement (io.siddhi.query.api.execution.query.input.state.StreamStateElement)3 JoinInputStream (io.siddhi.query.api.execution.query.input.stream.JoinInputStream)3 SingleInputStream (io.siddhi.query.api.execution.query.input.stream.SingleInputStream)3 Query (io.siddhi.query.api.execution.query.Query)2 AbsentStreamStateElement (io.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement)2 TimeConstant (io.siddhi.query.api.expression.constant.TimeConstant)2 ArrayList (java.util.ArrayList)2 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)1 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)1 OperationNotSupportedException (io.siddhi.core.exception.OperationNotSupportedException)1 ProcessStreamReceiver (io.siddhi.core.query.input.ProcessStreamReceiver)1 JoinStreamRuntime (io.siddhi.core.query.input.stream.join.JoinStreamRuntime)1 SingleStreamRuntime (io.siddhi.core.query.input.stream.single.SingleStreamRuntime)1 StateStreamRuntime (io.siddhi.core.query.input.stream.state.StateStreamRuntime)1 ExecutionElement (io.siddhi.query.api.execution.ExecutionElement)1