hive:反射函数

mi7gmzs6  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(464)

我正在尝试使用具有此签名的配置单元的反射功能:

reflect(class, method[, arg1[, arg2..]])

我想检查一下是否有一个专栏 c 有价值的 hello world ! 包含 world ,于是我写道:

with a as
(select "hello world !" as c)
select reflect("java.lang.String",c ,"contains", "world") from a

但它不起作用,因为它不尊重签名,所以我尝试了这个

with a as
(select "hello world !" as c)
select reflect(reflect("java.lang.Object","toString",c) ,"contains", "world") from a

也没用!我想知道如何申请 reflect 给定列上的函数?

jobtbby3

jobtbby31#

反射2会有帮助。请参阅https://issues.apache.org/jira/browse/hive-20007

select reflect2("stackoverflow","length");  
+------+--+
| _c0  |
+------+--+
| 13   |
+------+--+

但是hashcode()不起作用。看到了吗https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/genericudfreflect2.java#l86

select reflect2("stackoverflow","hashCode");
Error: Error while compiling statement: FAILED: SemanticException [Error 10016]: Line 1:32 Argument type mismatch '"hashCode"': Use hash() UDF instead of this.

相关问题