刚学完hive,总结下hive导入导出数据的几种方式:
hive导入数据的四种方式
(加local是本地,overwrite into会覆盖)
从本地文件系统中导入数据到Hive表
create table wyp (id int,name string,age int, tel string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'STORED AS TEXTFILE;
load data local inpath 'wyp.txt' intotable wyp;
HDFS上导入数据到Hive表
load data inpath '/home/wyp/add.txt'into table wyp;
从别的表中查询出相应的数据并导入到Hive表中
createtable test(id int, name string,tel string) partitioned by (age int) ROW FORMAT DELIMITED FIELDS TERMINATEDBY '\t' STORED AS TEXTFILE;
insertinto table test partition (age='25') select id, name, tel from wyp;
在创建表的时候通过从别的表中查询出相应的记录并插入到所创建的表[称为CTAS(create table .. as select)]
createtable test4 as select id, name, tel from wyp;
Hive导出数据的三种方式
导出到本地文件系统
insertoverwrite local directory '/home/wyp/wyp'
生成的文件名是000000_0.
导出到HDFS中
insertoverwrite directory '/home/wyp/hdfs'
导出到Hive的另一个表中
insert intotable test partition (age='25') select id, name, tel from wyp;