GenericUDTF使用流程记载(转载+自己整理)
生活随笔
收集整理的這篇文章主要介紹了
GenericUDTF使用流程记载(转载+自己整理)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
概述
本文是對[1]的整理和復現。
UDTF的意思是進一出多。
在hive中UDTF的意思是,輸入一條數據,返回多條數據
環境
| 組件 | 版本 |
| Hadoop | 3.1.2 |
| Zookeeper | 3.6.0 |
| Mysql | 8.0.22-0ubuntu0.20.04.2 |
| Hive | 3.1.2 |
?
Hive準備工作
use db1; drop table if exists test; create table test( ind int, col string, col1 string ); insert into test values (1,'a,b,c','1,2'); insert into test values (2,'j,k',null); insert into test values (3,null,null) ;注冊GenericUDTF流程
| 注冊命令(hive/beeline中進行) | 備注 |
| add jar /home/appleyuchi/桌面/Flink_Code/FLINK讀寫各種數據源/Java/target/table_api-1.0-SNAPSHOT.jar; | 指明自定義依賴包 |
| create temporary function get_map as 'ArrToMapUDTF'; | 依賴包中的類ArrToMapUDTF注冊為get_map |
?
使用GenericUDAF流程
| hive命令 | 實驗結果 | 備注 |
| use db1; select * from test; | 1?? ?a,b,c?? ?1,2 | 檢查hive功能是否ok |
| use db1; select get_map(col,col1) from test; | a?? ?1 b?? ?2 c?? ?NULL j?? ?NULL k?? ?NULL | 使用寫好的udtf |
從實驗結果來看這個GenericUDAF的效果也很明顯:
把一條數據打散。
?
完整代碼:
https://gitee.com/appleyuchi/Flink_Code/blob/master/FLINK讀寫各種數據源/Java/src/main/java/ArrToMapUDTF.java
另外一個完整的例子可以參考[2]
Reference:
[1]hive中udtf編寫及使用
[2]Hive User Defined Table Generating Functions (UDTF) Java Example
總結
以上是生活随笔為你收集整理的GenericUDTF使用流程记载(转载+自己整理)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 程序员接单赚外快的渠道你知道的有哪些?
- 下一篇: 芝麻信用商家接入指南