hadoop—编写一个hiveudf函数,该函数接受可变数量的参数并输出一个json blob

mwkjh3gx  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(329)

我想编写一个hiveudf,它接受数量可变的参数(不同类型),并将其输出为json blob(具有列名到列值的Map)。

Select userId, myudf(col2, col3) from TABLE 2; // the output of udf should be {"col2":50, "col3":"Y" }

Select userId, myudf(col2, col3, col4) from TABLE 1; // the output of udf should be {"col2":"s", "col3":5, "col4":"Y"}

Select userId, myudf(col2, col3, col4, col6, col7) from TABLE 3; //the output of udf should be {"col2":"M", "col3":"A", "col4":2.5, "col6":"D", "col7":99 }

每个表都有不同类型的不同列(userid在所有表中都是通用的)。我可以分别传递列名,如果这有帮助的话:myudf(“col2”,col2,“col3”,col3)。任何想法都将不胜感激。

0qx6xfy6

0qx6xfy61#

应该使用genericudf对象(按udf对象的顺序)。
马克·格罗弗为此写了一篇很好的博客文章http://mark.thegrovers.ca/tech-blog/how-to-write-a-hive-udf
以下是相关的源代码:https://github.com/markgrover/hive-translate/blob/master/src/main/java/org/mgrover/hive/translate/genericudftranslate.java

相关问题