Search in sources :

Example 66 with StreamEvent

use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class SelectOnDemandQueryRuntime method execute.

public Event[] execute() {
    try {
        StateEvent stateEvent = new StateEvent(1, 0);
        StreamEvent streamEvents = queryableProcessor.query(stateEvent, compiledCondition, compiledSelection, outputAttributes);
        if (streamEvents == null) {
            return null;
        } else {
            List<Event> events = new ArrayList<Event>();
            while (streamEvents != null) {
                events.add(new Event(streamEvents.getTimestamp(), streamEvents.getOutputData()));
                streamEvents = streamEvents.getNext();
            }
            return events.toArray(new Event[0]);
        }
    } catch (Throwable t) {
        throw new OnDemandQueryRuntimeException("Error executing '" + queryName + "', " + t.getMessage(), t);
    }
}
Also used : StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) ArrayList(java.util.ArrayList) Event(io.siddhi.core.event.Event) ComplexEvent(io.siddhi.core.event.ComplexEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent) StateEvent(io.siddhi.core.event.state.StateEvent) OnDemandQueryRuntimeException(io.siddhi.core.exception.OnDemandQueryRuntimeException)

Example 67 with StreamEvent

use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class SelectOnDemandQueryRuntime method generateResetComplexEventChunk.

private ComplexEventChunk<ComplexEvent> generateResetComplexEventChunk(MetaStreamEvent metaStreamEvent) {
    StreamEvent streamEvent = new StreamEvent(metaStreamEvent.getOutputData().size(), metaStreamEvent.getOnAfterWindowData().size(), metaStreamEvent.getOutputData().size());
    streamEvent.setType(ComplexEvent.Type.RESET);
    StateEvent stateEvent = stateEventFactory.newInstance();
    if (eventType == MetaStreamEvent.EventType.AGGREGATE) {
        stateEvent.addEvent(1, streamEvent);
    } else {
        stateEvent.addEvent(0, streamEvent);
    }
    stateEvent.setType(ComplexEvent.Type.RESET);
    ComplexEventChunk<ComplexEvent> complexEventChunk = new ComplexEventChunk<>();
    complexEventChunk.add(stateEvent);
    return complexEventChunk;
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 68 with StreamEvent

use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class UpdateOrInsertOnDemandQueryRuntime 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;
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 69 with StreamEvent

use of io.siddhi.core.event.stream.StreamEvent 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));
            }
        }
    }
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) SelectorTypeComplexEventChunk(io.siddhi.core.query.selector.SelectorTypeComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException) StateEvent(io.siddhi.core.event.state.StateEvent) SelectorTypeComplexEventChunk(io.siddhi.core.query.selector.SelectorTypeComplexEventChunk)

Example 70 with StreamEvent

use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.

the class AbsentStreamPostStateProcessor method process.

/**
 * This method just mark the state changed but does not send the stateEvent to the next processors.
 *
 * @param stateEvent        the state event
 * @param complexEventChunk the ComplexEventChunk
 */
protected void process(StateEvent stateEvent, ComplexEventChunk complexEventChunk) {
    // Mark the state changed
    thisStatePreProcessor.stateChanged();
    // Update the timestamp
    StreamEvent streamEvent = stateEvent.getStreamEvent(stateId);
    stateEvent.setTimestamp(streamEvent.getTimestamp());
    // This is the notification to AbsentStreamPreStateProcessor that this event has been processed
    this.isEventReturned = true;
    if (thisStatePreProcessor.isStartState) {
        if (nextEveryStatePreProcessor != null && nextEveryStatePreProcessor == thisStatePreProcessor) {
            // nextEveryStatePreProcessor refers the AbsentStreamPreStateProcessor
            nextEveryStatePreProcessor.addEveryState(stateEvent);
        }
    }
    ((AbsentPreStateProcessor) thisStatePreProcessor).updateLastArrivalTime(streamEvent.getTimestamp());
}
Also used : StreamEvent(io.siddhi.core.event.stream.StreamEvent)

Aggregations

StreamEvent (io.siddhi.core.event.stream.StreamEvent)203 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)92 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)74 StateEvent (io.siddhi.core.event.state.StateEvent)52 ComplexEvent (io.siddhi.core.event.ComplexEvent)33 ArrayList (java.util.ArrayList)27 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)26 Map (java.util.Map)24 Event (io.siddhi.core.event.Event)23 Test (org.testng.annotations.Test)23 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)20 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)18 Attribute (io.siddhi.query.api.definition.Attribute)17 HashMap (java.util.HashMap)17 Operation (io.siddhi.core.event.stream.Operation)12 LinkedList (java.util.LinkedList)12 SnapshotableStreamEventQueue (io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue)11 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)10 HashSet (java.util.HashSet)10 StreamEventConverter (io.siddhi.core.event.stream.converter.StreamEventConverter)8