Search in sources :

Example 11 with Expression

use of org.ballerinalang.siddhi.query.api.expression.Expression in project ballerina by ballerina-lang.

the class SiddhiQLBaseVisitorImpl method visitPartition_with_stream.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public PartitionType visitPartition_with_stream(@NotNull SiddhiQLParser.Partition_with_streamContext ctx) {
    String streamId = (String) visit(ctx.stream_id());
    activeStreams.add(streamId);
    try {
        if (ctx.condition_ranges() != null) {
            PartitionType partitionType = new RangePartitionType(streamId, (RangePartitionType.RangePartitionProperty[]) visit(ctx.condition_ranges()));
            populateQueryContext(partitionType, ctx);
            return partitionType;
        } else if (ctx.attribute() != null) {
            PartitionType partitionType = new ValuePartitionType(streamId, (Expression) visit(ctx.attribute()));
            populateQueryContext(partitionType, ctx);
            return partitionType;
        } else {
            throw newSiddhiParserException(ctx);
        }
    } finally {
        activeStreams.clear();
    }
}
Also used : RangePartitionType(org.ballerinalang.siddhi.query.api.execution.partition.RangePartitionType) Expression(org.ballerinalang.siddhi.query.api.expression.Expression) ValuePartitionType(org.ballerinalang.siddhi.query.api.execution.partition.ValuePartitionType) RangePartitionType(org.ballerinalang.siddhi.query.api.execution.partition.RangePartitionType) ValuePartitionType(org.ballerinalang.siddhi.query.api.execution.partition.ValuePartitionType) PartitionType(org.ballerinalang.siddhi.query.api.execution.partition.PartitionType)

Example 12 with Expression

use of org.ballerinalang.siddhi.query.api.expression.Expression in project ballerina by ballerina-lang.

the class SiddhiQLBaseVisitorImpl method visitAnd_math_operation.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public Expression visitAnd_math_operation(@NotNull SiddhiQLParser.And_math_operationContext ctx) {
    if (ctx.AND() != null) {
        Expression expression = Expression.and((Expression) visit(ctx.math_operation(0)), (Expression) visit(ctx.math_operation(1)));
        populateQueryContext(expression, ctx);
        return expression;
    } else {
        throw newSiddhiParserException(ctx);
    }
}
Also used : Expression(org.ballerinalang.siddhi.query.api.expression.Expression)

Example 13 with Expression

use of org.ballerinalang.siddhi.query.api.expression.Expression in project ballerina by ballerina-lang.

the class SiddhiQLBaseVisitorImpl method visitNot_math_operation.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public Expression visitNot_math_operation(@NotNull SiddhiQLParser.Not_math_operationContext ctx) {
    Expression expression = Expression.not((Expression) visit(ctx.math_operation()));
    populateQueryContext(expression, ctx);
    return expression;
}
Also used : Expression(org.ballerinalang.siddhi.query.api.expression.Expression)

Example 14 with Expression

use of org.ballerinalang.siddhi.query.api.expression.Expression in project ballerina by ballerina-lang.

the class SiddhiQLBaseVisitorImpl method visitMultiplication_math_operation.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public Expression visitMultiplication_math_operation(@NotNull SiddhiQLParser.Multiplication_math_operationContext ctx) {
    Expression expression;
    if (ctx.multiply != null) {
        expression = Expression.multiply((Expression) visit(ctx.math_operation(0)), (Expression) visit(ctx.math_operation(1)));
    } else if (ctx.devide != null) {
        expression = Expression.divide((Expression) visit(ctx.math_operation(0)), (Expression) visit(ctx.math_operation(1)));
    } else if (ctx.mod != null) {
        expression = Expression.mod((Expression) visit(ctx.math_operation(0)), (Expression) visit(ctx.math_operation(1)));
    } else {
        throw newSiddhiParserException(ctx);
    }
    populateQueryContext(expression, ctx);
    return expression;
}
Also used : Expression(org.ballerinalang.siddhi.query.api.expression.Expression)

Example 15 with Expression

use of org.ballerinalang.siddhi.query.api.expression.Expression in project ballerina by ballerina-lang.

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) {
                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, (OutputStream.OutputEventType) visit(ctx.output_event_type()));
                populateQueryContext(outputStream, ctx);
                return outputStream;
            } else {
                OutputStream outputStream = new InsertIntoStream(source.streamId, source.isInnerStream);
                populateQueryContext(outputStream, ctx);
                return outputStream;
            }
        }
    } else if (ctx.DELETE() != null) {
        Source source = (Source) visit(ctx.target());
        if (source.isInnerStream) {
            throw newSiddhiParserException(ctx, "DELETE can be only used with Tables!");
        }
        if (ctx.output_event_type() != null) {
            OutputStream outputStream = new DeleteStream(source.streamId, (OutputStream.OutputEventType) visit(ctx.output_event_type()), (Expression) visit(ctx.expression()));
            populateQueryContext(outputStream, ctx);
            return outputStream;
        } else {
            OutputStream outputStream = new DeleteStream(source.streamId, (Expression) visit(ctx.expression()));
            populateQueryContext(outputStream, ctx);
            return outputStream;
        }
    } else if (ctx.UPDATE() != null) {
        Source source = (Source) visit(ctx.target());
        if (source.isInnerStream) {
            throw newSiddhiParserException(ctx, "DELETE 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(org.ballerinalang.siddhi.query.api.execution.query.output.stream.UpdateOrInsertStream) Expression(org.ballerinalang.siddhi.query.api.expression.Expression) DeleteStream(org.ballerinalang.siddhi.query.api.execution.query.output.stream.DeleteStream) OutputStream(org.ballerinalang.siddhi.query.api.execution.query.output.stream.OutputStream) InsertIntoStream(org.ballerinalang.siddhi.query.api.execution.query.output.stream.InsertIntoStream) UpdateStream(org.ballerinalang.siddhi.query.api.execution.query.output.stream.UpdateStream) ReturnStream(org.ballerinalang.siddhi.query.api.execution.query.output.stream.ReturnStream)

Aggregations

Expression (org.ballerinalang.siddhi.query.api.expression.Expression)32 Attribute (org.ballerinalang.siddhi.query.api.definition.Attribute)11 SiddhiAppCreationException (org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException)10 VariableExpressionExecutor (org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor)9 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)7 ExpressionExecutor (org.ballerinalang.siddhi.core.executor.ExpressionExecutor)7 Variable (org.ballerinalang.siddhi.query.api.expression.Variable)7 ArrayList (java.util.ArrayList)6 OutputAttribute (org.ballerinalang.siddhi.query.api.execution.query.selection.OutputAttribute)5 MetaStateEvent (org.ballerinalang.siddhi.core.event.state.MetaStateEvent)4 IncrementalAttributeAggregator (org.ballerinalang.siddhi.core.query.selector.attribute.aggregator.incremental.IncrementalAttributeAggregator)4 AttributeFunction (org.ballerinalang.siddhi.query.api.expression.AttributeFunction)4 ReturnAttribute (org.ballerinalang.siddhi.annotation.ReturnAttribute)3 Table (org.ballerinalang.siddhi.core.table.Table)3 Within (org.ballerinalang.siddhi.query.api.aggregation.Within)3 AbstractDefinition (org.ballerinalang.siddhi.query.api.definition.AbstractDefinition)3 AggregationRuntime (org.ballerinalang.siddhi.core.aggregation.AggregationRuntime)2 SingleStreamRuntime (org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime)2 CompiledCondition (org.ballerinalang.siddhi.core.util.collection.operator.CompiledCondition)2 MatchingMetaInfoHolder (org.ballerinalang.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)2