Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

georgekjolly avatar image
georgekjolly asked Erick Ramirez commented

Getting AssertionError when executing user defined aggregate

Hi All,

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

user-defined aggregate
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered Erick Ramirez commented

This is a known issue in the Cassandra 3.x releases that has been fixed in 3.11 (CASSANDRA-13399).

As a side note, we don't recommend using 3.10 since it's not officially supported by the community. Either use the latest C* 3.0 or 3.11 releases to avoid running into problems with unsupported versions. Cheers!

2 comments Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Thanks a lot, it worked in 3.11

0 Likes 0 ·

Glad to help. Cheers!

0 Likes 0 ·