Cassandra UDF: getting error on checking null values

Viewed 28

I wrote an UDF like the below:
CREATE FUNCTION myspace.getValue(lng bigint, dbl double, etc double) RETURNS NULL ON NULL INPUT RETURNS double LANGUAGE java AS 'if (lng != null) {return (double)lng;} else if (dbl != null) { return dbl;} else return etc;';

And I get this error:

InvalidRequest: Error from server: code=2200 [Invalid query] message="Java source compilation failed:
Line 1: The operator != is undefined for the argument type(s) long, null
Line 1: The operator != is undefined for the argument type(s) double, null"

While in manuals these comparisons seems ok (e.g. here). I am using Cassandra 4.0.3 (through its docker image).

2 Answers

I found the problem. I changed RETURNS NULL ON NULL INPUT to CALLED ON NULL INPUT and it is ok now and works as I expect :)

This is really a Java question more than a Cassandra question.

Both double and long are primitive Java data types and are assigned a default value if not initialised (0L or 0.0d respectively) so they can't be null.

For more information, see Java Primitive Data Types. Cheers!

Related