@Override
    public OutputStream visitQuery_output(@NotNull SiddhiQLParser.Query_outputContext ctx) {
//        query_output
//        :INSERT output_event_type? INTO target
//        |UPDATE OR INTO INSERT INTO output_event_type? INTO target
//        |DELETE target (FOR output_event_type)? (ON expression)?
//        |UPDATE target (FOR output_event_type)? (ON expression)?
//        |RETURN output_event_type?
//        ;

        if (ctx.INSERT() != null) {
            Source source = (Source) visit(ctx.target());
            if (ctx.UPDATE() != null && ctx.OR() != null) {
                if (source.isInnerStream || source.isFaultStream) {
                    throw newSiddhiParserException(ctx, "UPDATE OR INTO INSERT be only used with Tables!");
                }
                if (ctx.output_event_type() != null) {
                    if (ctx.set_clause() != null) {
                        OutputStream outputStream = new UpdateOrInsertStream(source.streamId,
                                (OutputStream.OutputEventType) visit(ctx.output_event_type()),
                                (UpdateSet) visit(ctx.set_clause()),
                                (Expression) visit(ctx.expression()));
                        populateQueryContext(outputStream, ctx);
                        return outputStream;
                    } else {
                        OutputStream outputStream = new UpdateOrInsertStream(source.streamId,
                                (OutputStream.OutputEventType) visit(ctx.output_event_type()),
                                (Expression) visit(ctx.expression()));
                        populateQueryContext(outputStream, ctx);
                        return outputStream;
                    }
                } else {
                    if (ctx.set_clause() != null) {
                        OutputStream outputStream = new UpdateOrInsertStream(source.streamId,
                                (UpdateSet) visit(ctx.set_clause()), (Expression) visit(ctx.expression()));
                        populateQueryContext(outputStream, ctx);
                        return outputStream;
                    } else {
                        OutputStream outputStream = new UpdateOrInsertStream(source.streamId, (Expression)
                                visit(ctx.expression()));
                        populateQueryContext(outputStream, ctx);
                        return outputStream;
                    }
                }
            } else {
                if (ctx.output_event_type() != null) {
                    OutputStream outputStream = new InsertIntoStream(source.streamId, source.isInnerStream,
                            source.isFaultStream,
                            (OutputStream.OutputEventType) visit(ctx.output_event_type()));
                    populateQueryContext(outputStream, ctx);
                    return outputStream;
                } else {
                    OutputStream outputStream = new InsertIntoStream(source.streamId, source.isInnerStream,
                            source.isFaultStream);
                    populateQueryContext(outputStream, ctx);
                    return outputStream;
                }
            }
        } else if (ctx.DELETE() != null) {
            Source source = (Source) visit(ctx.target());
            if (source.isInnerStream || source.isFaultStream) {
                throw newSiddhiParserException(ctx, "DELETE can be only used with Tables!");
            }
            Expression expression = null;
            if (ctx.expression() != null) {
                expression = (Expression) visit(ctx.expression());
            }
            if (ctx.output_event_type() != null) {
                OutputStream outputStream = new DeleteStream(source.streamId,
                        (OutputStream.OutputEventType) visit(ctx.output_event_type()), expression);
                populateQueryContext(outputStream, ctx);
                return outputStream;
            } else {
                OutputStream outputStream = new DeleteStream(source.streamId, expression);
                populateQueryContext(outputStream, ctx);
                return outputStream;
            }
        } else if (ctx.UPDATE() != null) {
            Source source = (Source) visit(ctx.target());
            if (source.isInnerStream || source.isFaultStream) {
                throw newSiddhiParserException(ctx, "UPDATE can be only used with Tables!");
            }
            if (ctx.output_event_type() != null) {
                if (ctx.set_clause() != null) {
                    OutputStream outputStream = new UpdateStream(source.streamId,
                            (OutputStream.OutputEventType) visit(ctx.output_event_type()),
                            (UpdateSet) visit(ctx.set_clause()),
                            (Expression) visit(ctx.expression()));
                    populateQueryContext(outputStream, ctx);
                    return outputStream;
                } else {
                    OutputStream outputStream = new UpdateStream(source.streamId,
                            (OutputStream.OutputEventType) visit(ctx.output_event_type()),
                            (Expression) visit(ctx.expression()));
                    populateQueryContext(outputStream, ctx);
                    return outputStream;
                }
            } else {
                if (ctx.set_clause() != null) {
                    OutputStream outputStream = new UpdateStream(source.streamId, (UpdateSet) visit(ctx.set_clause()),
                            (Expression) visit(ctx.expression()));
                    populateQueryContext(outputStream, ctx);
                    return outputStream;
                } else {
                    OutputStream outputStream = new UpdateStream(source.streamId,
                            (Expression) visit(ctx.expression()));
                    populateQueryContext(outputStream, ctx);
                    return outputStream;
                }
            }
        } else if (ctx.RETURN() != null) {
            if (ctx.output_event_type() != null) {
                OutputStream outputStream = new ReturnStream((OutputStream.OutputEventType)
                        visit(ctx.output_event_type()));
                populateQueryContext(outputStream, ctx);
                return outputStream;
            } else {
                OutputStream outputStream = new ReturnStream();
                populateQueryContext(outputStream, ctx);
                return outputStream;
            }
        } else {
            throw newSiddhiParserException(ctx);
        }
    }
{@inheritDoc}
<p>The default implementation returns the result of calling
{@link #visitChildren} on {@code ctx}.</p>

@param ctx
modules/siddhi-query-compiler/src/main/java/io/siddhi/query/compiler/internal/SiddhiQLBaseVisitorImpl.java