如何使用自定义Java类在Cassandra中创建用户定义函数?

如何使用自定义Java类在Cassandra中创建用户定义函数?

问题描述:

我在网上找不到任何东西。如何在cassandra中创建自定义用户定义的函数?。

I couldn't find this anywhere online. How can I create a custom user defined function in cassandra?.

对于Ex:

CREATE OR REPLACE FUNCTION customfunc(custommap map<text, int>)
CALLED ON NULL INPUT
RETURNS map<int,bigint> 
LANGUAGE java AS 'return MyClass.mymethod(custommap);';

MyClass是可以在类路径中注册的类吗?

Where "MyClass" is a class that I can register in the Classpath?

我也有同样的问题。 UDF中的自定义类在 cassandra 2.2.14 中受支持,但在 cassandra 3.11.4 中不受支持。

I have the same issue, too. The custom class in UDF is support in cassandra 2.2.14, but not in cassandra 3.11.4.

遍历源代码, cassandra 3.11.4 ,在没有父类加载器的情况下设置UDF类加载器,以便它可以完全控制什么UDF使用的类/资源。在 org.apache.cassandra.cql3.functions.UDFunction.java 中,白名单和黑名单用于控制可以访问的类/包。

Go through the source codes, cassandra 3.11.4 setup the UDF class loader with no parent class loader so that it have full control about what class/resource UDF uses. In org.apache.cassandra.cql3.functions.UDFunction.java, a whitelist and blacklist is used to control which class/package can be access.

对于您的问题,应将 MyClass 的全名添加到白名单中,然后重新构建cassandra。

For your issue, you should add the full name of MyClass into whitelist, and re-build the cassandra.