搜索
您的当前位置:首页正文

hive分区表建表,删除字段

来源:爱go旅游网
hive分区表建表,删除字段

⼀、建⽴分区表(parquet存储格式)

--数据倾斜优化

set tez.queue.name=队列;

set hive.execution.engine=tez;

set hive.exec.dynamic.partition.mode=nonstrict;set hive.optimize.sort.dynamic.partition=true;set hive.exec.max.dynamic.partitions=100000;

set hive.exec.max.dynamic.partitions.pernode=100000;set hive.ignore.mapjoin.hint=true;set hive.auto.convert.join = true;set hive.groupby.skewindata=true;

set hive.input.format=org.apache.hadoop.hive.ql.io.CombineHiveInputFormat;--是否合并Map输出⽂件, 默认值为trueset hive.merge.mapfiles=true;

--是否合并Reduce端输出⽂件,默认值为falseset hive.merge.mapredfiles=true;

--合并⽂件的⼤⼩,默认值为256000000 256Mset hive.merge.size.per.task=256000000;

set mapreduce.job.reduce.slowstart.completedmaps=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_dayfrom

bdp.tmp_dm_dwd_data.dwd_qua_cos_ticket_day_ttmp02;三、分区表添加字段,末尾要加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_dwd_data.test_03;create table tmp_dm_dwd_data.test_03( customer_id STRING COMMENT '单号')

ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' stored as textfile;

--数据导⼊

load data inpath'/user/upload/data.csv' overwrite into table tmp_dm_dwd_data.test_03;

因篇幅问题不能全部显示,请点此查看更多更全内容

Top