Hive调用Java类ReflectUDF

版权声明:本文为博主原创文章,欢迎转载,转载请注明出处。 https://blog.csdn.net/u012802702/article/details/70199266

关于Hive调用Java类的方法,Hive的官方描述如下:

ReflectUDF

Skip to end of metadata
Reflect (Generic) UDF:必须是静态方法

A Java class and method often exists to handle the exact function a user would like to use in Hive. Rather than having to write a wrapper UDF to call this method, the majority of these methods can be called using reflect UDF. Reflect uses Java reflection to instantiate and call methods of objects; it can also call static functions. The method must return a primitive type or a type that Hive knows how to serialize.

SELECT reflect( "java.lang.String" "valueOf" 1 ),
       reflect("java.util.UUID", "randomUUID"),
        reflect( "java.lang.String" "isEmpty" ),
        reflect( "java.lang.Math" "max" 2 3 ),
        reflect( "java.lang.Math" "min" 2 3 ),
        reflect( "java.lang.Math" "round" 2.5 ),
        reflect( "java.lang.Math" "exp" 1.0 ),
        reflect( "java.lang.Math" "floor" 1.9 )
FROM src LIMIT  1 ;
 
 
1    true     3    2    3    2.7182818284590455   1.0

Version information

As of Hive 0.9.0, java_method() is a synonym for reflect(). See Misc. Functions in Hive Operators and UDFs.

Muhammad Ahsan likes this
  • No labels

1 Comment

  1. This doc comes from the Hive xdocs, with minor edits. It is included here because the xdocs are currently unavailable (Feb. 2013).

猜你喜欢

转载自blog.csdn.net/u012802702/article/details/70199266