如何编写hive UDF

时间:2016-04-09 22:48:49

标签: hadoop mapreduce hive hiveql hive-udf

我对如何使用UDFS感到困惑。是否可以用UDF替换下面的bash脚本功能?

#!/bin/bash

 src_count_q="use db;select count(*) from config_table where table_nm="test_source";"
 src_count=$(hive -e $src_count_q)

 trg_count_q="use db;select count(*) from config_table where table_nm="test_target";"
 trg_count=$(hive -e $trg_count_q)

 if ["$src_count" = "trg_count"];
 then
   $(hive -e "use db;select * from test_target;")
 fi

请帮忙!!我已经看过UDF如何反转字符串或更改case.But我无法弄清楚如何为我们重用查询结果的这类条件情况编写HIVE UDF。

还有其他更好的方法来处理这类查询流程吗?

1 个答案:

答案 0 :(得分:0)

据我所知,您可以使用HIVE UDF在hive中启用某些sql函数,但是你不能使用它们来放置PL-SQL之类的东西。 因此,对于您的问题,您可以使用Spark-SQL是我使用过的更好的方法。