@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);
        }
    }
on-demand query Runtime holds the runtime information needed for executing the on-demand query.
modules/siddhi-core/src/main/java/io/siddhi/core/query/FindOnDemandQueryRuntime.java