Add validation for attribute being present in count incremental function
@@ -21,6 +21,7 @@ import org.wso2.siddhi.annotation.Example;
import org.wso2.siddhi.annotation.Extension;
import org.wso2.siddhi.annotation.ReturnAttribute;
import org.wso2.siddhi.annotation.util.DataType;
+import org.wso2.siddhi.core.exception.SiddhiAppCreationException;
import org.wso2.siddhi.query.api.definition.Attribute;
import org.wso2.siddhi.query.api.expression.Expression;
@@ -52,6 +53,12 @@ public class CountIncrementalAttributeAggregator extends IncrementalAttributeAgg
Attribute count;
Expression countInitialValue;
+ //Validation if any attribute is called in count(attribute), count is only for events and not for attributes
+ if (attributeName != null) {
+ throw new SiddhiAppCreationException("Count incremental attribute aggregation cannot be executed " +
+ "when parameters are given. Count function is used to calculate the count of the events only.");
+ }
+
// 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
