0
votes

I have implemented user defined aggregate function average in my cassandra db as described in the link https://docs.datastax.com/en/dse/5.1/cql/cql/cql_using/useCreateUDA.html

CREATE OR REPLACE FUNCTION avgState ( state tuple<int,bigint>, val int ) CALLED ON NULL INPUT RETURNS tuple<int,bigint> LANGUAGE java AS 'if (val !=null) { state.setInt(0, state.getInt(0)+1); state.setLong(1, state.getLong(1)+val.intValue()); } return state;';

CREATE OR REPLACE FUNCTION avgFinal ( state tuple<int,bigint> ) CALLED ON NULL INPUT RETURNS double LANGUAGE java AS 'double r = 0; if (state.getInt(0) == 0) return null; r = state.getLong(1); r/= state.getInt(0); return Double.valueOf(r);';

CREATE AGGREGATE IF NOT EXISTS average ( int ) SFUNC avgState STYPE tuple<int,bigint> FINALFUNC avgFinal INITCOND (0,0);

User defined aggregate function average works fine when the query returns at least one row for aggregation. But when there is no row returned for aggregation, the query outputs the error ServerError: java.lang.AssertionError

Requesting help.

My cassandra db version is [cqlsh 5.0.1 | Cassandra 3.10 | CQL spec 3.4.4 | Native protocol v4]

Thanks in Advance, George

1

1 Answers