Search in sources :

Example 1 with OnDemandQueryRuntimeException

use of io.siddhi.core.exception.OnDemandQueryRuntimeException in project siddhi by wso2.

the class FindOnDemandQueryRuntime method execute.

@Override
public Event[] execute() {
    try {
        StateEvent stateEvent = new StateEvent(1, 0);
        StreamEvent streamEvents = null;
        switch(eventType) {
            case TABLE:
                streamEvents = table.find(stateEvent, compiledCondition);
                break;
            case WINDOW:
                streamEvents = window.find(stateEvent, compiledCondition);
                break;
            case AGGREGATE:
                stateEvent = new StateEvent(2, 0);
                streamEvents = aggregation.find(stateEvent, compiledCondition, siddhiQueryContext);
                break;
            case DEFAULT:
                break;
        }
        if (streamEvents == null) {
            return null;
        } else {
            if (selector != null) {
                if (eventType == MetaStreamEvent.EventType.AGGREGATE) {
                    return executeSelector(stateEventFactory, null, streamEvents, 1, selector);
                } else {
                    return executeSelector(stateEventFactory, null, streamEvents, 0, selector);
                }
            } 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 2 with OnDemandQueryRuntimeException

use of io.siddhi.core.exception.OnDemandQueryRuntimeException 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 3 with OnDemandQueryRuntimeException

use of io.siddhi.core.exception.OnDemandQueryRuntimeException in project siddhi by wso2.

the class OnDemandQueryRuntime method execute.

/**
 * This method initiates the execution of on-demand Query.
 *
 * @return an array of Events.
 */
public Event[] execute() {
    try {
        StateEvent stateEvent = new StateEvent(1, outputAttributes.length);
        StreamEvent streamEvent = new StreamEvent(metaStreamEvent.getBeforeWindowData().size(), metaStreamEvent.getOnAfterWindowData().size(), metaStreamEvent.getOutputData().size());
        stateEvent.addEvent(0, streamEvent);
        ComplexEventChunk complexEventChunk = new ComplexEventChunk(stateEvent, stateEvent);
        if (eventType == MetaStreamEvent.EventType.TABLE) {
            selector.process(complexEventChunk);
        } else {
            throw new OnDemandQueryRuntimeException("DELETE, INSERT, UPDATE and UPDATE OR INSERT on-demand Query " + "operations consume only stream events of type \"TABLE\".");
        }
        return new Event[] {};
    } catch (Throwable t) {
        throw new OnDemandQueryRuntimeException("Error executing '" + queryName + "', " + t.getMessage(), t);
    }
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) Event(io.siddhi.core.event.Event) StateEvent(io.siddhi.core.event.state.StateEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent) OnDemandQueryRuntimeException(io.siddhi.core.exception.OnDemandQueryRuntimeException)

Aggregations

Event (io.siddhi.core.event.Event)3 StateEvent (io.siddhi.core.event.state.StateEvent)3 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)3 StreamEvent (io.siddhi.core.event.stream.StreamEvent)3 OnDemandQueryRuntimeException (io.siddhi.core.exception.OnDemandQueryRuntimeException)3 ComplexEvent (io.siddhi.core.event.ComplexEvent)2 ArrayList (java.util.ArrayList)2 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)1