Search in sources :

Example 36 with Expression

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

the class SumIncrementalAttributeAggregator method init.

@Override
public void init(String attributeName, Attribute.Type attributeType) {
    Attribute sum;
    Expression sumInitialValue;
    if (attributeName == null) {
        throw new SiddhiAppCreationException("Sum incremental attribute aggregation cannot be executed " + "when no parameters are given");
    }
    if (attributeType.equals(Attribute.Type.FLOAT) || attributeType.equals(Attribute.Type.DOUBLE)) {
        sum = new Attribute("AGG_SUM_".concat(attributeName), Attribute.Type.DOUBLE);
        sumInitialValue = Expression.function("convert", Expression.variable(attributeName), Expression.value("double"));
        returnType = Attribute.Type.DOUBLE;
    } else if (attributeType.equals(Attribute.Type.INT) || attributeType.equals(Attribute.Type.LONG)) {
        sum = new Attribute("AGG_SUM_".concat(attributeName), Attribute.Type.LONG);
        sumInitialValue = Expression.function("convert", Expression.variable(attributeName), Expression.value("long"));
        returnType = Attribute.Type.LONG;
    } else {
        throw new SiddhiAppRuntimeException("Sum aggregation cannot be executed on attribute type " + attributeType.toString());
    }
    this.baseAttributes = new Attribute[] { sum };
    // Original attribute names
    this.baseAttributesInitialValues = new Expression[] { sumInitialValue };
// used for initial values, since those would be executed using original meta
}
Also used : ReturnAttribute(io.siddhi.annotation.ReturnAttribute) Attribute(io.siddhi.query.api.definition.Attribute) Expression(io.siddhi.query.api.expression.Expression) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) SiddhiAppRuntimeException(io.siddhi.core.exception.SiddhiAppRuntimeException)

Example 37 with Expression

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

Example 38 with Expression

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

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

Example 39 with Expression

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

Example 40 with Expression

use of io.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(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