Search in sources :

Example 16 with Expression

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

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 (!streamReference.isFaultStream && activeStreams.contains(streamReference.streamId)) {
                // Stream
                if (streamReference.streamIndex != null) {
                    expression = Expression.isNullStream(streamReference.streamId, streamReference.streamIndex);
                } else {
                    expression = Expression.isNullStream(streamReference.streamId);
                }
            } else if (streamReference.isFaultStream && activeStreams.contains(SiddhiConstants.FAULT_STREAM_FLAG + streamReference.streamId)) {
                // FaultStream
                if (streamReference.streamIndex != null) {
                    expression = Expression.isNullFaultStream(streamReference.streamId, streamReference.streamIndex);
                } else {
                    expression = Expression.isNullFaultStream(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(io.siddhi.query.api.expression.Expression)

Example 17 with Expression

use of io.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)?
    // 
    // |left_source=join_source join right_source=join_source (ON expression)?
    // |left_source=join_source left_unidirectional=UNIDIRECTIONAL join right_source=join_source (ON expression)?
    // 
    // ;
    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 : ValuePartitionType(io.siddhi.query.api.execution.partition.ValuePartitionType) PartitionType(io.siddhi.query.api.execution.partition.PartitionType) RangePartitionType(io.siddhi.query.api.execution.partition.RangePartitionType) Expression(io.siddhi.query.api.expression.Expression) SingleInputStream(io.siddhi.query.api.execution.query.input.stream.SingleInputStream) BasicSingleInputStream(io.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) JoinInputStream(io.siddhi.query.api.execution.query.input.stream.JoinInputStream) StateInputStream(io.siddhi.query.api.execution.query.input.stream.StateInputStream) JoinInputStream(io.siddhi.query.api.execution.query.input.stream.JoinInputStream) SingleInputStream(io.siddhi.query.api.execution.query.input.stream.SingleInputStream) AnonymousInputStream(io.siddhi.query.api.execution.query.input.stream.AnonymousInputStream) InputStream(io.siddhi.query.api.execution.query.input.stream.InputStream) BasicSingleInputStream(io.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) Within(io.siddhi.query.api.aggregation.Within)

Example 18 with Expression

use of io.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(io.siddhi.query.api.expression.Expression)

Example 19 with Expression

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

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

Example 20 with Expression

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

the class SiddhiQLBaseVisitorImpl method visitEquality_math_operation.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public Expression visitEquality_math_operation(@NotNull SiddhiQLParser.Equality_math_operationContext ctx) {
    if (ctx.eq != null) {
        Expression expression = Expression.compare((Expression) visit(ctx.math_operation(0)), Compare.Operator.EQUAL, (Expression) visit(ctx.math_operation(1)));
        populateQueryContext(expression, ctx);
        return expression;
    } else if (ctx.not_eq != null) {
        Expression expression = Expression.compare((Expression) visit(ctx.math_operation(0)), Compare.Operator.NOT_EQUAL, (Expression) visit(ctx.math_operation(1)));
        populateQueryContext(expression, ctx);
        return expression;
    } else {
        throw newSiddhiParserException(ctx);
    }
}
Also used : Expression(io.siddhi.query.api.expression.Expression)

Aggregations

Expression (io.siddhi.query.api.expression.Expression)44 Attribute (io.siddhi.query.api.definition.Attribute)18 Variable (io.siddhi.query.api.expression.Variable)14 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)13 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)13 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)11 ArrayList (java.util.ArrayList)11 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)10 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)10 ConstantExpressionExecutor (io.siddhi.core.executor.ConstantExpressionExecutor)9 OutputAttribute (io.siddhi.query.api.execution.query.selection.OutputAttribute)9 SiddhiQueryContext (io.siddhi.core.config.SiddhiQueryContext)7 AbstractDefinition (io.siddhi.query.api.definition.AbstractDefinition)7 AttributeFunction (io.siddhi.query.api.expression.AttributeFunction)7 Compare (io.siddhi.query.api.expression.condition.Compare)6 Table (io.siddhi.core.table.Table)5 ReturnAttribute (io.siddhi.annotation.ReturnAttribute)4 SiddhiAppRuntimeException (io.siddhi.core.exception.SiddhiAppRuntimeException)4 MatchingMetaInfoHolder (io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)4 HashMap (java.util.HashMap)4