diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java index 1013979..475ae7f 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/FunctionRegistry.java @@ -426,6 +426,7 @@ public final class FunctionRegistry { // Generic UDFs registerGenericUDF("reflect", GenericUDFReflect.class); + registerGenericUDF("java_method", GenericUDFReflect.class); registerGenericUDF("array", GenericUDFArray.class); registerGenericUDF("assert_true", GenericUDFAssertTrue.class); diff --git ql/src/test/queries/clientpositive/udf_java_method.q ql/src/test/queries/clientpositive/udf_java_method.q index e69de29..2f28be1 100644 --- ql/src/test/queries/clientpositive/udf_java_method.q +++ ql/src/test/queries/clientpositive/udf_java_method.q @@ -0,0 +1,25 @@ +DESCRIBE FUNCTION java_method; +DESCRIBE FUNCTION EXTENDED java_method; + +-- java_method() is a synonym for reflect() + +EXPLAIN EXTENDED +SELECT java_method("java.lang.String", "valueOf", 1), + java_method("java.lang.String", "isEmpty"), + java_method("java.lang.Math", "max", 2, 3), + java_method("java.lang.Math", "min", 2, 3), + java_method("java.lang.Math", "round", 2.5), + java_method("java.lang.Math", "exp", 1.0), + java_method("java.lang.Math", "floor", 1.9) +FROM src LIMIT 1; + + +SELECT java_method("java.lang.String", "valueOf", 1), + java_method("java.lang.String", "isEmpty"), + java_method("java.lang.Math", "max", 2, 3), + java_method("java.lang.Math", "min", 2, 3), + java_method("java.lang.Math", "round", 2.5), + java_method("java.lang.Math", "exp", 1.0), + java_method("java.lang.Math", "floor", 1.9) +FROM src LIMIT 1; + diff --git ql/src/test/results/clientpositive/show_functions.q.out ql/src/test/results/clientpositive/show_functions.q.out index 3770f80..6b8f942 100644 --- ql/src/test/results/clientpositive/show_functions.q.out +++ ql/src/test/results/clientpositive/show_functions.q.out @@ -77,6 +77,7 @@ index instr isnotnull isnull +java_method json_tuple lcase length diff --git ql/src/test/results/clientpositive/udf_java_method.q.out ql/src/test/results/clientpositive/udf_java_method.q.out index e69de29..ebe31a0 100644 --- ql/src/test/results/clientpositive/udf_java_method.q.out +++ ql/src/test/results/clientpositive/udf_java_method.q.out @@ -0,0 +1,152 @@ +PREHOOK: query: DESCRIBE FUNCTION java_method +PREHOOK: type: DESCFUNCTION +POSTHOOK: query: DESCRIBE FUNCTION java_method +POSTHOOK: type: DESCFUNCTION +java_method(class,method[,arg1[,arg2..]]) calls method with reflection +PREHOOK: query: DESCRIBE FUNCTION EXTENDED java_method +PREHOOK: type: DESCFUNCTION +POSTHOOK: query: DESCRIBE FUNCTION EXTENDED java_method +POSTHOOK: type: DESCFUNCTION +java_method(class,method[,arg1[,arg2..]]) calls method with reflection +Synonyms: reflect +Use this UDF to call Java methods by matching the argument signature + +PREHOOK: query: -- java_method() is a synonym for reflect() + +EXPLAIN EXTENDED +SELECT java_method("java.lang.String", "valueOf", 1), + java_method("java.lang.String", "isEmpty"), + java_method("java.lang.Math", "max", 2, 3), + java_method("java.lang.Math", "min", 2, 3), + java_method("java.lang.Math", "round", 2.5), + java_method("java.lang.Math", "exp", 1.0), + java_method("java.lang.Math", "floor", 1.9) +FROM src LIMIT 1 +PREHOOK: type: QUERY +POSTHOOK: query: -- java_method() is a synonym for reflect() + +EXPLAIN EXTENDED +SELECT java_method("java.lang.String", "valueOf", 1), + java_method("java.lang.String", "isEmpty"), + java_method("java.lang.Math", "max", 2, 3), + java_method("java.lang.Math", "min", 2, 3), + java_method("java.lang.Math", "round", 2.5), + java_method("java.lang.Math", "exp", 1.0), + java_method("java.lang.Math", "floor", 1.9) +FROM src LIMIT 1 +POSTHOOK: type: QUERY +ABSTRACT SYNTAX TREE: + (TOK_QUERY (TOK_FROM (TOK_TABREF (TOK_TABNAME src))) (TOK_INSERT (TOK_DESTINATION (TOK_DIR TOK_TMP_FILE)) (TOK_SELECT (TOK_SELEXPR (TOK_FUNCTION java_method "java.lang.String" "valueOf" 1)) (TOK_SELEXPR (TOK_FUNCTION java_method "java.lang.String" "isEmpty")) (TOK_SELEXPR (TOK_FUNCTION java_method "java.lang.Math" "max" 2 3)) (TOK_SELEXPR (TOK_FUNCTION java_method "java.lang.Math" "min" 2 3)) (TOK_SELEXPR (TOK_FUNCTION java_method "java.lang.Math" "round" 2.5)) (TOK_SELEXPR (TOK_FUNCTION java_method "java.lang.Math" "exp" 1.0)) (TOK_SELEXPR (TOK_FUNCTION java_method "java.lang.Math" "floor" 1.9))) (TOK_LIMIT 1))) + +STAGE DEPENDENCIES: + Stage-1 is a root stage + Stage-0 is a root stage + +STAGE PLANS: + Stage: Stage-1 + Map Reduce + Alias -> Map Operator Tree: + src + TableScan + alias: src + GatherStats: false + Select Operator + expressions: + expr: reflect('java.lang.String','valueOf',1) + type: string + expr: reflect('java.lang.String','isEmpty') + type: string + expr: reflect('java.lang.Math','max',2,3) + type: string + expr: reflect('java.lang.Math','min',2,3) + type: string + expr: reflect('java.lang.Math','round',2.5) + type: string + expr: reflect('java.lang.Math','exp',1.0) + type: string + expr: reflect('java.lang.Math','floor',1.9) + type: string + outputColumnNames: _col0, _col1, _col2, _col3, _col4, _col5, _col6 + Limit + File Output Operator + compressed: false + GlobalTableId: 0 +#### A masked pattern was here #### + NumFilesPerFileSink: 1 +#### A masked pattern was here #### + table: + input format: org.apache.hadoop.mapred.TextInputFormat + output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat + properties: + columns _col0,_col1,_col2,_col3,_col4,_col5,_col6 + columns.types string:string:string:string:string:string:string + escape.delim \ + serialization.format 1 + TotalFiles: 1 + GatherStats: false + MultiFileSpray: false + Needs Tagging: false + Path -> Alias: +#### A masked pattern was here #### + Path -> Partition: +#### A masked pattern was here #### + Partition + base file name: src + input format: org.apache.hadoop.mapred.TextInputFormat + output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat + properties: + bucket_count -1 + columns key,value + columns.types string:string +#### A masked pattern was here #### + name default.src + serialization.ddl struct src { string key, string value} + serialization.format 1 + serialization.lib org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe +#### A masked pattern was here #### + serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe + + input format: org.apache.hadoop.mapred.TextInputFormat + output format: org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat + properties: + bucket_count -1 + columns key,value + columns.types string:string +#### A masked pattern was here #### + name default.src + serialization.ddl struct src { string key, string value} + serialization.format 1 + serialization.lib org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe +#### A masked pattern was here #### + serde: org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe + name: default.src + name: default.src + + Stage: Stage-0 + Fetch Operator + limit: 1 + + +PREHOOK: query: SELECT java_method("java.lang.String", "valueOf", 1), + java_method("java.lang.String", "isEmpty"), + java_method("java.lang.Math", "max", 2, 3), + java_method("java.lang.Math", "min", 2, 3), + java_method("java.lang.Math", "round", 2.5), + java_method("java.lang.Math", "exp", 1.0), + java_method("java.lang.Math", "floor", 1.9) +FROM src LIMIT 1 +PREHOOK: type: QUERY +PREHOOK: Input: default@src +#### A masked pattern was here #### +POSTHOOK: query: SELECT java_method("java.lang.String", "valueOf", 1), + java_method("java.lang.String", "isEmpty"), + java_method("java.lang.Math", "max", 2, 3), + java_method("java.lang.Math", "min", 2, 3), + java_method("java.lang.Math", "round", 2.5), + java_method("java.lang.Math", "exp", 1.0), + java_method("java.lang.Math", "floor", 1.9) +FROM src LIMIT 1 +POSTHOOK: type: QUERY +POSTHOOK: Input: default@src +#### A masked pattern was here #### +1 true 3 2 3 2.7182818284590455 1.0 diff --git ql/src/test/results/clientpositive/udf_reflect.q.out ql/src/test/results/clientpositive/udf_reflect.q.out index 6f17cfd..86703fc 100644 --- ql/src/test/results/clientpositive/udf_reflect.q.out +++ ql/src/test/results/clientpositive/udf_reflect.q.out @@ -8,6 +8,7 @@ PREHOOK: type: DESCFUNCTION POSTHOOK: query: DESCRIBE FUNCTION EXTENDED reflect POSTHOOK: type: DESCFUNCTION reflect(class,method[,arg1[,arg2..]]) calls method with reflection +Synonyms: java_method Use this UDF to call Java methods by matching the argument signature PREHOOK: query: EXPLAIN EXTENDED