hive> create table user > (id int, > name string, > age int, > tel string) > ROW FORMAT DELIMITED > FIELDS TERMINATED BY '\t' > STORED AS TEXTFILE; OK Time taken: 2.832 seconds
hive> load data local inpath 'user.txt' into table user; Copying data from file:/home/bcat/user.txt Copying file: file:/home/bcat/user.txt Loading data to table default.user Table default.user stats: [num_partitions: 0, num_files: 1, num_rows: 0, total_size: 67] OK Time taken: 5.967 seconds
hive> load data inpath '/home/bcat/user2.txt' into table user; Loading data to table default.user Table default.user stats: [num_partitions: 0, num_files: 2, num_rows: 0, total_size: 215] OK Time taken: 0.47 seconds
注意”load data inpath ‘/home/bcat/user2.txt’ into table user;”里面是没有local这个单词的,这个是和第一种方法的区别。
3、从别的表中查询出相应的数据并导入到Hive表中
先建立一张新表
1 2 3 4 5 6 7 8
hive> create table test( > id int, > name string, > tel string) > partitioned by (age int) > ROW FORMAT DELIMITED > FIELDS TERMINATED BY '\t' > STORED AS TEXTFILE;
这里使用了age作为分区字段。 下面将user表中的查询结果并插入到test表中
1 2 3 4
hive> insert into table test > partition (age='25') > select id, name, tel > from user;