蜂巢:反映功能

时间:2016-07-11 14:09:13

标签: hadoop reflection hive hql

我试图使用具有此签名的Hive Reflect函数:

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函数?

1 个答案:

答案 0 :(得分:0)

reflect2会有所帮助。请参见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.