use of io.siddhi.core.event.state.MetaStateEvent 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();
}
}
use of io.siddhi.core.event.state.MetaStateEvent in project siddhi by wso2.
the class MatcherParser method constructMatchingMetaStateHolder.
public static MatchingMetaInfoHolder constructMatchingMetaStateHolder(MetaComplexEvent matchingMetaComplexEvent, int defaultStreamEventIndex, AbstractDefinition candsidateDefinition, int currentState) {
int storeEventIndex = 0;
MetaStreamEvent tableStreamEvent = new MetaStreamEvent();
tableStreamEvent.setEventType(MetaStreamEvent.EventType.TABLE);
tableStreamEvent.addInputDefinition(candsidateDefinition);
for (Attribute attribute : candsidateDefinition.getAttributeList()) {
tableStreamEvent.addOutputData(attribute);
}
MetaStateEvent metaStateEvent = null;
if (matchingMetaComplexEvent instanceof MetaStreamEvent) {
metaStateEvent = new MetaStateEvent(2);
metaStateEvent.addEvent(((MetaStreamEvent) matchingMetaComplexEvent));
metaStateEvent.addEvent(tableStreamEvent);
storeEventIndex = 1;
defaultStreamEventIndex = 0;
if (currentState == SiddhiConstants.UNKNOWN_STATE) {
currentState = defaultStreamEventIndex;
}
} else {
MetaStreamEvent[] metaStreamEvents = ((MetaStateEvent) matchingMetaComplexEvent).getMetaStreamEvents();
// for join
for (; storeEventIndex < metaStreamEvents.length; storeEventIndex++) {
MetaStreamEvent metaStreamEvent = metaStreamEvents[storeEventIndex];
if (storeEventIndex != defaultStreamEventIndex && metaStreamEvent.getLastInputDefinition().equalsIgnoreAnnotations(candsidateDefinition)) {
metaStateEvent = ((MetaStateEvent) matchingMetaComplexEvent);
break;
}
}
if (metaStateEvent == null) {
metaStateEvent = new MetaStateEvent(metaStreamEvents.length + 1);
for (MetaStreamEvent metaStreamEvent : metaStreamEvents) {
metaStateEvent.addEvent(metaStreamEvent);
}
metaStateEvent.addEvent(tableStreamEvent);
storeEventIndex = metaStreamEvents.length;
}
}
return new MatchingMetaInfoHolder(metaStateEvent, defaultStreamEventIndex, storeEventIndex, metaStateEvent.getMetaStreamEvent(defaultStreamEventIndex).getLastInputDefinition(), candsidateDefinition, currentState);
}
use of io.siddhi.core.event.state.MetaStateEvent in project siddhi by wso2.
the class ExpressionBatchWindowProcessor method processAllExpiredEvents.
private void processAllExpiredEvents(StreamEventCloner streamEventCloner, WindowState state, long currentTime, List<ComplexEventChunk<StreamEvent>> streamEventChunks) {
MetaStateEvent metaStateEvent = constructExpression(metaStreamEvent, siddhiQueryContext);
QueryParserHelper.updateVariablePosition(metaStateEvent, variableExpressionExecutors);
if (!streamInputEvents) {
StreamEvent expiredEvent = state.currentEventQueue.getFirst();
state.currentEventQueue.clear();
while (expiredEvent != null) {
StreamEvent aExpiredEvent = expiredEvent;
expiredEvent = expiredEvent.getNext();
aExpiredEvent.setNext(null);
processStreamEvent(state, currentTime, aExpiredEvent, streamEventCloner, streamEventChunks);
}
state.currentEventQueue.reset();
} else {
StreamEvent expiredEvent = state.expiredEventQueue.getFirst();
state.expiredEventQueue.clear();
while (expiredEvent != null) {
StreamEvent aExpiredEvent = expiredEvent;
expiredEvent = expiredEvent.getNext();
aExpiredEvent.setNext(null);
processStreamEventAsStream(state, currentTime, aExpiredEvent, streamEventCloner, streamEventChunks, false);
}
state.expiredEventQueue.reset();
}
}
use of io.siddhi.core.event.state.MetaStateEvent in project siddhi by wso2.
the class ExpressionBatchWindowProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, WindowState state) {
if (expressionStringExecutor == null && !init) {
MetaStateEvent metaStateEvent = new MetaStateEvent(new MetaStreamEvent[] { metaStreamEvent, metaStreamEvent, metaStreamEvent });
QueryParserHelper.updateVariablePosition(metaStateEvent, variableExpressionExecutors);
init = true;
}
List<ComplexEventChunk<StreamEvent>> streamEventChunks = new ArrayList<>();
synchronized (state) {
long currentTime = siddhiQueryContext.getSiddhiAppContext().getTimestampGenerator().currentTime();
while (streamEventChunk.hasNext()) {
StreamEvent streamEvent = streamEventChunk.next();
streamEventChunk.remove();
if (expressionStringExecutor != null) {
String expressionStringNew = (String) expressionStringExecutor.execute(streamEvent);
if (!expressionStringNew.equals(expressionString)) {
expressionString = expressionStringNew;
processAllExpiredEvents(streamEventCloner, state, currentTime, streamEventChunks);
}
}
if (!streamInputEvents) {
processStreamEvent(state, currentTime, streamEvent, streamEventCloner, streamEventChunks);
} else {
processStreamEventAsStream(state, currentTime, streamEvent, streamEventCloner, streamEventChunks, true);
}
}
}
for (ComplexEventChunk<StreamEvent> outputStreamEventChunk : streamEventChunks) {
nextProcessor.process(outputStreamEventChunk);
}
}
use of io.siddhi.core.event.state.MetaStateEvent in project siddhi by wso2.
the class ExpressionWindowProcessor method processAllExpiredEvents.
private void processAllExpiredEvents(ComplexEventChunk<StreamEvent> streamEventChunk, WindowState state, long currentTime) {
MetaStateEvent metaStateEvent = constructExpression(metaStreamEvent, siddhiQueryContext);
QueryParserHelper.updateVariablePosition(metaStateEvent, variableExpressionExecutors);
StreamEvent expiredEvent = state.expiredEventQueue.getFirst();
state.expiredEventQueue.clear();
while (expiredEvent != null) {
StreamEvent aExpiredEvent = expiredEvent;
expiredEvent = expiredEvent.getNext();
aExpiredEvent.setNext(null);
processStreamEvent(streamEventChunk, state, currentTime, aExpiredEvent);
}
state.expiredEventQueue.reset();
}
Aggregations