从具有不同记录格式的文件为csv文件创建外部HIVE表 [英] Create external HIVE table from files with different record formats for a csv file

查看:585
本文介绍了从具有不同记录格式的文件为csv文件创建外部HIVE表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由第一列值定义的具有不同记录格式的CSV文件:
示例数据:

I have a CSV file with different record formats that is defined by the first column value: Sample Data:

"EL","XXXXXXX", 2017-07-17
"EH","XXXXXXX",1,2017-07-17,"AAA"
"BI","XXXXXXX","AAA","BBBB"

在这种情况下,我使用3种定义的记录类型。
有没有办法将它加载到不同的配置单元表中?

In this case, I am getting the file with 3 defined record types. Is there a way to load this to different hive tables ?

推荐答案

演示

create table el (s1 string,d1 date);
create table eh (s1 string,i1 int,dt1 date,s2 string);
create table bi (s1 string,s2 string,s3 string);







create external table myfile 
(
    c1  string
   ,c2  string
   ,c3  string
   ,c4  string
   ,c5  string
)

row format serde 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
with serdeproperties 
(
    'separatorChar' = ','
   ,'quoteChar'     = '"'
   ,'escapeChar'    = '\\'
)  
stored as textfile
;







select * from myfile;

+-----+----------+--------------+-------------+-------+
| c1  |    c2    |      c3      |     c4      |  c5   |
+-----+----------+--------------+-------------+-------+
| EL  | XXXXXXX  |  2017-07-17  | NULL        | NULL  |
| EH  | XXXXXXX  | 1            | 2017-07-17  | AAA   |
| BI  | XXXXXXX  | AAA          | BBBB        | NULL  |
+-----+----------+--------------+-------------+-------+







from myfile
insert into el select c2,c3       where c1='EL'
insert into eh select c2,c3,c4,c5 where c1='EH'
insert into bi select c2,c3,c4    where c1='BI'
;







select * from el;

+----------+-------------+
|    s1    |     d1      |
+----------+-------------+
| XXXXXXX  | 2017-07-17  |
+----------+-------------+







select * from eh;

+----------+-----+-------------+------+
|    s1    | i1  |     dt1     |  s2  |
+----------+-----+-------------+------+
| XXXXXXX  | 1   | 2017-07-17  | AAA  |
+----------+-----+-------------+------+







select * from bi;

+----------+------+-------+
|    s1    |  s2  |  s3   |
+----------+------+-------+
| XXXXXXX  | AAA  | BBBB  |
+----------+------+-------+

这篇关于从具有不同记录格式的文件为csv文件创建外部HIVE表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆