use of org.ballerinalang.siddhi.query.api.definition.Attribute in project ballerina by ballerina-lang.
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 };
assert baseAttributes.length == baseAttributesInitialValues.length;
}
use of org.ballerinalang.siddhi.query.api.definition.Attribute 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;
}
Aggregations