对于csv和txt文件导入hive表,区别在于二者的分隔符不同,这一点在建表语句中体现出来。下面是两种方式的导入方式步骤:
1.将csv文件导入到hive表
(1)建表语句:
USE database;
CREATE TABLE table(
ssid int comment 'ssid',
orderid int comment 'orderid'
)
COMMENT 'table comment'
row format delimited fields terminated by ','
STORED AS textfile;
(2)将表上传到服务器上,然后执行下面语句
download[hdfs:///***/hotel.csv-20190904-172542.csv hotel.csv] --加载路径
LOAD DATA local INPATH 'hotel.csv' into table database.table;--将数据load到表中
2.将txt问卷导入hive表中
(1)建表语句:
USE database;
CREATE TABLE table(
ssid int comment 'ssid',
orderid int comment 'orderid'
)
COMMENT 'table comment'
row format delimited fields terminated by '\t'
STORED AS textfile;
(2)将表上传到服务器上,然后执行下面语句
download[hdfs:///***/hotel.txt-20190904-172542.csv hotel.txt] --加载路径
LOAD DATA local INPATH 'hotel.txt' into table database.table;--将数据load到表中