Search in sources :

Example 6 with UpdateStream

use of io.siddhi.query.api.execution.query.output.stream.UpdateStream in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitQuery_output.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public OutputStream visitQuery_output(@NotNull SiddhiQLParser.Query_outputContext ctx) {
    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);
    }
}
Also used : UpdateOrInsertStream(io.siddhi.query.api.execution.query.output.stream.UpdateOrInsertStream) Expression(io.siddhi.query.api.expression.Expression) DeleteStream(io.siddhi.query.api.execution.query.output.stream.DeleteStream) OutputStream(io.siddhi.query.api.execution.query.output.stream.OutputStream) InsertIntoStream(io.siddhi.query.api.execution.query.output.stream.InsertIntoStream) UpdateStream(io.siddhi.query.api.execution.query.output.stream.UpdateStream) ReturnStream(io.siddhi.query.api.execution.query.output.stream.ReturnStream)

Example 7 with UpdateStream

use of io.siddhi.query.api.execution.query.output.stream.UpdateStream in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitStore_query_output.

/**
 * {@inheritDoc}
 * <p>
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 */
@Override
public OutputStream visitStore_query_output(@NotNull SiddhiQLParser.Store_query_outputContext ctx) {
    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());
        }
        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, "DELETE can be only used with Tables!");
        }
        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 {
        throw newSiddhiParserException(ctx);
    }
}
Also used : Expression(io.siddhi.query.api.expression.Expression) DeleteStream(io.siddhi.query.api.execution.query.output.stream.DeleteStream) OutputStream(io.siddhi.query.api.execution.query.output.stream.OutputStream) UpdateStream(io.siddhi.query.api.execution.query.output.stream.UpdateStream) UpdateSet(io.siddhi.query.api.execution.query.output.stream.UpdateSet)

Example 8 with UpdateStream

use of io.siddhi.query.api.execution.query.output.stream.UpdateStream in project siddhi by wso2.

the class Query method updateBy.

public void updateBy(String outputTableId, UpdateSet updateSetAttributes, Expression onUpdateExpression) {
    this.outputStream = new UpdateStream(outputTableId, updateSetAttributes, onUpdateExpression);
    updateOutputEventType(outputRate, outputStream);
}
Also used : UpdateStream(io.siddhi.query.api.execution.query.output.stream.UpdateStream)

Example 9 with UpdateStream

use of io.siddhi.query.api.execution.query.output.stream.UpdateStream in project siddhi by wso2.

the class Query method updateBy.

public void updateBy(String outputTableId, Expression onUpdateExpression) {
    this.outputStream = new UpdateStream(outputTableId, onUpdateExpression);
    updateOutputEventType(outputRate, outputStream);
}
Also used : UpdateStream(io.siddhi.query.api.execution.query.output.stream.UpdateStream)

Aggregations

UpdateStream (io.siddhi.query.api.execution.query.output.stream.UpdateStream)9 DeleteStream (io.siddhi.query.api.execution.query.output.stream.DeleteStream)5 InsertIntoStream (io.siddhi.query.api.execution.query.output.stream.InsertIntoStream)4 UpdateOrInsertStream (io.siddhi.query.api.execution.query.output.stream.UpdateOrInsertStream)4 OutputStream (io.siddhi.query.api.execution.query.output.stream.OutputStream)3 Expression (io.siddhi.query.api.expression.Expression)3 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)2 Table (io.siddhi.core.table.Table)2 Window (io.siddhi.core.window.Window)2 ReturnStream (io.siddhi.query.api.execution.query.output.stream.ReturnStream)2 UpdateSet (io.siddhi.query.api.execution.query.output.stream.UpdateSet)2 AggregationRuntime (io.siddhi.core.aggregation.AggregationRuntime)1 SiddhiOnDemandQueryContext (io.siddhi.core.config.SiddhiOnDemandQueryContext)1 SiddhiQueryContext (io.siddhi.core.config.SiddhiQueryContext)1 StateEventFactory (io.siddhi.core.event.state.StateEventFactory)1 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)1 StreamEventConverter (io.siddhi.core.event.stream.converter.StreamEventConverter)1 ZeroStreamEventConverter (io.siddhi.core.event.stream.converter.ZeroStreamEventConverter)1 OnDemandQueryCreationException (io.siddhi.core.exception.OnDemandQueryCreationException)1 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)1