hive> insert overwrite local directory '/home/wyp/wyp'
> row format delimited
> fields terminated by '\t'
> select * from wyp;
hive -e "select * from wyp" >> local/wyp.txt
cat wyp.sql
#select * from wyp
hive -f wyp.sql >> local/wyp2.txt
hive> insert overwrite directory '/home/wyp/hdfs'
> select * from wyp;
hive> insert into table test
> partition (age='25')
> select id, name, tel
> from wyp;
hive> create table wyp
> (id int, name string,
> age int, tel string)
> ROW FORMAT DELIMITED
> FIELDS TERMINATED BY '\t'
> STORED AS TEXTFILE;
cat wyp.txt
#1 wyp 25 13188888888888
#2 test 30 13888888888888
load data local inpath 'wyp.txt' into table wyp;
dfs -ls /user/hive/warehouse/wyp ;
从本地文件系统将数据导入到HIVE表的过程中,其实是现将数据临时复制到HDFS下面的一个目录,然后再将数据从临时目录下移动到对应HIVE表的数据目录中。 因此,HIVE也支持将数据直接从HDFS上的一个目录移动到相应HIVE表的目录中去。
和本地文件系统导入的区别只是是否有inpath。
load data inpath '/home/wyp/add.txt' into table wyp;
hive> create table test(
> id int, name string
> ,tel string)
> partitioned by
> (age int)
> ROW FORMAT DELIMITED
> FIELDS TERMINATED BY '\t'
> STORED AS TEXTFILE;
hive> insert into table test
> partition (age='25')
> select id, name, tel
> from wyp;
##动态指明分区
hive> set hive.exec.dynamic.partition.mode=nonstrict;
hive> insert into table test
> partition (age)
> select id, name,
> tel, age
> from wyp;
#overwrite方式重写原来的数据
hive> insert overwrite table test
> PARTITION (age)
> select id, name, tel, age
> from wyp;
#多表插入,只需要扫描一遍数据生成需要的各种表
hive> from wyp
> insert into table test
> partition(age)
> select id, name, tel, age
> insert into table test3
> select id, name
> where age>25;
hive> create table test4
> as
> select id, name, tel
> from wyp;