hive分区表建表,删除字段
⼀、建⽴分区表(parquet存储格式)
--数据倾斜优化
set tez.queue.name=队列;
ine=tez;
de=nonstrict;
set hive.optimize.sort.dynamic.partition=true;
ax.dynamic.partitions=100000;
ax.dynamic.partitions.pernode=100000;
set hive.ignore.mapjoin.hint=true;
set vert.join = true;
upby.skewindata=true;
set hive.input.format=org.apache.hadoop.hive.ql.io.CombineHiveInputFormat;
--是否合并Map输出⽂件, 默认值为true
mapfiles=true;
--是否合并Reduce端输出⽂件,默认值为false
mapredfiles=true;
--合并⽂件的⼤⼩,默认值为256000000 256M
size.per.task=256000000;
set duce.slowstartpletedmaps=0.1;
create external table if not exists dm_dwd_data.dwd_qua_cos_ticket_day(
dept_code STRING COMMENT '⽹点'
,
product_code STRING COMMENT '产品'
,rate_hb double COMMENT '⽇环⽐')
comment '建表'
PARTITIONED BY (inc_day STRING)
ROW FORMAT SERDE
'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe'
STORED AS INPUTFORMAT
'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat';
⼆、临时表插⼊分区
insert overwrite table dm_dwd_data.dwd_qua_cos_ticket_day partition (inc_day)
select
dept_code --⽹点
,product_code --产品
,rate_hb --⽇环⽐
,inc_day
from
三、分区表添加字段,末尾要加cascade
alter table dm_dwd_data.dwd_qua_cos_ticket_day add columns(
is_merge_dept STRING COMMENT '是否同场站'
,
is_shiftno_num STRING COMMENT '是否多班次') cascade;
四、分区表删除字段
alter table dm_dwd_data.dwd_qua_cos_ticket_day replace columns (dept_code STRING,product_code STRING);括号⾥为需要保留的字段
五、⼿⼯数据导⼊
--创建导⼊数据表
drop table if exists tmp_dm_st_03;
create table tmp_dm_st_03(
customer_id STRING COMMENT '单号'
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
stored as textfile;
--数据导⼊drop删除表
load data inpath'/user/upload/data.csv' overwrite into table tmp_dm_st_03;