【发布时间】:2016-07-11 14:09:12
【问题描述】:
我正在尝试使用具有此签名的 Hive 的 Reflect 函数:
reflect(class, method[, arg1[, arg2..]])
我想检查一个值为hello world ! 的列c 是否包含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 函数?
【问题讨论】:
-
Hive 手册中的所有示例都适用于 static 方法 (cwiki.apache.org/confluence/display/Hive/ReflectUDF) 并且源代码似乎创建了一个新的“类”实例通过调用 constructor-with-no-argument (grepcode.com/file/repo1.maven.org/maven2/org.apache.hive/…) 所以我认为你注定要失败。尝试自定义 UDF。
-
顺便说一句,我猜你的用例涉及比一些简单的字符串原语更复杂的东西(参见
case when C like '%world%' then True else False end) -
谢谢@SamsonScharfrichter,但他们在文档中说:
Reflect uses Java reflection to instantiate and call methods of objects; it can also call static functions。我的目标是掌握反射功能而不是like示例。 -
@SamsonScharfrichter,Hive 手册中的
isEmpty方法呢?示例中使用的参数是什么?如何将其应用于列? -
不知道...看看源代码,如果你能理解的话:-/
标签: hadoop reflection hive hql