1.一次插入多个分区
动态分区:
create table test_tb(
id string,
name string
)
partitioned by (dt string)
row format delimited
fields terminate by '\t'
stored as orc;
set hive.exec.dynamic.partition=true; --开启动态分区
set hive.exec.dynamic.partition.mode = nonstrict; -- 动态分区模式,允许所有字段都可以为动态分区
insert into table test_tb partition(dt)
select id,name,birthday as dt
from test_table; -- test_table是非分区表
添加分区:
alter table test_tb1 add if not exists partition(dt='20190101');
2. 批量删除分区
--方法一;
alter table tb_test drop if exists
partition(dt='20180101'),
partition(dt='20180102'),
partition(dt='20180103'),
partition(dt='20180104');
-- 方法二;
alter table tb_test drop partition(dt>='20180101',dt<='20180104');
3.修改表名列名
alter table 旧表名 rename to 新表名;
alter table 表名 change 旧字段名 新字段名 字段类型;
4.在指定列后添加列
alter table table_name add columns(新字段 字段类型 comment "");
alter table table_name change 新字段 新字段 字段类型 after 指定字段;
5.row_number over() 按照多个字段降序排序
row_number() over(partition by 分组字段 order by 字段 1 desc, 字段 2 desc)