use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class JoinProcessor method execute.
private void execute(ComplexEventChunk complexEventChunk, List<ComplexEventChunk> returnEventChunkList) {
StateEvent joinStateEvent = new StateEvent(2, 0);
StreamEvent nextEvent = (StreamEvent) complexEventChunk.getFirst();
complexEventChunk.clear();
while (nextEvent != null) {
StreamEvent streamEvent = nextEvent;
nextEvent = streamEvent.getNext();
streamEvent.setNext(null);
ComplexEvent.Type eventType = streamEvent.getType();
if (eventType == ComplexEvent.Type.TIMER) {
continue;
} else if (eventType == ComplexEvent.Type.RESET) {
if (!leftJoinProcessor) {
StateEvent outputStateEvent = joinEventBuilder(null, streamEvent, eventType);
returnEventChunkList.add(new SelectorTypeComplexEventChunk(new ComplexEventChunk<>(outputStateEvent, outputStateEvent), false));
} else {
StateEvent outputStateEvent = joinEventBuilder(streamEvent, null, eventType);
returnEventChunkList.add(new SelectorTypeComplexEventChunk(new ComplexEventChunk<>(outputStateEvent, outputStateEvent), false));
}
} else {
joinStateEvent.setEvent(matchingStreamIndex, streamEvent);
StreamEvent foundStreamEvent;
if (this.isOptimisedQuery) {
try {
foundStreamEvent = query(joinStateEvent);
} catch (SiddhiAppRuntimeException e) {
log.warn("Performing select clause in databases failed due to '" + e.getMessage() + " in query '" + queryName + "' within Siddhi app '" + siddhiAppName + "' hence reverting back to querying only with where clause.", e);
this.isOptimisedQuery = false;
foundStreamEvent = findableProcessor.find(joinStateEvent, compiledCondition);
}
} else {
foundStreamEvent = findableProcessor.find(joinStateEvent, compiledCondition);
}
joinStateEvent.setEvent(matchingStreamIndex, null);
if (foundStreamEvent == null) {
if (outerJoinProcessor && !leftJoinProcessor) {
StateEvent outputStateEvent = joinEventBuilder(null, streamEvent, eventType);
returnEventChunkList.add(new SelectorTypeComplexEventChunk(new ComplexEventChunk<>(outputStateEvent, outputStateEvent), false));
} else if (outerJoinProcessor && leftJoinProcessor) {
StateEvent outputStateEvent = joinEventBuilder(streamEvent, null, eventType);
returnEventChunkList.add(new SelectorTypeComplexEventChunk(new ComplexEventChunk<>(outputStateEvent, outputStateEvent), false));
}
} else if (!isOptimisedQuery) {
ComplexEventChunk<ComplexEvent> returnEventChunk = new ComplexEventChunk<>();
while (foundStreamEvent != null) {
StreamEvent nextFoundStreamEvent = foundStreamEvent.getNext();
foundStreamEvent.setNext(null);
if (!leftJoinProcessor) {
returnEventChunk.add(joinEventBuilder(foundStreamEvent, streamEvent, eventType));
} else {
returnEventChunk.add(joinEventBuilder(streamEvent, foundStreamEvent, eventType));
}
foundStreamEvent = nextFoundStreamEvent;
}
returnEventChunkList.add(new SelectorTypeComplexEventChunk(returnEventChunk, false));
} else {
ComplexEventChunk<ComplexEvent> returnEventChunk = new ComplexEventChunk<>();
while (foundStreamEvent != null) {
StreamEvent nextFoundStreamEvent = foundStreamEvent.getNext();
StateEvent returnEvent = stateEventFactory.newInstance();
returnEvent.setType(eventType);
returnEvent.setTimestamp(foundStreamEvent.getTimestamp());
Object[] outputData = foundStreamEvent.getOutputData();
for (int i = 0; i < outputData.length; i++) {
Object data = outputData[i];
returnEvent.setOutputData(data, i);
}
returnEventChunk.add(returnEvent);
foundStreamEvent = nextFoundStreamEvent;
}
returnEventChunkList.add(new SelectorTypeComplexEventChunk(returnEventChunk, true));
}
}
}
}
use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class DeleteOnDemandQueryRuntime method generateResetComplexEventChunk.
private ComplexEventChunk<ComplexEvent> generateResetComplexEventChunk(MetaStreamEvent metaStreamEvent) {
StreamEvent streamEvent = new StreamEvent(metaStreamEvent.getBeforeWindowData().size(), metaStreamEvent.getOnAfterWindowData().size(), metaStreamEvent.getOutputData().size());
streamEvent.setType(ComplexEvent.Type.RESET);
StateEvent stateEvent = stateEventFactory.newInstance();
stateEvent.addEvent(0, streamEvent);
stateEvent.setType(ComplexEvent.Type.RESET);
ComplexEventChunk<ComplexEvent> complexEventChunk = new ComplexEventChunk<>();
complexEventChunk.add(stateEvent);
return complexEventChunk;
}
use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class InsertOnDemandQueryRuntime method generateResetComplexEventChunk.
private ComplexEventChunk<ComplexEvent> generateResetComplexEventChunk(MetaStreamEvent metaStreamEvent) {
StreamEvent streamEvent = new StreamEvent(metaStreamEvent.getBeforeWindowData().size(), metaStreamEvent.getOnAfterWindowData().size(), metaStreamEvent.getOutputData().size());
streamEvent.setType(ComplexEvent.Type.RESET);
StateEvent stateEvent = stateEventFactory.newInstance();
stateEvent.addEvent(0, streamEvent);
stateEvent.setType(ComplexEvent.Type.RESET);
ComplexEventChunk<ComplexEvent> complexEventChunk = new ComplexEventChunk<>();
complexEventChunk.add(stateEvent);
return complexEventChunk;
}
use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class InsertIntoWindowCallback method send.
/**
* Add the event into the {@link Window}
*
* @param complexEventChunk the event to add
* @param noOfEvents number of events
*/
@Override
public void send(ComplexEventChunk complexEventChunk, int noOfEvents) {
if (getSiddhiDebugger() != null) {
getSiddhiDebugger().checkBreakPoint(getQueryName(), SiddhiDebugger.QueryTerminal.OUT, complexEventChunk.getFirst());
}
// If events are inserted directly from another window, expired events can arrive
complexEventChunk.reset();
while (complexEventChunk.hasNext()) {
ComplexEvent complexEvent = complexEventChunk.next();
if (complexEvent.getType() == ComplexEvent.Type.EXPIRED) {
complexEvent.setType(ComplexEvent.Type.CURRENT);
}
}
window.add(complexEventChunk);
}
use of io.siddhi.core.event.ComplexEvent in project siddhi by wso2.
the class OutputCallback method constructMatchingStateEventChunk.
protected ComplexEventChunk<StateEvent> constructMatchingStateEventChunk(ComplexEventChunk matchingComplexEventChunk, boolean convertToStreamEvent, StateEventFactory stateEventFactory, int matchingStreamIndex, StreamEventFactory streamEventFactory, StreamEventConverter streamEventConverter) {
ComplexEventChunk<StateEvent> stateEventChunk = new ComplexEventChunk<>();
while (matchingComplexEventChunk.hasNext()) {
ComplexEvent matchingComplexEvent = matchingComplexEventChunk.next();
matchingComplexEventChunk.remove();
StateEvent stateEvent = stateEventFactory.newInstance();
if (convertToStreamEvent) {
StreamEvent borrowEvent = streamEventFactory.newInstance();
streamEventConverter.convertData(matchingComplexEvent.getTimestamp(), matchingComplexEvent.getOutputData(), matchingComplexEvent.getType() == ComplexEvent.Type.EXPIRED ? ComplexEvent.Type.CURRENT : matchingComplexEvent.getType(), borrowEvent);
stateEvent.addEvent(matchingStreamIndex, borrowEvent);
} else {
stateEvent.addEvent(matchingStreamIndex, (StreamEvent) matchingComplexEvent);
}
stateEventChunk.add(stateEvent);
}
return stateEventChunk;
}
Aggregations