private static OnDemandQueryRuntime constructOnDemandQueryRuntime(Table table, OnDemandQuery onDemandQuery,
                                                                      Map<String, Table> tableMap,
                                                                      Map<String, Window> windowMap,
                                                                      int metaPosition,
                                                                      Expression onCondition,
                                                                      MetaStreamEvent metaStreamEvent,
                                                                      List<VariableExpressionExecutor>
                                                                              variableExpressionExecutors,
                                                                      LockWrapper lockWrapper,
                                                                      SiddhiQueryContext siddhiQueryContext) {
        metaStreamEvent.setEventType(EventType.TABLE);
        if (table instanceof QueryableProcessor && onDemandQuery.getType() == OnDemandQuery.OnDemandQueryType.FIND) {
            try {
                return constructOptimizedOnDemandQueryRuntime(table, onDemandQuery, tableMap,
                        metaPosition, onCondition, metaStreamEvent, variableExpressionExecutors, siddhiQueryContext);
                //In case of error, we try to create the regular on-demand query runtime.
            } catch (SiddhiAppCreationException | SiddhiAppValidationException | QueryableRecordTableException e) {
                if (log.isDebugEnabled()) {
                    log.debug("On-demand query optimization failed for table: "
                            + table.getTableDefinition().getId() + ". Creating On-demand query runtime in normal mode. " +
                            "Reason for failure: " + e.getMessage());
                }
                return constructRegularOnDemandQueryRuntime(table, onDemandQuery, tableMap, windowMap,
                        metaPosition, onCondition, metaStreamEvent, variableExpressionExecutors,
                        lockWrapper, siddhiQueryContext);
            }
        } else {
            return constructRegularOnDemandQueryRuntime(table, onDemandQuery, tableMap, windowMap,
                    metaPosition, onCondition, metaStreamEvent, variableExpressionExecutors,
                    lockWrapper, siddhiQueryContext);
        }
    }
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