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输出文件, 默认值为true
set hive.merge.mapfiles=true;
--是否合并Reduce端输出文件,默认值为false
set hive.merge.mapredfiles=true;
--合并文件的大小,默认值为256000000 256M
set 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_day
from
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;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM