【Hive】加载.csv文件

  • 用org.apache.hadoop.hive.serde2.OpenCSVSerde格式建表,分隔符为逗号
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
DROP TABLE IF EXISTS hydra.demo;

CREATE TABLE hydra.demo
(
id string,
confirmed_count string,
confirmed_incr string,
record_date string,
country_name string,
country_shortcode string,
continent string
)
ROW format serde 'org.apache.hadoop.hive.serde2.OpenCSVSerde' WITH SERDEPROPERTIES
(
"separatorChar"=","
)
STORED AS TEXTFILE;

 

  • 从hdfs拉数
1
LOAD DATA inpath '/data/countrydata.csv' INTO TABLE hydra.demo;

 

  • 从linux本地拉数
1
LOAD DATA LOCAL inpath '/root/data/countrydata.csv' INTO TABLE hydra.demo;

 

  • 查数
1
SELECT * FROM hydra.demo;