Search in sources :

Example 76 with Expression

use of org.wso2.siddhi.query.api.expression.Expression in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitAggregation_time_range.

@Override
public TimePeriod visitAggregation_time_range(@NotNull SiddhiQLParser.Aggregation_time_rangeContext ctx) {
    // read left and right contexts
    SiddhiQLParser.Aggregation_time_durationContext left = ctx.aggregation_time_duration().get(0);
    SiddhiQLParser.Aggregation_time_durationContext right = ctx.aggregation_time_duration().get(1);
    // Visit left and right expression using above contexts and create a new
    // RangeTimeSpecifier object
    TimePeriod.Duration leftTimeDuration = visitAggregation_time_duration(left);
    TimePeriod.Duration rightTimeDuration = visitAggregation_time_duration(right);
    TimePeriod timePeriod = TimePeriod.range(leftTimeDuration, rightTimeDuration);
    populateQueryContext(timePeriod, ctx);
    return timePeriod;
}
Also used : SiddhiQLParser(org.wso2.siddhi.query.compiler.SiddhiQLParser) TimePeriod(org.wso2.siddhi.query.api.aggregation.TimePeriod)

Example 77 with Expression

use of org.wso2.siddhi.query.api.expression.Expression in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitAddition_math_operation.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public Expression visitAddition_math_operation(@NotNull SiddhiQLParser.Addition_math_operationContext ctx) {
    Expression expression;
    if (ctx.add != null) {
        expression = Expression.add((Expression) visit(ctx.math_operation(0)), (Expression) visit(ctx.math_operation(1)));
    } else if (ctx.substract != null) {
        expression = Expression.subtract((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.wso2.siddhi.query.api.expression.Expression)

Example 78 with Expression

use of org.wso2.siddhi.query.api.expression.Expression in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitOr_math_operation.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public Object visitOr_math_operation(@NotNull SiddhiQLParser.Or_math_operationContext ctx) {
    if (ctx.OR() != null) {
        Expression expression = Expression.or((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.wso2.siddhi.query.api.expression.Expression)

Example 79 with Expression

use of org.wso2.siddhi.query.api.expression.Expression in project siddhi by wso2.

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.wso2.siddhi.query.api.execution.partition.RangePartitionType) Expression(org.wso2.siddhi.query.api.expression.Expression) ValuePartitionType(org.wso2.siddhi.query.api.execution.partition.ValuePartitionType) PartitionType(org.wso2.siddhi.query.api.execution.partition.PartitionType) RangePartitionType(org.wso2.siddhi.query.api.execution.partition.RangePartitionType) ValuePartitionType(org.wso2.siddhi.query.api.execution.partition.ValuePartitionType)

Example 80 with Expression

use of org.wso2.siddhi.query.api.expression.Expression in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitJoin_stream.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public Object visitJoin_stream(@NotNull SiddhiQLParser.Join_streamContext ctx) {
    // join_stream
    // :left_source=join_source join right_source=join_source right_unidirectional=UNIDIRECTIONAL (ON expression)?
    // within_time?
    // |left_source=join_source join right_source=join_source (ON expression)? within_time?
    // |left_source=join_source left_unidirectional=UNIDIRECTIONAL join right_source=join_source (ON expression)?
    // within_time?
    // ;
    SingleInputStream leftStream = (SingleInputStream) visit(ctx.left_source);
    SingleInputStream rightStream = (SingleInputStream) visit(ctx.right_source);
    JoinInputStream.Type joinType = (JoinInputStream.Type) visit(ctx.join());
    JoinInputStream.EventTrigger eventTrigger = null;
    Expression onCondition = null;
    Within within = null;
    Expression per = null;
    if (ctx.within_time_range() != null) {
        within = (Within) visit(ctx.within_time_range());
    }
    if (ctx.per() != null) {
        per = (Expression) visit(ctx.per());
    }
    if (ctx.expression() != null) {
        onCondition = (Expression) visit(ctx.expression());
    }
    if (ctx.right_unidirectional != null) {
        eventTrigger = JoinInputStream.EventTrigger.RIGHT;
    } else if (ctx.left_unidirectional != null) {
        eventTrigger = JoinInputStream.EventTrigger.LEFT;
    } else {
        eventTrigger = JoinInputStream.EventTrigger.ALL;
    }
    InputStream inputStream = InputStream.joinStream(leftStream, joinType, rightStream, onCondition, eventTrigger, within, per);
    populateQueryContext(inputStream, ctx);
    return inputStream;
}
Also used : PartitionType(org.wso2.siddhi.query.api.execution.partition.PartitionType) RangePartitionType(org.wso2.siddhi.query.api.execution.partition.RangePartitionType) ValuePartitionType(org.wso2.siddhi.query.api.execution.partition.ValuePartitionType) Expression(org.wso2.siddhi.query.api.expression.Expression) BasicSingleInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) SingleInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.SingleInputStream) JoinInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.JoinInputStream) JoinInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.JoinInputStream) BasicSingleInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) InputStream(org.wso2.siddhi.query.api.execution.query.input.stream.InputStream) SingleInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.SingleInputStream) AnonymousInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.AnonymousInputStream) StateInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.StateInputStream) Within(org.wso2.siddhi.query.api.aggregation.Within)

Aggregations

Expression (org.wso2.siddhi.query.api.expression.Expression)32 ArrayList (java.util.ArrayList)20 Attribute (org.wso2.siddhi.query.api.definition.Attribute)16 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)15 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)15 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)13 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)13 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)13 Variable (org.wso2.siddhi.query.api.expression.Variable)11 Test (org.testng.annotations.Test)10 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)10 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)10 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)10 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)9 OutputAttribute (org.wso2.siddhi.query.api.execution.query.selection.OutputAttribute)8 CompiledCondition (org.wso2.siddhi.core.util.collection.operator.CompiledCondition)7 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)6 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)6 MatchingMetaInfoHolder (org.wso2.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)6 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)6