HIVE HOW TO LOAD DATA_Candice Jing_百度空间

系统 2867 0

HIVE HOW TO LOAD DATA_Candice Jing_百度空间

HIVE HOW TO LOAD DATA

How to load data into Hive
------------------------
In order to load data into Hive, we need to tell Hive the format of the data
through "CREATE TABLE" statement:

FileFormat: the data has to be in Text or SequenceFile.
Format of the row:
If the data is in delimited format, use MetadataTypedColumnsetSerDe
If the data is in delimited format and has more than 1 levels of delimitor,
use DynamicSerDe with TCTLSeparatedProtocol
If the data is a serialized thrift object, use ThriftSerDe
The steps to load the data:
1 Create a table:

CREATE TABLE t (foo STRING, bar STRING)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
STORED AS TEXTFILE; 

CREATE TABLE t2 (foo STRING, bar ARRAY<STRING>)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
COLLECTION ITEMS TERMINATED BY ','
STORED AS TEXTFILE; 

CREATE TABLE t3 (foo STRING, bar MAP<STRING,STRING>)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
COLLECTION ITEMS TERMINATED BY ','
MAP KEYS TERMINATED BY ':'
STORED AS TEXTFILE;

CREATE TABLE t4 (foo STRING, bar MAP<STRING,STRING>)
ROW FORMAT SERIALIZER 'org.apache.hadoop.hive .serde2.MetadataTypedColumnsetSerDe'
WITH SERDEPROPERTIES ('columns'='foo,bar','SERIALIZATION.FORMAT'='9'); 

(RegexDeserializer is not done yet)
CREATE TABLE t5 (foo STRING, bar STRING)
ROW FORMAT SERIALIZER 'org.apache.hadoop.hive.serde2.RegexDeserializer'
WITH SERDEPROPERTIES ('regex'='([a-z]*) ([a-z])'); 

2 Load the data:
LOAD DATA LOCAL INPATH '../examples/files/kv1.txt' OVERWRITE INTO TABLE t; 

How to read data from Hive tables
------------------------
In order to read data from Hive tables, we need to know the same 2 things:

File Format
Row Format
Then we just need to directly open the HDFS file and read the data.

 

 

CREATE TABLE table1 (a STRING, b STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' ESCAPED BY '\\'
STORED AS TEXTFILE; 

ESCAPED BY 指定转义字符

HIVE HOW TO LOAD DATA_Candice Jing_百度空间


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论