DROP TABLE IF EXISTS dm_xx.t_adl_daily_all_users_v1; USE dm_xx; CREATE TABLE IF NOT EXISTS dm_xx.t_adl_daily_all_users_v1( aa string COMMENT ' ' ,bb string COMMENT '区号' ,cc string COMMENT '号码' ) PARTITIONED BY ( inc_day string COMMENT 'inc_day used by partition' ) STORED AS parquet TBLPROPERTIES('parquet.compression'='SNAPPY');
1. 创建parquet table :
create table mytable(a int,b int) STORED AS PARQUET;
2. 创建带压缩的parquet table:
create table mytable(a int,b int) STORED AS PARQUET TBLPROPERTIES('parquet.compression'='SNAPPY');
3. 如果原来创建表的时候没有指定压缩,后续可以通过修改表属性的方式添加压缩:
ALTER TABLE mytable SET TBLPROPERTIES ('parquet.compression'='SNAPPY');
或者在写入的时候
set parquet.compression=SNAPPY;
不过只会影响后续入库的数据,原来的数据不会被压缩,需要重跑原来的数据。
采用压缩之后大概可以降低1/3的存储大小。
-------------------------------------------------------- 合并 -------------------------------------------------------- -- set hive.execution.engine=tez; -- set tez.queue.name=dtb_matter; set hive.execution.engine=mr; set mapred.job.queue.name=dw; set hive.exec.parallel=true; set hive.exec.dynamic.partition=true; set hive.exec.dynamic.partition.mode=nonstrict; drop table tmp_dim.dim_ch; create table tmp_dim.dim_ch stored as parquet as select ... -- 临时表 保留7天分区 -- alter table dim.dim_tb_name drop partition (inc_day = '$[time(yyyyMMdd,-7d)]');