1、建分区表 (多个字段入hive,其原数据字段是啥分隔符符号,入hive就要是啥分隔符)
create table table_name (num_id string comment '手机号', if_active string comment '是否活跃') partitioned by (statis_date string) row format delimited fields terminated by '\t';
2、查看表下所有的分区
show partitions table_name;
3、查看表下某个 statis_date 分区数据 10行
select * from table_name where statis_date=20210224 limit 10;
4、 删除表
drop table if exists table_name;
5、删除表下某个statis_date分区数据
alter table table_name drop partition(statis_date=20210224);
6、修改表结构 num_id 字段为 serv_num 类型 string
Alter table table_name change num_id serv_num string
7、修改表名
alter table table_name rename to new_table_name;
8、修改表的分区的分区名
alter table table_name partition(dt='partition_old_name') rename to partition(dt='partition_new_name')
9、 添加字段 new_col,new_tcl;添加到了最后一行,想调整位置的话后面可以再改。
ALTER TABLE table_name ADD COLUMNS (new_col INT,new_tcl string);
10、移动字段new_col ,new_tcl 到 address字段的后面 ; 移动列到指定位置
alter table table_name change new_col INT,new_tcl string after address ;
11、删除表的某一列较特殊,选择留下的字段,不选择的则删除
将d和e两列一起删除:
ALTER TABLE test_change REPLACE COLUMNS (a int, b int,c string,e string);
15、若删错了数据,一般回收站的位置。
hdfs dfs -ls /user/hive/.Trash/210609160000/user/hive/warehouse/ods.db