use of org.wso2.siddhi.query.api.execution.query.input.state.StateElement 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;
}
use of org.wso2.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())));
}
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);
}
}
use of org.wso2.siddhi.query.api.execution.query.input.state.StateElement 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;
}
use of org.wso2.siddhi.query.api.execution.query.input.state.StateElement 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);
}
}
use of org.wso2.siddhi.query.api.execution.query.input.state.StateElement in project siddhi by wso2.
the class SiddhiQLBaseVisitorImpl method visitPattern_source_chain.
/**
* {@inheritDoc}
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*
* @param ctx
*/
@Override
public Object visitPattern_source_chain(@NotNull SiddhiQLParser.Pattern_source_chainContext ctx) {
if (ctx.pattern_source_chain().size() == 1) {
StateElement stateElement = ((StateElement) visit(ctx.pattern_source_chain(0)));
if (ctx.within_time() != null) {
stateElement.setWithin((TimeConstant) visit(ctx.within_time()));
}
populateQueryContext(stateElement, ctx);
return stateElement;
} else if (ctx.pattern_source_chain().size() == 2) {
NextStateElement nextStateElement = new NextStateElement(((StateElement) visit(ctx.pattern_source_chain(0))), ((StateElement) visit(ctx.pattern_source_chain(1))));
populateQueryContext(nextStateElement, ctx);
return nextStateElement;
} else if (ctx.pattern_source() != null) {
StateElement stateElement = ((StateElement) visit(ctx.pattern_source()));
if (ctx.within_time() != null) {
stateElement.setWithin((TimeConstant) visit(ctx.within_time()));
}
populateQueryContext(stateElement, ctx);
return stateElement;
} else {
throw newSiddhiParserException(ctx);
}
}
Aggregations