博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HIVE HOW TO LOAD DATA_Candice Jing_百度空间
阅读量:6699 次
发布时间:2019-06-25

本文共 1857 字,大约阅读时间需要 6 分钟。

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 指定转义字符

转载地址:http://ziloo.baihongyu.com/

你可能感兴趣的文章
《PWA实战:面向下一代的Progressive Web APP》读书笔记
查看>>
redux 源码详解
查看>>
Android屏幕适配
查看>>
你真的懂函数吗?
查看>>
区块链技术怎么构架落地应用?
查看>>
西宁a货翡翠,孝感a货翡翠
查看>>
告诉你银行在年底为存储做的小动作
查看>>
函数中的apply,call入门介绍
查看>>
XCode10 swift4.2 适配遇到的坑
查看>>
我的友情链接
查看>>
四元數與旋轉
查看>>
开始nodejs+express的学习+实践(8)
查看>>
java-递归折半查找法
查看>>
RPM的用法
查看>>
收集整理的非常有用的PHP函数
查看>>
css3图标悬停导航菜单
查看>>
linux下搭建FTP服务器
查看>>
c语言数组问题解析
查看>>
Windows 7操作系统使用移动硬盘快速安装
查看>>
DuangDuangDuang!码云项目的 Readme.md 特殊技能
查看>>