dept_20200401.log
dept_20200402.log
dept_20200403.log
hive (default)> create table dept_partition( deptno int, dname string, loc string ) partitioned by (day string) row format delimited fields terminated by ‘\t‘;
10 ACCOUNTING 1700 20 RESEARCH 1800
30 SALES 1900 40 OPERATIONS 1700
50 TEST 2000 60 DEV 1900
hive (default)> load data local inpath ‘/opt/module/hive/datas/dept_20200401.log‘ into table dept_partition partition(day=‘20200401‘); hive (default)> load data local inpath ‘/opt/module/hive/datas/dept_20200402.log‘ into table dept_partition partition(day=‘20200402‘); hive (default)> load data local inpath ‘/opt/module/hive/datas/dept_20200403.log‘ into table dept_partition partition(day=‘20200403‘);
hive (default)> select * from dept_partition where day=‘20200401‘;
hive (default)> select * from dept_partition where day=‘20200401‘ union select * from dept_partition where day=‘20200402‘ union select * from dept_partition where day=‘20200403‘; hive (default)> select * from dept_partition where day=‘20200401‘ or day=‘20200402‘ or day=‘20200403‘;
hive> desc formatted dept_partition; # Partition Information # col_name data_type comment month string
hive (default)> create table dept_partition2( deptno int, dname string, loc string ) partitioned by (day string, hour string) row format delimited fields terminated by ‘\t‘;
hive (default)> load data local inpath ‘/opt/module/hive/datas/dept_20200401.log‘ into table dept_partition2 partition(day=‘20200401‘, hour=‘12‘);
hive (default)> select * from dept_partition2 where day=‘20200401‘ and hour=‘12‘;
hive (default)> dfs -mkdir -p /user/hive/warehouse/mydb.db/dept_partition2/day=20200401/hour=13; hive (default)> dfs -put /opt/module/datas/dept_20200401.log /user/hive/warehouse/mydb.db/dept_partition2/day=20200401/hour=13;
hive (default)> select * from dept_partition2 where day=‘20200401‘ and hour=‘13‘;
hive (default)> select * from dept_partition2 where day=‘20200401‘ and hour=‘13‘;
hive (default)> dfs -mkdir -p /user/hive/warehouse/mydb.db/dept_partition2/day=20200401/hour=14; hive (default)> dfs -put /opt/module/hive/datas/dept_20200401.log /user/hive/warehouse/mydb.db/dept_partition2/day=20200401/hour=14;
hive (default)> alter table dept_partition2 add partition(day=‘201709‘,hour=‘14‘);
hive (default)> select * from dept_partition2 where day=‘20200401‘ and hour=‘14‘;
hive (default)> dfs -mkdir -p /user/hive/warehouse/mydb.db/dept_partition2/day=20200401/hour=15;
hive (default)> load data local inpath ‘/opt/module/hive/datas/dept_20200401.log‘ into table dept_partition2 partition(day=‘20200401‘,hour=‘15‘);
hive (default)> select * from dept_partition2 where day=‘20200401‘ and hour=‘15‘;
hive (default)> create table dept_partition_dy(id int, name string) partitioned by (loc int) row format delimited fields terminated by ‘\t‘;
set hive.exec.dynamic.partition.mode = nonstrict; hive (default)> insert into table dept_partition_dy partition(loc) select deptno, dname, loc from dept;
hive (default)> show partitions dept_partition;
1001 ss1 1002 ss2 1003 ss3 1004 ss4 1005 ss5 1006 ss6 1007 ss7 1008 ss8 1009 ss9 1010 ss10 1011 ss11 1012 ss12 1013 ss13 1014 ss14 1015 ss15 1016 ss16
create table stu_buck(id int, name string) clustered by(id) into 4 buckets row format delimited fields terminated by ‘\t‘;
hive (default)> desc formatted stu_buck; Num Buckets:
hive (default)> load data inpath ‘/student.txt‘ into table stu_buck;
hive(default)>insert into table stu_buck select * from student_insert;
hive (default)> select * from stu_buck tablesample(bucket 1 out of 4 on id);
Hive基础(44):Hive语法(5) DDL(2) 分区表和分桶表
原文:https://www.cnblogs.com/qiu-hua/p/15141056.html