private static OnDemandQueryRuntime constructOnDemandQueryRuntime(AggregationRuntime aggregation,
                                                                      OnDemandQuery onDemandQuery,
                                                                      Map<String, Table> tableMap,
                                                                      Map<String, Window> windowMap,
                                                                      Within within, Expression per,
                                                                      Expression onCondition,
                                                                      MetaStreamEvent metaStreamEvent,
                                                                      List<VariableExpressionExecutor>
                                                                              variableExpressionExecutors,
                                                                      LockWrapper lockWrapper,
                                                                      SiddhiQueryContext siddhiQueryContext) {
        int metaPosition;
        metaStreamEvent.setEventType(EventType.AGGREGATE);
        initMetaStreamEvent(metaStreamEvent, aggregation.getAggregationDefinition());
        MatchingMetaInfoHolder metaStreamInfoHolder = generateMatchingMetaInfoHolder(metaStreamEvent,
                aggregation.getAggregationDefinition());
        CompiledCondition compiledCondition = aggregation.compileExpression(onCondition, within, per,
                onDemandQuery.getSelector().getGroupByList(), metaStreamInfoHolder, variableExpressionExecutors,
                tableMap, siddhiQueryContext);
        ((IncrementalAggregateCompileCondition) compiledCondition).init();
        metaStreamInfoHolder = ((IncrementalAggregateCompileCondition) compiledCondition).
                getAlteredMatchingMetaInfoHolder();
        FindOnDemandQueryRuntime findOnDemandQueryRuntime = new FindOnDemandQueryRuntime(aggregation, compiledCondition,
                siddhiQueryContext.getName(), metaStreamEvent, siddhiQueryContext);
        metaPosition = 1;
        populateFindOnDemandQueryRuntime(findOnDemandQueryRuntime, metaStreamInfoHolder,
                onDemandQuery.getSelector(), variableExpressionExecutors, tableMap, windowMap,
                metaPosition, !onDemandQuery.getSelector().getGroupByList().isEmpty(), lockWrapper, siddhiQueryContext);
        ComplexEventPopulater complexEventPopulater = StreamEventPopulaterFactory.constructEventPopulator(
                metaStreamInfoHolder.getMetaStateEvent().getMetaStreamEvent(0), 0,
                ((IncrementalAggregateCompileCondition) compiledCondition).getAdditionalAttributes());
        ((IncrementalAggregateCompileCondition) compiledCondition)
                .setComplexEventPopulater(complexEventPopulater);
        return findOnDemandQueryRuntime;
    }
Parse a onDemandQuery and return corresponding OnDemandQueryRuntime.

@param onDemandQuery       onDemandQuery to be parsed.
@param siddhiQueryContext associated Siddhi query context.
@param tableMap         keyvalue containing tables.
@param windowMap        keyvalue containing windows.
@param aggregationMap   keyvalue containing aggregation runtimes.
@return OnDemandQueryRuntime
modules/siddhi-core/src/main/java/io/siddhi/core/util/parser/OnDemandQueryParser.java