hive之数据导入

hive> create table t_order_simple
    > as
    > select name,money from t_order;
    
hive> show tables;
OK
t_order
t_order_ex
t_order_simple

hive> select * from t_order_simple
    > ;
OK
iphone  6888.0
xiaomi  3999.0
meizhu  2499.0
mate7   4398.0

hive> insert into table t_order_simple
    > select name,money from t_order
    > where id>4;

Parttion
create table tab_ip_part(id int,name string ,ip string, country string)
    partitioned by (part_flag string)
    row format delimited fields terminated by ','

    load data local inpath '' overwrite into table tab_ip_part
    partition(part_flag='part1');
    
create table t_order_part(id int,name string ,price double)
partitioned by (nation string )
row format delimited fields terminated by ',';

hive> show tables;
OK
t_order
t_order_ex
t_order_part
t_order_simple

[root@hadoop04 soft]# vi old.data

1,kupai,23
2,xiaomi,2399
3,meizu,2499
4,mate7,4398
5,dashen,300
6,chuizi,2499
7,nubia ,2700
[root@hadoop04 soft]# vi order.data2
8,iphone6plus,25
9,mote,32
10,sunsaum,22
11,apple,8
load data local inpath '/root/soft/old.data' into table t_order_part partition(nation='china');
load data local inpath '/root/soft/order.data2' into table t_order_part partition(nation='foreign');
hive> select * from t_order_part;
OK
1       kupai   23.0    china
2       xiaomi  2399.0  china
3       meizu   2499.0  china
4       mate7   4398.0  china
5       dashen  300.0   china
6       chuizi  2499.0  china
7       nubia   2700.0  china
8       iphone6plus     25.0    foreign
9       mote    32.0    foreign
10      sunsaum 22.0    foreign
11      apple   8.0     foreign
Time taken: 0.326 seconds, Fetched: 11 row(s)

hive> select * from t_order_part where nation='china' and price >400;
Total MapReduce jobs = 1
Launching Job 1 out of 1
Number of reduce tasks is set to 0 since there's no reduce operator
Starting Job = job_1452925978043_0003, Tracking URL = http://hadoop07:8088/proxy/application_1452925978043_0003/
Kill Command = /home/hadoop/hadoop-2.6.0/bin/hadoop job  -kill job_1452925978043_0003
Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 0
2016-01-16 00:47:24,316 Stage-1 map = 0%,  reduce = 0%
2016-01-16 00:48:13,208 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 3.81 sec
2016-01-16 00:48:14,330 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 3.81 sec
2016-01-16 00:48:15,438 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 3.81 sec
MapReduce Total cumulative CPU time: 3 seconds 810 msec
Ended Job = job_1452925978043_0003
MapReduce Jobs Launched:
Job 0: Map: 1   Cumulative CPU: 3.81 sec   HDFS Read: 311 HDFS Write: 108 SUCCESS
Total MapReduce CPU Time Spent: 3 seconds 810 msec
OK
2       xiaomi  2399.0  china
3       meizu   2499.0  china
4       mate7   4398.0  china
6       chuizi  2499.0  china
7       nubia   2700.0  china
Time taken: 104.042 seconds, Fetched: 5 row(s)

alter table tab_ip change id id_alter string
alter table tab_ots add partition (partcol='dt') location '/'
show partition y_order_part

insert overwrite directory '/result.txt' select name,price from t_order_part;
insert overwrite local directory '/result.txt' select name,price from t_order_part;app