1

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).

Hamzeh
  • 11
  • 3

2 Answers2

0

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 :)

Hamzeh
  • 11
  • 3
0

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!

Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23
  • I know differences between primitive types and objects. As can be seen in the accepted answer, by changing the command it became ok. – Hamzeh Jun 18 '22 at 05:34