Hive : reflect function

荒凉一梦 提交于 2020-01-14 04:00:37

问题


Im trying to use Reflect function of Hive which have this signature :

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

I want to ckeck if a column c with value hello world ! contains world, so I wrote :

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

But it didnt work because it does not respect the signature, so i tried this

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

It didnt work also ! I want to know how to apply reflect function on a given column ?


回答1:


reflect2 will help.See https://issues.apache.org/jira/browse/HIVE-20007

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

but hashCode() won't work.See 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.


来源:https://stackoverflow.com/questions/38309083/hive-reflect-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!