我如何在Hive中执行双分隔符(||)? [英] How can I do a double delimiter(||) in Hive?
本文介绍了我如何在Hive中执行双分隔符(||)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将数据加载到由双管道(||)分隔的配置单元表中。当我尝试这样:
示例I / P:
1405983600000 || 111.111.82.41 || 806065581 || session-id
在配置单元中创建表:
create table test_hive(k1字符串,k2字符串,k3字符串,k4字符串,)以'||'结尾的行格式定界字段存储为文本文件;
从文本文件加载数据:
将数据本地inpath'/Desktop/input.txt'载入表test_hive;
当我这样做时,它将以下面的格式存储数据:
1405983600000 tabspace-as-second-column 111.111.82.41 tabspace-as-fourth-column
由于我期望表中的数据是
1405983600000 111.111 .82.41 806065581 session-id
请帮助我解决此问题,但我无法解决它可以做到这一点,如果你不想使用替代serde或有早期版本的蜂巢:
create external table my_table(line string)location / path / file;
然后在上面创建视图:
创建视图my_view作为选择split(行,'\\ | \\\'|')[0]作为column_1
,split(行,'\\ | \\ |')[1]作为column_2
,split(line,'\\ | \\'|)[2]作为column_3
from my_table;
查询视图。祝你好运。
I am trying to load data into hive tables which is delimited by double pipe(||). When I try this :
Sample I/P:
1405983600000||111.111.82.41||806065581||session-id
Creating table in hive:
create table test_hive(k1 string, k2 string, k3 string, k4 string,) row format delimited fields terminated by '||' stored as textfile;
Loading data from text file:
load data local inpath '/Desktop/input.txt' into table test_hive;
When I do this it is storing data in the below format:
1405983600000 tabspace-as-second-column 111.111.82.41 tabspace-as-fourth-column
Where as I am expecting the data in table to be
1405983600000 111.111.82.41 806065581 session-id
Kindly help me out I have tried different options on this but unable to resolve it
解决方案
You could do this if you don't want to use alternate serde or have earlier version of hive:
create external table my_table (line string) location /path/file;
Then create view on top:
create view my_view as select split(line,'\\|\\|')[0] as column_1
, split(line,'\\|\\|')[1] as column_2
, split(line,'\\|\\|')[2] as column_3
from my_table;
Query the view. Good luck.
这篇关于我如何在Hive中执行双分隔符(||)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文