Cassandra UDF:检查零值时出错

发布于 2025-02-06 12:11:31 字数 570 浏览 3 评论 0原文


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;';

我得到了这个错误:

InvalidRequest:来自服务器的错误:代码= 2200 [无效查询]消息=“ Java源编译失败:
第1行:运算符!=对于参数类型长,null
不确定 第1行:操作员!=对于参数类型double,null“

)不确定

在手册中这些比较似乎还可以(例如master/udfs.cql“ rel =“ nofollow noreferrer”>在这里)。 我正在使用Cassandra 4.0.3(通过其Docker映像)。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九命猫 2025-02-13 12:11:32

我发现了这个问题。我将更改为null输入上的null 在null Input上都可以,现在还可以,我希望:)

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

千紇 2025-02-13 12:11:32

这确实是一个爪哇问题,而不是卡桑德拉的问题。

double都是原始的Java数据类型,如果不是初始化的(0l0.0D 分别),因此它们不能为null

有关更多信息,请参见 Java Primitive Data类型。干杯!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文