public void addQuery(QueryRuntimeImpl metaQueryRuntime) {
        Query query = metaQueryRuntime.getQuery();

        if (query.getOutputStream() instanceof InsertIntoStream &&
                metaQueryRuntime.getOutputCallback() instanceof InsertIntoStreamCallback) {
            InsertIntoStreamCallback insertIntoStreamCallback = (InsertIntoStreamCallback) metaQueryRuntime
                    .getOutputCallback();
            StreamDefinition streamDefinition = insertIntoStreamCallback.getOutputStreamDefinition();
            String id = streamDefinition.getId();

            if (((InsertIntoStream) query.getOutputStream()).isInnerStream()) {
                metaQueryRuntime.setToLocalStream(true);
                localStreamDefinitionMap.putIfAbsent(id, streamDefinition);
                DefinitionParserHelper.validateOutputStream(streamDefinition, localStreamDefinitionMap.get(id));

                StreamJunction outputStreamJunction = localStreamJunctionMap.get(id);

                if (outputStreamJunction == null) {
                    outputStreamJunction = new StreamJunction(streamDefinition,
                            siddhiAppContext.getExecutorService(),
                            siddhiAppContext.getBufferSize(),
                            null, siddhiAppContext);
                    localStreamJunctionMap.putIfAbsent(id, outputStreamJunction);
                }
                insertIntoStreamCallback.init(localStreamJunctionMap.get(id));
            } else {
                streamDefinitionMap.putIfAbsent(id, streamDefinition);
                DefinitionParserHelper.validateOutputStream(streamDefinition, streamDefinitionMap.get(id));
                StreamJunction outputStreamJunction = streamJunctionMap.get(id);

                if (outputStreamJunction == null) {
                    outputStreamJunction = new StreamJunction(streamDefinition,
                            siddhiAppContext.getExecutorService(),
                            siddhiAppContext.getBufferSize(),
                            null, siddhiAppContext);
                    streamJunctionMap.putIfAbsent(id, outputStreamJunction);
                }
                insertIntoStreamCallback.init(streamJunctionMap.get(id));
            }
        } else if (query.getOutputStream() instanceof InsertIntoStream &&
                metaQueryRuntime.getOutputCallback() instanceof InsertIntoWindowCallback) {
            InsertIntoWindowCallback insertIntoWindowCallback = (InsertIntoWindowCallback)
                    metaQueryRuntime.getOutputCallback();
            StreamDefinition streamDefinition = insertIntoWindowCallback.getOutputStreamDefinition();
            String id = streamDefinition.getId();
            DefinitionParserHelper.validateOutputStream(streamDefinition, windowDefinitionMap.get(id));
            StreamJunction outputStreamJunction = streamJunctionMap.get(id);

            if (outputStreamJunction == null) {
                outputStreamJunction = new StreamJunction(streamDefinition,
                        siddhiAppContext.getExecutorService(),
                        siddhiAppContext.getBufferSize(),
                        null, siddhiAppContext);
                streamJunctionMap.putIfAbsent(id, outputStreamJunction);
            }
            insertIntoWindowCallback.getWindow().setPublisher(streamJunctionMap.get(insertIntoWindowCallback
                    .getOutputStreamDefinition().getId()).constructPublisher());
        }

        if (metaQueryRuntime.isFromLocalStream()) {
            for (int i = 0; i < metaQueryRuntime.getStreamRuntime().getSingleStreamRuntimes().size(); i++) {
                String streamId = metaQueryRuntime.getStreamRuntime().getSingleStreamRuntimes().get(i)
                        .getProcessStreamReceiver().getStreamId();
                if (streamId.startsWith("#")) {
                    StreamDefinition streamDefinition = (StreamDefinition) localStreamDefinitionMap.get(streamId);
                    StreamJunction streamJunction = localStreamJunctionMap.get(streamId);
                    if (streamJunction == null) {
                        streamJunction = new StreamJunction(streamDefinition, siddhiAppContext
                                .getExecutorService(),
                                siddhiAppContext.getBufferSize(),
                                null, siddhiAppContext);
                        localStreamJunctionMap.put(streamId, streamJunction);
                    }
                    streamJunction.subscribe(metaQueryRuntime.getStreamRuntime().getSingleStreamRuntimes().get
                            (i).getProcessStreamReceiver());
                }
            }
        }

        queryRuntimeList.add(metaQueryRuntime);
    }
Runtime class to handle partitioning. It will hold all information regarding current partitions and wil create
partition dynamically during runtime.
modules/siddhi-core/src/main/java/io/siddhi/core/partition/PartitionRuntimeImpl.java