use of io.siddhi.core.query.processor.stream.window.WindowProcessor in project siddhi by wso2.
the class SingleInputStreamParser method generateProcessor.
public static Processor generateProcessor(StreamHandler streamHandler, MetaComplexEvent metaEvent, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, boolean supportsBatchProcessing, boolean outputExpectsExpiredEvents, boolean findToBeExecuted, SiddhiQueryContext siddhiQueryContext) {
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;
}
if (streamHandler instanceof Window) {
metaStreamEvent.initializeOnAfterWindowData();
}
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, false, SiddhiConstants.CURRENT, ProcessingMode.BATCH, false, siddhiQueryContext);
}
} 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, false, SiddhiConstants.CURRENT, ProcessingMode.BATCH, false, siddhiQueryContext);
}
}
} 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(siddhiQueryContext.getSiddhiAppContext()));
configReader = siddhiQueryContext.getSiddhiContext().getConfigManager().generateConfigReader(((Window) streamHandler).getNamespace(), ((Window) streamHandler).getName());
windowProcessor.initProcessor(metaStreamEvent, attributeExpressionExecutors, configReader, outputExpectsExpiredEvents, findToBeExecuted, false, streamHandler, siddhiQueryContext);
return windowProcessor;
} else if (streamHandler instanceof StreamFunction) {
AbstractStreamProcessor abstractStreamProcessor;
configReader = siddhiQueryContext.getSiddhiContext().getConfigManager().generateConfigReader(((StreamFunction) streamHandler).getNamespace(), ((StreamFunction) streamHandler).getName());
if (supportsBatchProcessing) {
try {
abstractStreamProcessor = (StreamProcessor) SiddhiClassLoader.loadExtensionImplementation((Extension) streamHandler, StreamProcessorExtensionHolder.getInstance(siddhiQueryContext.getSiddhiAppContext()));
abstractStreamProcessor.initProcessor(metaStreamEvent, attributeExpressionExecutors, configReader, outputExpectsExpiredEvents, false, false, streamHandler, siddhiQueryContext);
return abstractStreamProcessor;
} catch (SiddhiAppCreationException e) {
if (!e.isClassLoadingIssue()) {
ExceptionUtil.populateQueryContext(e, streamHandler, siddhiQueryContext.getSiddhiAppContext(), siddhiQueryContext);
throw e;
}
}
}
abstractStreamProcessor = (StreamFunctionProcessor) SiddhiClassLoader.loadExtensionImplementation((Extension) streamHandler, StreamFunctionProcessorExtensionHolder.getInstance(siddhiQueryContext.getSiddhiAppContext()));
abstractStreamProcessor.initProcessor(metaStreamEvent, attributeExpressionExecutors, configReader, outputExpectsExpiredEvents, false, false, streamHandler, siddhiQueryContext);
return abstractStreamProcessor;
} else {
throw new SiddhiAppCreationException(streamHandler.getClass().getName() + " is not supported", streamHandler.getQueryContextStartIndex(), streamHandler.getQueryContextEndIndex());
}
}
use of io.siddhi.core.query.processor.stream.window.WindowProcessor in project siddhi by wso2.
the class JoinInputStreamParser method insertJoinProcessorsAndGetFindable.
private static FindableProcessor insertJoinProcessorsAndGetFindable(JoinProcessor preJoinProcessor, JoinProcessor postJoinProcessor, SingleStreamRuntime streamRuntime, boolean outputExpectsExpiredEvents, InputStream inputStream, SiddhiQueryContext siddhiQueryContext) {
Processor lastProcessor = streamRuntime.getProcessorChain();
Processor prevLastProcessor = null;
boolean containFindable = false;
if (lastProcessor != null) {
containFindable = lastProcessor instanceof FindableProcessor;
while (lastProcessor.getNextProcessor() != null) {
prevLastProcessor = lastProcessor;
lastProcessor = lastProcessor.getNextProcessor();
if (!containFindable) {
containFindable = lastProcessor instanceof FindableProcessor;
}
}
}
if (!containFindable) {
try {
WindowProcessor windowProcessor = new EmptyWindowProcessor();
ExpressionExecutor[] expressionExecutors = new ExpressionExecutor[1];
expressionExecutors[0] = new ConstantExpressionExecutor(0, Attribute.Type.INT);
ConfigReader configReader = siddhiQueryContext.getSiddhiContext().getConfigManager().generateConfigReader("", "lengthBatch");
windowProcessor.initProcessor(((MetaStreamEvent) streamRuntime.getMetaComplexEvent()), expressionExecutors, configReader, outputExpectsExpiredEvents, true, false, inputStream, siddhiQueryContext);
if (lastProcessor != null) {
prevLastProcessor = lastProcessor;
prevLastProcessor.setNextProcessor(windowProcessor);
lastProcessor = windowProcessor;
} else {
lastProcessor = windowProcessor;
}
} catch (Throwable t) {
throw new SiddhiAppCreationException(t);
}
}
if (lastProcessor instanceof FindableProcessor) {
if (prevLastProcessor != null) {
prevLastProcessor.setNextProcessor(preJoinProcessor);
} else {
streamRuntime.setProcessorChain(preJoinProcessor);
}
preJoinProcessor.setNextProcessor(lastProcessor);
lastProcessor.setNextProcessor(postJoinProcessor);
return (FindableProcessor) lastProcessor;
} else {
throw new OperationNotSupportedException("Stream " + ((MetaStreamEvent) streamRuntime.getMetaComplexEvent()).getLastInputDefinition().getId() + "'s last processor " + lastProcessor.getClass().getCanonicalName() + " is not an instance of " + FindableProcessor.class.getCanonicalName() + " hence join cannot be proceed");
}
}
use of io.siddhi.core.query.processor.stream.window.WindowProcessor in project siddhi by wso2.
the class Window method init.
/**
* Initialize the WindowEvent table by creating {@link WindowProcessor} to handle the events.
*
* @param tableMap map of {@link Table}s
* @param eventWindowMap map of EventWindows
* @param windowName name of the query window belongs to.
* @param findToBeExecuted will find will be executed on the window.
*/
public void init(Map<String, Table> tableMap, Map<String, Window> eventWindowMap, String windowName, boolean findToBeExecuted) {
if (this.windowProcessor != null) {
return;
}
// Create and initialize MetaStreamEvent
MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
metaStreamEvent.addInputDefinition(windowDefinition);
metaStreamEvent.setEventType(MetaStreamEvent.EventType.WINDOW);
for (Attribute attribute : windowDefinition.getAttributeList()) {
metaStreamEvent.addOutputData(attribute);
}
this.streamEventFactory = new StreamEventFactory(metaStreamEvent);
StreamEventCloner streamEventCloner = new StreamEventCloner(metaStreamEvent, this.streamEventFactory);
OutputStream.OutputEventType outputEventType = windowDefinition.getOutputEventType();
boolean outputExpectsExpiredEvents = outputEventType != OutputStream.OutputEventType.CURRENT_EVENTS;
SiddhiQueryContext siddhiQueryContext = new SiddhiQueryContext(siddhiAppContext, windowName);
WindowProcessor internalWindowProcessor = (WindowProcessor) SingleInputStreamParser.generateProcessor(windowDefinition.getWindow(), metaStreamEvent, new ArrayList<VariableExpressionExecutor>(), tableMap, false, outputExpectsExpiredEvents, findToBeExecuted, siddhiQueryContext);
internalWindowProcessor.setStreamEventCloner(streamEventCloner);
internalWindowProcessor.constructStreamEventPopulater(metaStreamEvent, 0);
EntryValveProcessor entryValveProcessor = null;
if (internalWindowProcessor instanceof SchedulingProcessor) {
entryValveProcessor = new EntryValveProcessor(this.siddhiAppContext);
Scheduler scheduler = SchedulerParser.parse(entryValveProcessor, siddhiQueryContext);
scheduler.init(this.lockWrapper, windowName);
scheduler.setStreamEventFactory(streamEventFactory);
((SchedulingProcessor) internalWindowProcessor).setScheduler(scheduler);
}
if (entryValveProcessor != null) {
entryValveProcessor.setToLast(internalWindowProcessor);
this.windowProcessor = entryValveProcessor;
} else {
this.windowProcessor = internalWindowProcessor;
}
// StreamPublishProcessor must be the last in chain so that it can publish the events to StreamJunction
this.windowProcessor.setToLast(new StreamPublishProcessor(outputEventType));
this.internalWindowProcessor = internalWindowProcessor;
}
use of io.siddhi.core.query.processor.stream.window.WindowProcessor in project siddhi by siddhi-io.
the class JoinInputStreamParser method insertJoinProcessorsAndGetFindable.
private static FindableProcessor insertJoinProcessorsAndGetFindable(JoinProcessor preJoinProcessor, JoinProcessor postJoinProcessor, SingleStreamRuntime streamRuntime, boolean outputExpectsExpiredEvents, InputStream inputStream, SiddhiQueryContext siddhiQueryContext) {
Processor lastProcessor = streamRuntime.getProcessorChain();
Processor prevLastProcessor = null;
boolean containFindable = false;
if (lastProcessor != null) {
containFindable = lastProcessor instanceof FindableProcessor;
while (lastProcessor.getNextProcessor() != null) {
prevLastProcessor = lastProcessor;
lastProcessor = lastProcessor.getNextProcessor();
if (!containFindable) {
containFindable = lastProcessor instanceof FindableProcessor;
}
}
}
if (!containFindable) {
try {
WindowProcessor windowProcessor = new EmptyWindowProcessor();
ExpressionExecutor[] expressionExecutors = new ExpressionExecutor[1];
expressionExecutors[0] = new ConstantExpressionExecutor(0, Attribute.Type.INT);
ConfigReader configReader = siddhiQueryContext.getSiddhiContext().getConfigManager().generateConfigReader("", "lengthBatch");
windowProcessor.initProcessor(((MetaStreamEvent) streamRuntime.getMetaComplexEvent()), expressionExecutors, configReader, outputExpectsExpiredEvents, true, false, inputStream, siddhiQueryContext);
if (lastProcessor != null) {
prevLastProcessor = lastProcessor;
prevLastProcessor.setNextProcessor(windowProcessor);
lastProcessor = windowProcessor;
} else {
lastProcessor = windowProcessor;
}
} catch (Throwable t) {
throw new SiddhiAppCreationException(t);
}
}
if (lastProcessor instanceof FindableProcessor) {
if (prevLastProcessor != null) {
prevLastProcessor.setNextProcessor(preJoinProcessor);
} else {
streamRuntime.setProcessorChain(preJoinProcessor);
}
preJoinProcessor.setNextProcessor(lastProcessor);
lastProcessor.setNextProcessor(postJoinProcessor);
return (FindableProcessor) lastProcessor;
} else {
throw new OperationNotSupportedException("Stream " + ((MetaStreamEvent) streamRuntime.getMetaComplexEvent()).getLastInputDefinition().getId() + "'s last processor " + lastProcessor.getClass().getCanonicalName() + " is not an instance of " + FindableProcessor.class.getCanonicalName() + " hence join cannot be proceed");
}
}
use of io.siddhi.core.query.processor.stream.window.WindowProcessor in project siddhi by siddhi-io.
the class SingleInputStreamParser method generateProcessor.
public static Processor generateProcessor(StreamHandler streamHandler, MetaComplexEvent metaEvent, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, boolean supportsBatchProcessing, boolean outputExpectsExpiredEvents, boolean findToBeExecuted, SiddhiQueryContext siddhiQueryContext) {
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;
}
if (streamHandler instanceof Window) {
metaStreamEvent.initializeOnAfterWindowData();
}
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, false, SiddhiConstants.CURRENT, ProcessingMode.BATCH, false, siddhiQueryContext);
}
} 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, false, SiddhiConstants.CURRENT, ProcessingMode.BATCH, false, siddhiQueryContext);
}
}
} 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(siddhiQueryContext.getSiddhiAppContext()));
configReader = siddhiQueryContext.getSiddhiContext().getConfigManager().generateConfigReader(((Window) streamHandler).getNamespace(), ((Window) streamHandler).getName());
windowProcessor.initProcessor(metaStreamEvent, attributeExpressionExecutors, configReader, outputExpectsExpiredEvents, findToBeExecuted, false, streamHandler, siddhiQueryContext);
return windowProcessor;
} else if (streamHandler instanceof StreamFunction) {
AbstractStreamProcessor abstractStreamProcessor;
configReader = siddhiQueryContext.getSiddhiContext().getConfigManager().generateConfigReader(((StreamFunction) streamHandler).getNamespace(), ((StreamFunction) streamHandler).getName());
if (supportsBatchProcessing) {
try {
abstractStreamProcessor = (StreamProcessor) SiddhiClassLoader.loadExtensionImplementation((Extension) streamHandler, StreamProcessorExtensionHolder.getInstance(siddhiQueryContext.getSiddhiAppContext()));
abstractStreamProcessor.initProcessor(metaStreamEvent, attributeExpressionExecutors, configReader, outputExpectsExpiredEvents, false, false, streamHandler, siddhiQueryContext);
return abstractStreamProcessor;
} catch (SiddhiAppCreationException e) {
if (!e.isClassLoadingIssue()) {
ExceptionUtil.populateQueryContext(e, streamHandler, siddhiQueryContext.getSiddhiAppContext(), siddhiQueryContext);
throw e;
}
}
}
abstractStreamProcessor = (StreamFunctionProcessor) SiddhiClassLoader.loadExtensionImplementation((Extension) streamHandler, StreamFunctionProcessorExtensionHolder.getInstance(siddhiQueryContext.getSiddhiAppContext()));
abstractStreamProcessor.initProcessor(metaStreamEvent, attributeExpressionExecutors, configReader, outputExpectsExpiredEvents, false, false, streamHandler, siddhiQueryContext);
return abstractStreamProcessor;
} else {
throw new SiddhiAppCreationException(streamHandler.getClass().getName() + " is not supported", streamHandler.getQueryContextStartIndex(), streamHandler.getQueryContextEndIndex());
}
}
Aggregations