bash 如何在 hive 中使用 Posexplode 函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26405104/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to use Posexplode function in hive
提问by Raghunath
I am using posexplode
to split single to multiple records in hive.
Along with multiple records as output i need to generate sequence number for each row.
我正在使用posexplode
在 hive 中将单个记录拆分为多个记录。随着多条记录作为输出,我需要为每一行生成序列号。
col1
, col2
, col3
and col4
are defined as string because rarely we get alpha data as well.
col1
, col2
,col3
和col4
被定义为字符串,因为我们也很少获得 alpha 数据。
col1 | col2| col3 | col4
---------------------------
7 | 9 | A | 3
5 | 6 | 9
Seq | Col
----------
1 | 7
2 | 9
3 | A
4 | 3
1 | 5
2 | 6
3 | 9
I am using below mentioned query but I am getting error
我正在使用下面提到的查询,但出现错误
-bash: syntax error near unexpected token (
-bash: syntax error near unexpected token (
My query is :
我的查询是:
SELECT
seq, col
FROM
(SELECT array( col1, col2 , col3,col4) as arr_r FROM srctable ) arrayrec
LATERAL VIEW posexplode(arrayrec) EXPLODED_rec as seq, col
How can this be resolved
如何解决这个问题
I am able to run successfully this query :
我能够成功运行此查询:
SELECT col FROM
(SELECT array( col1, col2 , col3,col4)
as arr_r FROM srctable ) arrayrec
LATERAL VIEW explode(arrayrec) EXPLODED_rec as col
Which produces below output
产生以下输出
Col
-----
7
9
A
3
5
6
9
I have checked the link : How to get first n elements in an array in Hive
回答by user3122114
Try
尝试
SELECT Seq, col FROM
(SELECT array( col1, col2 , col3,col4)
as arr_r FROM srctable ) arrayrec
LATERAL VIEW posexplode(arrayrec.arr_r) EXPLODED_rec as Seq, col;
Also check your hive version. posexplode() is available as of Hive 0.13.0.
还要检查您的配置单元版本。从 Hive 0.13.0 开始,poseexplode() 可用。