如何使用自定义 Java 类在 Cassandra 中创建用户定义的函数? [英] How can I create User Defined Functions in Cassandra with Custom Java Class?
问题描述
我在网上找不到这个.如何在 cassandra 中创建自定义用户定义函数?
I couldn't find this anywhere online. How can I create a custom user defined function in cassandra?.
例如:
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?
推荐答案
我也有同样的问题.cassandra 2.2.14 支持 UDF 中的自定义类,但 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.
这篇关于如何使用自定义 Java 类在 Cassandra 中创建用户定义的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!