use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.
the class SelectorParser method getAttributeProcessors.
/**
* Method to construct AttributeProcessor list for the selector.
*
* @param selector Selector
* @param id stream id
* @param siddhiAppContext siddhi app context
* @param metaComplexEvent meta ComplexEvent
* @param tableMap Table Map
* @param variableExpressionExecutors list of VariableExpressionExecutors
* @param outputStream
* @return list of AttributeProcessors
*/
private static List<AttributeProcessor> getAttributeProcessors(Selector selector, String id, SiddhiAppContext siddhiAppContext, MetaComplexEvent metaComplexEvent, Map<String, Table> tableMap, List<VariableExpressionExecutor> variableExpressionExecutors, OutputStream outputStream, String queryName, int metaPosition) {
List<AttributeProcessor> attributeProcessorList = new ArrayList<>();
StreamDefinition outputDefinition = StreamDefinition.id(id);
outputDefinition.setQueryContextStartIndex(outputStream.getQueryContextStartIndex());
outputDefinition.setQueryContextEndIndex(outputStream.getQueryContextEndIndex());
List<OutputAttribute> outputAttributes = selector.getSelectionList();
if (selector.getSelectionList().size() == 0) {
if (metaComplexEvent instanceof MetaStreamEvent) {
List<Attribute> attributeList = ((MetaStreamEvent) metaComplexEvent).getLastInputDefinition().getAttributeList();
for (Attribute attribute : attributeList) {
outputAttributes.add(new OutputAttribute(new Variable(attribute.getName())));
}
} else {
int position = 0;
for (MetaStreamEvent metaStreamEvent : ((MetaStateEvent) metaComplexEvent).getMetaStreamEvents()) {
if (metaPosition == SiddhiConstants.UNKNOWN_STATE || metaPosition == position) {
List<Attribute> attributeList = metaStreamEvent.getLastInputDefinition().getAttributeList();
for (Attribute attribute : attributeList) {
OutputAttribute outputAttribute = new OutputAttribute(new Variable(attribute.getName()));
if (!outputAttributes.contains(outputAttribute)) {
outputAttributes.add(outputAttribute);
} else {
List<AbstractDefinition> definitions = new ArrayList<>();
for (MetaStreamEvent aMetaStreamEvent : ((MetaStateEvent) metaComplexEvent).getMetaStreamEvents()) {
definitions.add(aMetaStreamEvent.getLastInputDefinition());
}
throw new DuplicateAttributeException("Duplicate attribute exist in streams " + definitions, outputStream.getQueryContextStartIndex(), outputStream.getQueryContextEndIndex());
}
}
}
++position;
}
}
}
int i = 0;
for (OutputAttribute outputAttribute : outputAttributes) {
ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(outputAttribute.getExpression(), metaComplexEvent, SiddhiConstants.UNKNOWN_STATE, tableMap, variableExpressionExecutors, siddhiAppContext, !(selector.getGroupByList().isEmpty()), 0, queryName);
if (expressionExecutor instanceof VariableExpressionExecutor) {
// for variables we will directly put
// value at conversion stage
VariableExpressionExecutor executor = ((VariableExpressionExecutor) expressionExecutor);
if (metaComplexEvent instanceof MetaStateEvent) {
((MetaStateEvent) metaComplexEvent).addOutputDataAllowingDuplicate(new MetaStateEventAttribute(executor.getAttribute(), executor.getPosition()));
} else {
((MetaStreamEvent) metaComplexEvent).addOutputDataAllowingDuplicate(executor.getAttribute());
}
outputDefinition.attribute(outputAttribute.getRename(), ((VariableExpressionExecutor) expressionExecutor).getAttribute().getType());
} else {
// To maintain output variable positions
if (metaComplexEvent instanceof MetaStateEvent) {
((MetaStateEvent) metaComplexEvent).addOutputDataAllowingDuplicate(null);
} else {
((MetaStreamEvent) metaComplexEvent).addOutputDataAllowingDuplicate(null);
}
AttributeProcessor attributeProcessor = new AttributeProcessor(expressionExecutor);
attributeProcessor.setOutputPosition(i);
attributeProcessorList.add(attributeProcessor);
outputDefinition.attribute(outputAttribute.getRename(), attributeProcessor.getOutputType());
}
i++;
}
metaComplexEvent.setOutputDefinition(outputDefinition);
return attributeProcessorList;
}
use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.
the class SingleInputStreamParser method generateProcessor.
public static Processor generateProcessor(StreamHandler streamHandler, MetaComplexEvent metaEvent, List<VariableExpressionExecutor> variableExpressionExecutors, SiddhiAppContext siddhiAppContext, Map<String, Table> tableMap, boolean supportsBatchProcessing, boolean outputExpectsExpiredEvents, String queryName) {
Expression[] parameters = streamHandler.getParameters();
MetaStreamEvent metaStreamEvent;
int stateIndex = SiddhiConstants.UNKNOWN_STATE;
if (metaEvent instanceof MetaStateEvent) {
stateIndex = ((MetaStateEvent) metaEvent).getStreamEventCount() - 1;
metaStreamEvent = ((MetaStateEvent) metaEvent).getMetaStreamEvent(stateIndex);
} else {
metaStreamEvent = (MetaStreamEvent) metaEvent;
}
ExpressionExecutor[] attributeExpressionExecutors;
if (parameters != null) {
if (parameters.length > 0) {
attributeExpressionExecutors = new ExpressionExecutor[parameters.length];
for (int i = 0, parametersLength = parameters.length; i < parametersLength; i++) {
attributeExpressionExecutors[i] = ExpressionParser.parseExpression(parameters[i], metaEvent, stateIndex, tableMap, variableExpressionExecutors, siddhiAppContext, false, SiddhiConstants.CURRENT, queryName);
}
} else {
List<Attribute> attributeList = metaStreamEvent.getLastInputDefinition().getAttributeList();
int parameterSize = attributeList.size();
attributeExpressionExecutors = new ExpressionExecutor[parameterSize];
for (int i = 0; i < parameterSize; i++) {
attributeExpressionExecutors[i] = ExpressionParser.parseExpression(new Variable(attributeList.get(i).getName()), metaEvent, stateIndex, tableMap, variableExpressionExecutors, siddhiAppContext, false, SiddhiConstants.CURRENT, queryName);
}
}
} else {
attributeExpressionExecutors = new ExpressionExecutor[0];
}
ConfigReader configReader;
if (streamHandler instanceof Filter) {
return new FilterProcessor(attributeExpressionExecutors[0]);
} else if (streamHandler instanceof Window) {
WindowProcessor windowProcessor = (WindowProcessor) SiddhiClassLoader.loadExtensionImplementation((Extension) streamHandler, WindowProcessorExtensionHolder.getInstance(siddhiAppContext));
configReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(((Window) streamHandler).getNamespace(), ((Window) streamHandler).getName());
windowProcessor.initProcessor(metaStreamEvent.getLastInputDefinition(), attributeExpressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents, queryName, streamHandler);
return windowProcessor;
} else if (streamHandler instanceof StreamFunction) {
AbstractStreamProcessor abstractStreamProcessor;
configReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(((StreamFunction) streamHandler).getNamespace(), ((StreamFunction) streamHandler).getName());
if (supportsBatchProcessing) {
try {
abstractStreamProcessor = (StreamProcessor) SiddhiClassLoader.loadExtensionImplementation((Extension) streamHandler, StreamProcessorExtensionHolder.getInstance(siddhiAppContext));
metaStreamEvent.addInputDefinition(abstractStreamProcessor.initProcessor(metaStreamEvent.getLastInputDefinition(), attributeExpressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents, queryName, streamHandler));
return abstractStreamProcessor;
} catch (SiddhiAppCreationException e) {
if (!e.isClassLoadingIssue()) {
ExceptionUtil.populateQueryContext(e, streamHandler, siddhiAppContext);
throw e;
}
}
}
abstractStreamProcessor = (StreamFunctionProcessor) SiddhiClassLoader.loadExtensionImplementation((Extension) streamHandler, StreamFunctionProcessorExtensionHolder.getInstance(siddhiAppContext));
metaStreamEvent.addInputDefinition(abstractStreamProcessor.initProcessor(metaStreamEvent.getLastInputDefinition(), attributeExpressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents, queryName, streamHandler));
return abstractStreamProcessor;
} else {
throw new SiddhiAppCreationException(streamHandler.getClass().getName() + " is not supported", streamHandler.getQueryContextStartIndex(), streamHandler.getQueryContextEndIndex());
}
}
use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.
the class SingleInputStreamParser method parseInputStream.
/**
* Parse single InputStream and return SingleStreamRuntime
*
* @param inputStream single input stream to be parsed
* @param siddhiAppContext query to be parsed
* @param variableExpressionExecutors List to hold VariableExpressionExecutors to update after query parsing
* @param streamDefinitionMap Stream Definition Map
* @param tableDefinitionMap Table Definition Map
* @param windowDefinitionMap window definition map
* @param aggregationDefinitionMap aggregation definition map
* @param tableMap Table Map
* @param metaComplexEvent MetaComplexEvent
* @param processStreamReceiver ProcessStreamReceiver
* @param supportsBatchProcessing supports batch processing
* @param outputExpectsExpiredEvents is output expects ExpiredEvents
* @param queryName query name of single input stream belongs to.
*
* @return SingleStreamRuntime
*/
public static SingleStreamRuntime parseInputStream(SingleInputStream inputStream, SiddhiAppContext siddhiAppContext, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, AbstractDefinition> streamDefinitionMap, Map<String, AbstractDefinition> tableDefinitionMap, Map<String, AbstractDefinition> windowDefinitionMap, Map<String, AbstractDefinition> aggregationDefinitionMap, Map<String, Table> tableMap, MetaComplexEvent metaComplexEvent, ProcessStreamReceiver processStreamReceiver, boolean supportsBatchProcessing, boolean outputExpectsExpiredEvents, String queryName) {
Processor processor = null;
EntryValveProcessor entryValveProcessor = null;
boolean first = true;
MetaStreamEvent metaStreamEvent;
if (metaComplexEvent instanceof MetaStateEvent) {
metaStreamEvent = new MetaStreamEvent();
((MetaStateEvent) metaComplexEvent).addEvent(metaStreamEvent);
initMetaStreamEvent(inputStream, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, metaStreamEvent);
} else {
metaStreamEvent = (MetaStreamEvent) metaComplexEvent;
initMetaStreamEvent(inputStream, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, metaStreamEvent);
}
// A window cannot be defined for a window stream
if (!inputStream.getStreamHandlers().isEmpty() && windowDefinitionMap != null && windowDefinitionMap.containsKey(inputStream.getStreamId())) {
for (StreamHandler handler : inputStream.getStreamHandlers()) {
if (handler instanceof Window) {
throw new OperationNotSupportedException("Cannot create " + ((Window) handler).getName() + " " + "window for the window stream " + inputStream.getStreamId());
}
}
}
if (!inputStream.getStreamHandlers().isEmpty()) {
for (StreamHandler handler : inputStream.getStreamHandlers()) {
Processor currentProcessor = generateProcessor(handler, metaComplexEvent, variableExpressionExecutors, siddhiAppContext, tableMap, supportsBatchProcessing, outputExpectsExpiredEvents, queryName);
if (currentProcessor instanceof SchedulingProcessor) {
if (entryValveProcessor == null) {
entryValveProcessor = new EntryValveProcessor(siddhiAppContext);
if (first) {
processor = entryValveProcessor;
first = false;
} else {
processor.setToLast(entryValveProcessor);
}
}
Scheduler scheduler = SchedulerParser.parse(siddhiAppContext.getScheduledExecutorService(), entryValveProcessor, siddhiAppContext);
((SchedulingProcessor) currentProcessor).setScheduler(scheduler);
}
if (first) {
processor = currentProcessor;
first = false;
} else {
processor.setToLast(currentProcessor);
}
}
}
metaStreamEvent.initializeAfterWindowData();
return new SingleStreamRuntime(processStreamReceiver, processor, metaComplexEvent);
}
use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.
the class SingleInputStreamParser method initMetaStreamEvent.
/**
* Method to generate MetaStreamEvent reagent to the given input stream. Empty definition will be created and
* definition and reference is will be set accordingly in this method.
*
* @param inputStream InputStream
* @param streamDefinitionMap StreamDefinition Map
* @param tableDefinitionMap TableDefinition Map
* @param aggregationDefinitionMap AggregationDefinition Map
* @param metaStreamEvent MetaStreamEvent
*/
private static void initMetaStreamEvent(SingleInputStream inputStream, Map<String, AbstractDefinition> streamDefinitionMap, Map<String, AbstractDefinition> tableDefinitionMap, Map<String, AbstractDefinition> windowDefinitionMap, Map<String, AbstractDefinition> aggregationDefinitionMap, MetaStreamEvent metaStreamEvent) {
String streamId = inputStream.getStreamId();
if (!inputStream.isInnerStream() && windowDefinitionMap != null && windowDefinitionMap.containsKey(streamId)) {
AbstractDefinition inputDefinition = windowDefinitionMap.get(streamId);
if (!metaStreamEvent.getInputDefinitions().contains(inputDefinition)) {
metaStreamEvent.addInputDefinition(inputDefinition);
}
} else if (streamDefinitionMap != null && streamDefinitionMap.containsKey(streamId)) {
AbstractDefinition inputDefinition = streamDefinitionMap.get(streamId);
metaStreamEvent.addInputDefinition(inputDefinition);
} else if (!inputStream.isInnerStream() && tableDefinitionMap != null && tableDefinitionMap.containsKey(streamId)) {
AbstractDefinition inputDefinition = tableDefinitionMap.get(streamId);
metaStreamEvent.addInputDefinition(inputDefinition);
} else if (!inputStream.isInnerStream() && aggregationDefinitionMap != null && aggregationDefinitionMap.containsKey(streamId)) {
AbstractDefinition inputDefinition = aggregationDefinitionMap.get(streamId);
metaStreamEvent.addInputDefinition(inputDefinition);
} else {
throw new SiddhiAppCreationException("Stream/table/window/aggregation definition with ID '" + inputStream.getStreamId() + "' has not been defined", inputStream.getQueryContextStartIndex(), inputStream.getQueryContextEndIndex());
}
if ((inputStream.getStreamReferenceId() != null) && !(inputStream.getStreamId()).equals(inputStream.getStreamReferenceId())) {
// if ref id is provided
metaStreamEvent.setInputReferenceId(inputStream.getStreamReferenceId());
}
}
use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.
the class StateInputStreamParser method parse.
private static InnerStateRuntime parse(StateElement stateElement, Map<String, AbstractDefinition> streamDefinitionMap, Map<String, AbstractDefinition> tableDefinitionMap, Map<String, AbstractDefinition> windowDefinitionMap, Map<String, AbstractDefinition> aggregationDefinitionMap, Map<String, Table> tableMap, MetaStateEvent metaStateEvent, SiddhiAppContext siddhiAppContext, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, ProcessStreamReceiver> processStreamReceiverMap, StreamPreStateProcessor streamPreStateProcessor, StreamPostStateProcessor streamPostStateProcessor, StateInputStream.Type stateType, ArrayList<Map.Entry<Long, Set<Integer>>> withinStates, LatencyTracker latencyTracker, String queryName) {
if (stateElement instanceof StreamStateElement) {
BasicSingleInputStream basicSingleInputStream = ((StreamStateElement) stateElement).getBasicSingleInputStream();
SingleStreamRuntime singleStreamRuntime = SingleInputStreamParser.parseInputStream(basicSingleInputStream, siddhiAppContext, variableExpressionExecutors, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, processStreamReceiverMap.get(basicSingleInputStream.getUniqueStreamIds().get(0)), false, false, queryName);
int stateIndex = metaStateEvent.getStreamEventCount() - 1;
if (streamPreStateProcessor == null) {
if (stateElement.getWithin() != null) {
Set<Integer> withinStateset = new HashSet<Integer>();
withinStateset.add(SiddhiConstants.ANY);
withinStates.add(0, new AbstractMap.SimpleEntry<Long, Set<Integer>>(stateElement.getWithin().getValue(), withinStateset));
}
if (stateElement instanceof AbsentStreamStateElement) {
AbsentStreamPreStateProcessor absentProcessor = new AbsentStreamPreStateProcessor(stateType, clonewithinStates(withinStates), ((AbsentStreamStateElement) stateElement).getWaitingTime());
// Set the scheduler
siddhiAppContext.addEternalReferencedHolder(absentProcessor);
EntryValveProcessor entryValveProcessor = new EntryValveProcessor(siddhiAppContext);
entryValveProcessor.setToLast(absentProcessor);
Scheduler scheduler = SchedulerParser.parse(siddhiAppContext.getScheduledExecutorService(), entryValveProcessor, siddhiAppContext);
absentProcessor.setScheduler(scheduler);
// Assign the AbsentStreamPreStateProcessor to streamPreStateProcessor
streamPreStateProcessor = absentProcessor;
} else {
streamPreStateProcessor = new StreamPreStateProcessor(stateType, clonewithinStates(withinStates));
}
streamPreStateProcessor.init(siddhiAppContext, queryName);
if (stateElement.getWithin() != null) {
withinStates.remove(0);
}
}
streamPreStateProcessor.setStateId(stateIndex);
streamPreStateProcessor.setNextProcessor(singleStreamRuntime.getProcessorChain());
singleStreamRuntime.setProcessorChain(streamPreStateProcessor);
if (streamPostStateProcessor == null) {
if (stateElement instanceof AbsentStreamStateElement) {
streamPostStateProcessor = new AbsentStreamPostStateProcessor();
} else {
streamPostStateProcessor = new StreamPostStateProcessor();
}
}
streamPostStateProcessor.setStateId(stateIndex);
singleStreamRuntime.getProcessorChain().setToLast(streamPostStateProcessor);
streamPostStateProcessor.setThisStatePreProcessor(streamPreStateProcessor);
streamPreStateProcessor.setThisStatePostProcessor(streamPostStateProcessor);
streamPreStateProcessor.setThisLastProcessor(streamPostStateProcessor);
StreamInnerStateRuntime innerStateRuntime = new StreamInnerStateRuntime(stateType);
innerStateRuntime.setFirstProcessor(streamPreStateProcessor);
innerStateRuntime.setLastProcessor(streamPostStateProcessor);
innerStateRuntime.addStreamRuntime(singleStreamRuntime);
return innerStateRuntime;
} else if (stateElement instanceof NextStateElement) {
StateElement currentElement = ((NextStateElement) stateElement).getStateElement();
InnerStateRuntime currentInnerStateRuntime = parse(currentElement, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, siddhiAppContext, variableExpressionExecutors, processStreamReceiverMap, streamPreStateProcessor, streamPostStateProcessor, stateType, withinStates, latencyTracker, queryName);
if (stateElement.getWithin() != null) {
Set<Integer> withinStateSet = new HashSet<Integer>();
withinStateSet.add(currentInnerStateRuntime.getFirstProcessor().getStateId());
withinStateSet.add(currentInnerStateRuntime.getLastProcessor().getStateId());
withinStates.add(0, new AbstractMap.SimpleEntry<Long, Set<Integer>>(stateElement.getWithin().getValue(), withinStateSet));
}
StateElement nextElement = ((NextStateElement) stateElement).getNextStateElement();
InnerStateRuntime nextInnerStateRuntime = parse(nextElement, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, siddhiAppContext, variableExpressionExecutors, processStreamReceiverMap, streamPreStateProcessor, streamPostStateProcessor, stateType, withinStates, latencyTracker, queryName);
if (stateElement.getWithin() != null) {
withinStates.remove(0);
}
// currentInnerStateRuntime.getFirstProcessor().getStateId()
currentInnerStateRuntime.getLastProcessor().setNextStatePreProcessor(nextInnerStateRuntime.getFirstProcessor());
NextInnerStateRuntime nextStateRuntime = new NextInnerStateRuntime(currentInnerStateRuntime, nextInnerStateRuntime, stateType);
nextStateRuntime.setFirstProcessor(currentInnerStateRuntime.getFirstProcessor());
nextStateRuntime.setLastProcessor(nextInnerStateRuntime.getLastProcessor());
for (SingleStreamRuntime singleStreamRuntime : currentInnerStateRuntime.getSingleStreamRuntimeList()) {
nextStateRuntime.addStreamRuntime(singleStreamRuntime);
}
for (SingleStreamRuntime singleStreamRuntime : nextInnerStateRuntime.getSingleStreamRuntimeList()) {
nextStateRuntime.addStreamRuntime(singleStreamRuntime);
}
return nextStateRuntime;
} else if (stateElement instanceof EveryStateElement) {
StateElement currentElement = ((EveryStateElement) stateElement).getStateElement();
InnerStateRuntime innerStateRuntime = parse(currentElement, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, siddhiAppContext, variableExpressionExecutors, processStreamReceiverMap, streamPreStateProcessor, streamPostStateProcessor, stateType, withinStates, latencyTracker, queryName);
EveryInnerStateRuntime everyInnerStateRuntime = new EveryInnerStateRuntime(innerStateRuntime, stateType);
everyInnerStateRuntime.setFirstProcessor(innerStateRuntime.getFirstProcessor());
everyInnerStateRuntime.setLastProcessor(innerStateRuntime.getLastProcessor());
for (SingleStreamRuntime singleStreamRuntime : innerStateRuntime.getSingleStreamRuntimeList()) {
everyInnerStateRuntime.addStreamRuntime(singleStreamRuntime);
}
everyInnerStateRuntime.getLastProcessor().setNextEveryStatePerProcessor(everyInnerStateRuntime.getFirstProcessor());
return everyInnerStateRuntime;
} else if (stateElement instanceof LogicalStateElement) {
LogicalStateElement.Type type = ((LogicalStateElement) stateElement).getType();
if (stateElement.getWithin() != null) {
Set<Integer> withinStateset = new HashSet<Integer>();
withinStateset.add(SiddhiConstants.ANY);
withinStates.add(0, new AbstractMap.SimpleEntry<Long, Set<Integer>>(stateElement.getWithin().getValue(), withinStateset));
}
LogicalPreStateProcessor logicalPreStateProcessor1;
if (((LogicalStateElement) stateElement).getStreamStateElement1() instanceof AbsentStreamStateElement) {
logicalPreStateProcessor1 = new AbsentLogicalPreStateProcessor(type, stateType, clonewithinStates(withinStates), ((AbsentStreamStateElement) ((LogicalStateElement) stateElement).getStreamStateElement1()).getWaitingTime());
// Set the scheduler
siddhiAppContext.addEternalReferencedHolder((AbsentLogicalPreStateProcessor) logicalPreStateProcessor1);
EntryValveProcessor entryValveProcessor = new EntryValveProcessor(siddhiAppContext);
entryValveProcessor.setToLast(logicalPreStateProcessor1);
Scheduler scheduler = SchedulerParser.parse(siddhiAppContext.getScheduledExecutorService(), entryValveProcessor, siddhiAppContext);
((SchedulingProcessor) logicalPreStateProcessor1).setScheduler(scheduler);
} else {
logicalPreStateProcessor1 = new LogicalPreStateProcessor(type, stateType, clonewithinStates(withinStates));
}
logicalPreStateProcessor1.init(siddhiAppContext, queryName);
LogicalPostStateProcessor logicalPostStateProcessor1;
if (((LogicalStateElement) stateElement).getStreamStateElement1() instanceof AbsentStreamStateElement) {
logicalPostStateProcessor1 = new AbsentLogicalPostStateProcessor(type);
} else {
logicalPostStateProcessor1 = new LogicalPostStateProcessor(type);
}
LogicalPreStateProcessor logicalPreStateProcessor2;
if (((LogicalStateElement) stateElement).getStreamStateElement2() instanceof AbsentStreamStateElement) {
logicalPreStateProcessor2 = new AbsentLogicalPreStateProcessor(type, stateType, clonewithinStates(withinStates), ((AbsentStreamStateElement) ((LogicalStateElement) stateElement).getStreamStateElement2()).getWaitingTime());
siddhiAppContext.addEternalReferencedHolder((AbsentLogicalPreStateProcessor) logicalPreStateProcessor2);
EntryValveProcessor entryValveProcessor = new EntryValveProcessor(siddhiAppContext);
entryValveProcessor.setToLast(logicalPreStateProcessor2);
Scheduler scheduler = SchedulerParser.parse(siddhiAppContext.getScheduledExecutorService(), entryValveProcessor, siddhiAppContext);
((SchedulingProcessor) logicalPreStateProcessor2).setScheduler(scheduler);
} else {
logicalPreStateProcessor2 = new LogicalPreStateProcessor(type, stateType, clonewithinStates(withinStates));
}
logicalPreStateProcessor2.init(siddhiAppContext, queryName);
LogicalPostStateProcessor logicalPostStateProcessor2;
if (((LogicalStateElement) stateElement).getStreamStateElement2() instanceof AbsentStreamStateElement) {
logicalPostStateProcessor2 = new AbsentLogicalPostStateProcessor(type);
} else {
logicalPostStateProcessor2 = new LogicalPostStateProcessor(type);
}
if (stateElement.getWithin() != null) {
withinStates.remove(0);
}
logicalPostStateProcessor1.setPartnerPreStateProcessor(logicalPreStateProcessor2);
logicalPostStateProcessor2.setPartnerPreStateProcessor(logicalPreStateProcessor1);
logicalPostStateProcessor1.setPartnerPostStateProcessor(logicalPostStateProcessor2);
logicalPostStateProcessor2.setPartnerPostStateProcessor(logicalPostStateProcessor1);
logicalPreStateProcessor1.setPartnerStatePreProcessor(logicalPreStateProcessor2);
logicalPreStateProcessor2.setPartnerStatePreProcessor(logicalPreStateProcessor1);
StateElement stateElement2 = ((LogicalStateElement) stateElement).getStreamStateElement2();
InnerStateRuntime innerStateRuntime2 = parse(stateElement2, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, siddhiAppContext, variableExpressionExecutors, processStreamReceiverMap, logicalPreStateProcessor2, logicalPostStateProcessor2, stateType, withinStates, latencyTracker, queryName);
StateElement stateElement1 = ((LogicalStateElement) stateElement).getStreamStateElement1();
InnerStateRuntime innerStateRuntime1 = parse(stateElement1, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, siddhiAppContext, variableExpressionExecutors, processStreamReceiverMap, logicalPreStateProcessor1, logicalPostStateProcessor1, stateType, withinStates, latencyTracker, queryName);
LogicalInnerStateRuntime logicalInnerStateRuntime = new LogicalInnerStateRuntime(innerStateRuntime1, innerStateRuntime2, stateType);
logicalInnerStateRuntime.setFirstProcessor(innerStateRuntime1.getFirstProcessor());
logicalInnerStateRuntime.setLastProcessor(innerStateRuntime2.getLastProcessor());
for (SingleStreamRuntime singleStreamRuntime : innerStateRuntime2.getSingleStreamRuntimeList()) {
logicalInnerStateRuntime.addStreamRuntime(singleStreamRuntime);
}
for (SingleStreamRuntime singleStreamRuntime : innerStateRuntime1.getSingleStreamRuntimeList()) {
logicalInnerStateRuntime.addStreamRuntime(singleStreamRuntime);
}
return logicalInnerStateRuntime;
} else if (stateElement instanceof CountStateElement) {
int minCount = ((CountStateElement) stateElement).getMinCount();
int maxCount = ((CountStateElement) stateElement).getMaxCount();
if (minCount == SiddhiConstants.ANY) {
minCount = 0;
}
if (maxCount == SiddhiConstants.ANY) {
maxCount = Integer.MAX_VALUE;
}
if (stateElement.getWithin() != null) {
Set<Integer> withinStateset = new HashSet<Integer>();
withinStateset.add(SiddhiConstants.ANY);
withinStates.add(0, new AbstractMap.SimpleEntry<Long, Set<Integer>>(stateElement.getWithin().getValue(), withinStateset));
}
CountPreStateProcessor countPreStateProcessor = new CountPreStateProcessor(minCount, maxCount, stateType, withinStates);
countPreStateProcessor.init(siddhiAppContext, queryName);
CountPostStateProcessor countPostStateProcessor = new CountPostStateProcessor(minCount, maxCount);
if (stateElement.getWithin() != null) {
withinStates.remove(0);
}
countPreStateProcessor.setCountPostStateProcessor(countPostStateProcessor);
StateElement currentElement = ((CountStateElement) stateElement).getStreamStateElement();
InnerStateRuntime innerStateRuntime = parse(currentElement, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, metaStateEvent, siddhiAppContext, variableExpressionExecutors, processStreamReceiverMap, countPreStateProcessor, countPostStateProcessor, stateType, withinStates, latencyTracker, queryName);
return new CountInnerStateRuntime((StreamInnerStateRuntime) innerStateRuntime);
} else {
throw new OperationNotSupportedException();
}
}
Aggregations