Search in sources :

Example 21 with Expression

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

the class SiddhiQLBaseVisitorImpl method visitAnd_math_operation.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public Expression visitAnd_math_operation(@NotNull SiddhiQLParser.And_math_operationContext ctx) {
    if (ctx.AND() != null) {
        Expression expression = Expression.and((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)

Example 22 with Expression

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

the class SiddhiQLBaseVisitorImpl method visitWithin_time_range.

@Override
public Object visitWithin_time_range(SiddhiQLParser.Within_time_rangeContext ctx) {
    Within within;
    if (ctx.end_pattern == null) {
        within = Within.within((Expression) visit(ctx.start_pattern));
    } else {
        within = Within.within((Expression) visit(ctx.start_pattern), (Expression) visit(ctx.end_pattern));
    }
    populateQueryContext(within, ctx);
    return within;
}
Also used : Expression(io.siddhi.query.api.expression.Expression) Within(io.siddhi.query.api.aggregation.Within)

Example 23 with Expression

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

the class AvgIncrementalAttributeAggregator method init.

@Override
public void init(String attributeName, Attribute.Type attributeType) {
    // Send the relevant attribute to this
    Attribute sum;
    Attribute count;
    Expression sumInitialValue;
    Expression countInitialValue;
    if (attributeName == null) {
        throw new SiddhiAppCreationException("Average incremental attribute aggregation cannot be executed " + "when no parameters are given");
    }
    SumIncrementalAttributeAggregator sumIncrementalAttributeAggregator = new SumIncrementalAttributeAggregator();
    sumIncrementalAttributeAggregator.init(attributeName, attributeType);
    CountIncrementalAttributeAggregator countIncrementalAttributeAggregator = new CountIncrementalAttributeAggregator();
    countIncrementalAttributeAggregator.init(null, null);
    // Only one attribute exists for sum and count
    sum = sumIncrementalAttributeAggregator.getBaseAttributes()[0];
    count = countIncrementalAttributeAggregator.getBaseAttributes()[0];
    // Only one init value exists for sum and count
    sumInitialValue = sumIncrementalAttributeAggregator.getBaseAttributeInitialValues()[0];
    countInitialValue = countIncrementalAttributeAggregator.getBaseAttributeInitialValues()[0];
    this.baseAttributes = new Attribute[] { sum, count };
    this.baseAttributesInitialValues = new Expression[] { sumInitialValue, countInitialValue };
}
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)

Example 24 with Expression

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

the class CountIncrementalAttributeAggregator method init.

@Override
public void init(String attributeName, Attribute.Type attributeType) {
    if (attributeName != null) {
        LOG.warn("Aggregation count function will return the count of all events and count(" + attributeName + ") will be considered as count().");
    }
    Attribute count;
    Expression countInitialValue;
    // Since we set the initial value of count, we can simply set it as long
    // However, since count is summed internally (in avg incremental calculation),
    // ensure that either double or long is used here (since return value of sum is long or
    // double. Long is chosen here)
    count = new Attribute("AGG_COUNT", Attribute.Type.LONG);
    countInitialValue = Expression.value(1L);
    this.baseAttributes = new Attribute[] { count };
    this.baseAttributesInitialValues = new Expression[] { countInitialValue };
}
Also used : ReturnAttribute(io.siddhi.annotation.ReturnAttribute) Attribute(io.siddhi.query.api.definition.Attribute) Expression(io.siddhi.query.api.expression.Expression)

Example 25 with Expression

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

the class CacheExpirer method generateExpiryCompiledCondition.

private CompiledCondition generateExpiryCompiledCondition() {
    MetaStreamEvent tableMetaStreamEvent = new MetaStreamEvent();
    tableMetaStreamEvent.setEventType(MetaStreamEvent.EventType.TABLE);
    TableDefinition matchingTableDefinition = TableDefinition.id(cacheTable.getTableDefinition().getId());
    for (Attribute attribute : cacheTable.getTableDefinition().getAttributeList()) {
        tableMetaStreamEvent.addOutputData(attribute);
        matchingTableDefinition.attribute(attribute.getName(), attribute.getType());
    }
    tableMetaStreamEvent.addInputDefinition(matchingTableDefinition);
    streamEventFactory = new StreamEventFactory(tableMetaStreamEvent);
    Variable rightExpressionForSubtract = new Variable(CACHE_TABLE_TIMESTAMP_ADDED);
    rightExpressionForSubtract.setStreamId(cacheTable.getTableDefinition().getId());
    Expression rightExpressionForCompare = new LongConstant(retentionPeriod);
    Compare.Operator greaterThanOperator = Compare.Operator.GREATER_THAN;
    MetaStreamEvent currentTimeMetaStreamEvent = new MetaStreamEvent();
    currentTimeMetaStreamEvent.setEventType(MetaStreamEvent.EventType.TABLE);
    Attribute currentTimeAttribute = new Attribute(CACHE_EXPIRE_CURRENT_TIME, Attribute.Type.LONG);
    currentTimeMetaStreamEvent.addOutputData(currentTimeAttribute);
    TableDefinition currentTimeTableDefinition = TableDefinition.id("");
    currentTimeTableDefinition.attribute(CACHE_EXPIRE_CURRENT_TIME, Attribute.Type.LONG);
    currentTimeMetaStreamEvent.addInputDefinition(currentTimeTableDefinition);
    MetaStateEvent metaStateEvent = new MetaStateEvent(2);
    metaStateEvent.addEvent(currentTimeMetaStreamEvent);
    metaStateEvent.addEvent(tableMetaStreamEvent);
    MatchingMetaInfoHolder matchingMetaInfoHolder = MatcherParser.constructMatchingMetaStateHolder(metaStateEvent, 0, cacheTable.getTableDefinition(), 0);
    List<VariableExpressionExecutor> variableExpressionExecutors = new ArrayList<>();
    Expression leftExpressionForSubtract = new Variable(CACHE_EXPIRE_CURRENT_TIME);
    Expression leftExpressionForCompare = new Subtract(leftExpressionForSubtract, rightExpressionForSubtract);
    Expression deleteCondition = new Compare(leftExpressionForCompare, greaterThanOperator, rightExpressionForCompare);
    SiddhiQueryContext siddhiQueryContext = new SiddhiQueryContext(siddhiAppContext, "expiryDeleteQuery");
    return cacheTable.compileCondition(deleteCondition, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiQueryContext);
}
Also used : LongConstant(io.siddhi.query.api.expression.constant.LongConstant) Variable(io.siddhi.query.api.expression.Variable) Attribute(io.siddhi.query.api.definition.Attribute) StreamEventFactory(io.siddhi.core.event.stream.StreamEventFactory) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) ArrayList(java.util.ArrayList) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) SiddhiQueryContext(io.siddhi.core.config.SiddhiQueryContext) Expression(io.siddhi.query.api.expression.Expression) MatchingMetaInfoHolder(io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder) TableDefinition(io.siddhi.query.api.definition.TableDefinition) Subtract(io.siddhi.query.api.expression.math.Subtract) Compare(io.siddhi.query.api.expression.condition.Compare) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

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