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;
}
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;
}
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;
}
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);
}
}
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();
}
}
Aggregations