private static ComplexEventChunk executeSelectorAndReturnChunk(StateEventFactory stateEventFactory,
                                                                   StreamEvent streamEvent, StreamEvent storeEvents,
                                                                   int storeEventIndex, QuerySelector selector) {
        ComplexEventChunk<StateEvent> complexEventChunk = new ComplexEventChunk<>();
        while (storeEvents != null) {

            StreamEvent storeEvent = storeEvents;
            storeEvents = storeEvents.getNext();
            storeEvent.setNext(null);

            StateEvent joinEvent = stateEventFactory.newInstance();
            if (streamEvent == null) {
                joinEvent.addEvent(storeEventIndex, storeEvent);
            } else {
                joinEvent.addEvent(0, streamEvent);
                joinEvent.addEvent(1, storeEvent);
            }
            complexEventChunk.add(joinEvent);
        }
        return selector.execute(complexEventChunk);
    }
Class to hold util functions used during OnDemandQueryRuntime
modules/siddhi-core/src/main/java/io/siddhi/core/util/OnDemandQueryRuntimeUtil.java