gpt4 book ai didi

hadoop - 如何将多个列值转换为 hive 中的行?

转载 作者:行者123 更新时间:2023-12-02 19:13:35 25 4
gpt4 key购买 nike

Input:

ID COLUMN1 COLUMN2 COLUMN3
1 M,S,E,T 1,2,3,4 5,6,7
2 A,B,C 6,5,8,7,9,1 2,4,3,0,1


Output:

ID COLUMN1 COLUMN2 COLUMN3
1 M 10 50
1 S 20 60
1 E 30 70
1 T 40 NULL
2 A 6 2
2 B 5 4
2 C 8 3
2 NULL 7 0
2 NULL 9 1
2 NULL 1 NULL

码:
select ID,
array_index( COLUMN1_arr, n ) as COLUMN1,
array_index( COLUMN2_arr, n ) as COLUMN2
from sample
lateral view numeric_range(size(COLUMN1_arr)) n1 as n;

错误:

FAILED: Semantic Exception [Error 10011]: Invalid function array_index



在这里,我在单列中有多个值,我需要将其转换为行,如输出所述。

最佳答案

爆炸是 hive 中提供的UDTF,您可以使用它将数据从列拆分为行。

SELECT ID1, col1,col2,col3
FROM tableName
lateral view explode(split(COLUMN1,',')) cols1 AS col1
lateral view explode(split(COLUMN2,',')) cols2 AS col2
lateral view explode(split(COLUMN3,',')) cols3 AS col3

关于hadoop - 如何将多个列值转换为 hive 中的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60056064/

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