我遇到了问题并且真的需要帮助。
以下是我的数据集
"counter","qid","i","qs","qt","tags","qvc","qac","aid","j","as","at"
"1",563355,62701,0,1235000081,"php,error,gd,image-processing",220,2,563372,67183,2,1235000501
"2",563356,15842,10,1235000140,"lisp,scheme,clojure",1047,16,563358,15842,3,1235000177
所有列都以','分隔,第六列是标记,这是一个由','分隔的2到5个标记的列表。
我尝试使用标记作为字符串创建表,也作为字符串数组创建表,两者都给我标记列表中的第一个值(在本例中为php
和lisp
),其余列为null 。
"1" 563355 62701 0 1235000081 "php NULL NULL NULL 220 2 563372
"2" 563356 15842 10 1235000140 "lisp NULL NULL NULL 1047 16 563358
期望的输出:
"1" 563355 62701 0 1235000081 "php,error,gd,image-processing" 220 2 563372
"2" 563356 15842 10 1235000140 "lisp,scheme,clojure" 1047 16 563358
我做了一些研究,发现我可以编写一个REGEXSERDE模式来读取数据,我是新手,我不知道如何编写正则表达式模式。正则表达式旁边还有其他方法吗?如果没有,有人可以帮我写一个正则表达式吗?
提前谢谢你。
答案 0 :(得分:0)
Easiest way to do this will be change ',' delimiter with something else
Other approach will be to use Open csv serde which will help you do this
答案 1 :(得分:0)
您可以使用Hive外部表
create external table try3.tablename(
counter string,
qid int,
i int,
qs int,
qt int,
tags string,
qac int,
aid int )
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.RegexSerDe'
WITH SERDEPROPERTIES (
'input.regex' = '(.*?),(.*?),(.*?),(.*?),(.*?),(\".*\"),(.*?),(.*?),.*'
)
STORED AS TEXTFILE
LOCATION '/somelocation'