# hivefunction **Repository Path**: py_main/hivefunction ## Basic Information - **Project Name**: hivefunction - **Description**: hive udtf函数 1、json数组拆分 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-12-30 - **Last Updated**: 2021-12-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # hivefunction ## 介绍 hive udtf函数 1、json数组拆分 输入:json数组字符串,输出:每个json数组元素作为一行输出 输入:[{"action_id":"favor_canel","item":"7","item_type":"sku_id","ts":1583746283096},{"action_id":"favor_canel","item":"8","item_type":"sku_id","ts":1583746285040},{"action_id":"favor_canel","item":"9","item_type":"sku_id","ts":1583746286984}] 输出: {"action_id":"favor_canel","item":"7","item_type":"sku_id","ts":1583746283096} {"action_id":"favor_canel","item":"8","item_type":"sku_id","ts":1583746285040} {"action_id":"favor_canel","item":"9","item_type":"sku_id","ts":1583746286984} ## 使用 根据jar包创建函数 create function explode_json_array as 'com.bigdata.hive.udtf.ExplodeJSONArray' using jar 'hdfs://hadoop102:8020/user/hive/jars/hivefunction-1.0-SNAPSHOT.jar'; 使用函数 select explode_json_array('[{"action_id":"favor_canel","item":"7","item_type":"sku_id","ts":1583746283096},{"action_id":"favor_canel","item":"8","item_type":"sku_id","ts":1583746285040},{"action_id":"favor_canel","item":"9","item_type":"sku_id","ts":1583746286984}]'); 参考: 尚硅谷电商数仓V4.0 https://cwiki.apache.org/confluence/display/Hive/DeveloperGuide+UDTF