Search in sources :

Example 71 with Expression

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

the class MinIncrementalAttributeAggregator method init.

@Override
public void init(String attributeName, Attribute.Type attributeType) {
    if (attributeName == null) {
        throw new SiddhiAppCreationException("Min incremental attribute aggregation cannot be executed " + "when no parameters are given");
    }
    if (attributeType.equals(Attribute.Type.INT) || attributeType.equals(Attribute.Type.LONG) || attributeType.equals(Attribute.Type.DOUBLE) || attributeType.equals(Attribute.Type.FLOAT)) {
        this.baseAttributes = new Attribute[] { new Attribute("AGG_MIN_".concat(attributeName), attributeType) };
        this.baseAttributesInitialValues = new Expression[] { Expression.variable(attributeName) };
        this.returnType = attributeType;
        assert baseAttributes.length == baseAttributesInitialValues.length;
    } else {
        throw new SiddhiAppRuntimeException("Min aggregation cannot be executed on attribute type " + attributeType.toString());
    }
}
Also used : ReturnAttribute(org.wso2.siddhi.annotation.ReturnAttribute) Attribute(org.wso2.siddhi.query.api.definition.Attribute) SiddhiAppCreationException(org.wso2.siddhi.core.exception.SiddhiAppCreationException) SiddhiAppRuntimeException(org.wso2.siddhi.core.exception.SiddhiAppRuntimeException)

Example 72 with Expression

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

Example 73 with Expression

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

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

Example 74 with Expression

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

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

Example 75 with Expression

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

the class SiddhiQLBaseVisitorImpl method visitQuery_section.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public Selector visitQuery_section(@NotNull SiddhiQLParser.Query_sectionContext ctx) {
    // query_section
    // :(SELECT ('*'| (output_attribute (',' output_attribute)* ))) group_by? having?
    // ;
    Selector selector = new Selector();
    List<OutputAttribute> attributeList = new ArrayList<OutputAttribute>(ctx.output_attribute().size());
    for (SiddhiQLParser.Output_attributeContext output_attributeContext : ctx.output_attribute()) {
        attributeList.add((OutputAttribute) visit(output_attributeContext));
    }
    selector.addSelectionList(attributeList);
    if (ctx.group_by() != null) {
        selector.addGroupByList((List<Variable>) visit(ctx.group_by()));
    }
    if (ctx.having() != null) {
        selector.having((Expression) visit(ctx.having()));
    }
    if (ctx.order_by() != null) {
        selector.addOrderByList((List<OrderByAttribute>) visit(ctx.order_by()));
    }
    if (ctx.limit() != null) {
        selector.limit((Constant) visit(ctx.limit()));
    }
    populateQueryContext(selector, ctx);
    return selector;
}
Also used : SiddhiQLParser(org.wso2.siddhi.query.compiler.SiddhiQLParser) Variable(org.wso2.siddhi.query.api.expression.Variable) ArrayList(java.util.ArrayList) OrderByAttribute(org.wso2.siddhi.query.api.execution.query.selection.OrderByAttribute) OutputAttribute(org.wso2.siddhi.query.api.execution.query.selection.OutputAttribute) BasicSelector(org.wso2.siddhi.query.api.execution.query.selection.BasicSelector) Selector(org.wso2.siddhi.query.api.execution.query.selection.Selector)

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