Search in sources :

Example 16 with Expression

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

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 : 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) Expression(org.ballerinalang.siddhi.query.api.expression.Expression) BasicSingleInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) SingleInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.SingleInputStream) JoinInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.JoinInputStream) InputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.InputStream) BasicSingleInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) SingleInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.SingleInputStream) JoinInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.JoinInputStream) AnonymousInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.AnonymousInputStream) StateInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.StateInputStream) Within(org.ballerinalang.siddhi.query.api.aggregation.Within)

Example 17 with Expression

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

the class SiddhiQLBaseVisitorImpl method visitStore_input.

@Override
public Object visitStore_input(SiddhiQLParser.Store_inputContext ctx) {
    String sourceId = (String) visit(ctx.source_id());
    String alias = null;
    if (ctx.alias() != null) {
        alias = (String) visit(ctx.source_id());
    }
    Store store = InputStore.store(alias, sourceId);
    Expression expression = null;
    if (ctx.expression() != null) {
        expression = (Expression) visit(ctx.expression());
    }
    populateQueryContext(store, ctx);
    if (ctx.per() != null) {
        return store.on(expression, (Within) visit(ctx.within_time_range()), (Expression) visit(ctx.per()));
    } else if (expression != null) {
        return store.on(expression);
    } else {
        return store;
    }
}
Also used : Expression(org.ballerinalang.siddhi.query.api.expression.Expression) Store(org.ballerinalang.siddhi.query.api.execution.query.input.store.Store) InputStore(org.ballerinalang.siddhi.query.api.execution.query.input.store.InputStore)

Example 18 with Expression

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

the class SiddhiQLBaseVisitorImpl method visitGreaterthan_lessthan_math_operation.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public Expression visitGreaterthan_lessthan_math_operation(@NotNull SiddhiQLParser.Greaterthan_lessthan_math_operationContext ctx) {
    Expression expression;
    if (ctx.gt != null) {
        expression = Expression.compare((Expression) visit(ctx.math_operation(0)), Compare.Operator.GREATER_THAN, (Expression) visit(ctx.math_operation(1)));
    } else if (ctx.lt != null) {
        expression = Expression.compare((Expression) visit(ctx.math_operation(0)), Compare.Operator.LESS_THAN, (Expression) visit(ctx.math_operation(1)));
    } else if (ctx.gt_eq != null) {
        expression = Expression.compare((Expression) visit(ctx.math_operation(0)), Compare.Operator.GREATER_THAN_EQUAL, (Expression) visit(ctx.math_operation(1)));
    } else if (ctx.lt_eq != null) {
        expression = Expression.compare((Expression) visit(ctx.math_operation(0)), Compare.Operator.LESS_THAN_EQUAL, (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 19 with Expression

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

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.ballerinalang.siddhi.query.api.expression.Expression)

Example 20 with Expression

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

the class SiddhiQLBaseVisitorImpl method visitNull_check.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public Object visitNull_check(@NotNull SiddhiQLParser.Null_checkContext ctx) {
    Expression expression;
    if (ctx.stream_reference() != null) {
        StreamReference streamReference = (StreamReference) visit(ctx.stream_reference());
        if (streamReference.isInnerStream) {
            // InnerStream
            if (streamReference.streamIndex != null) {
                expression = Expression.isNullInnerStream(streamReference.streamId, streamReference.streamIndex);
            } else {
                expression = Expression.isNullInnerStream(streamReference.streamId);
            }
        } else {
            if (activeStreams.contains(streamReference.streamId)) {
                // Stream
                if (streamReference.streamIndex != null) {
                    expression = Expression.isNullStream(streamReference.streamId, streamReference.streamIndex);
                } else {
                    expression = Expression.isNullStream(streamReference.streamId);
                }
            } else {
                // Attribute
                expression = Expression.isNull(Expression.variable(streamReference.streamId));
            }
        }
    } else if (ctx.function_operation() != null) {
        expression = Expression.isNull((Expression) visit(ctx.function_operation()));
    } else {
        // attribute_reference
        expression = Expression.isNull((Expression) visit(ctx.attribute_reference()));
    }
    populateQueryContext(expression, ctx);
    return expression;
}
Also used : Expression(org.ballerinalang.siddhi.query.api.expression.Expression)

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