Search in sources :

Example 31 with Expression

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

the class AvgIncrementalAttributeAggregator method getBaseAggregators.

@Override
public Expression[] getBaseAggregators() {
    Expression sumAggregator = Expression.function("sum", Expression.variable(getBaseAttributes()[0].getName()));
    Expression countAggregator = Expression.function("sum", Expression.variable(getBaseAttributes()[1].getName()));
    return new Expression[] { sumAggregator, countAggregator };
}
Also used : Expression(org.ballerinalang.siddhi.query.api.expression.Expression)

Example 32 with Expression

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

the class CountIncrementalAttributeAggregator method init.

@Override
public void init(String attributeName, Attribute.Type attributeType) {
    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 };
    assert baseAttributes.length == baseAttributesInitialValues.length;
}
Also used : Attribute(org.ballerinalang.siddhi.query.api.definition.Attribute) ReturnAttribute(org.ballerinalang.siddhi.annotation.ReturnAttribute) 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