gpt4 book ai didi

json - 编写一个Hive UDF函数,该函数接受可变数量的args,并超过JSON blob

转载 作者:行者123 更新时间:2023-12-02 21:28:44 24 4
gpt4 key购买 nike

我想编写一个Hive UDF,它接受可变数量的参数(不同类型)并将其输出为JSON Blob(具有列名到列值的映射关系)。

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)。任何想法将不胜感激。

最佳答案

您应该使用GenericUDF对象(按UDF对象的顺序)。

马克·格罗弗(Mark Grover)撰写了一篇关于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

关于json - 编写一个Hive UDF函数,该函数接受可变数量的args,并超过JSON blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35048024/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com