Hiveパーティションテーブル操作ガイド

Hiveパーティションテーブルの操作

目次

  1. パーティションパラメータの概要
  2. パーティションテーブルの作成
  3. データ挿入方法

ハイブテーブルのハイブパーティションは、実際にはテーブルの下のディレクトリです。
ここに画像の説明を挿入
ここに画像の説明を挿入

パーティションパラメータの概要

-- 设置动态分区参数(开启动态分区,一般使用前两个参数就就可以)
set hive.exec.dynamic.partition=true; -- 使用动态分区,默认false
-- strict可设置为静态和半动态,要求至少包含一个静态分区列,且放在最前面
-- nonstrict可设置为静态、半动态和动态,动态必须设置此参数。
set hive.exec.dynamic.partition.mode=nonstrick;
-- 允许的最大的动态分区的个数。默认1000。
set  hive.exec.max.dynamic.partitions=10000;
-- 一个mapreduce job所允许的最大的动态分区的个数。默认是100。
set hive.exec.max.dynamic.partitions.pernode=10000;
-- 一个任务最多可以创建的文件数目
set hive.exec.max.created.files=150000; 
-- 限定一次最多打开的文件数
set dfs.datanode.max.xcievres=9182;

パーティションテーブルの作成

-- 创建分区表
CREATE TABLE IF NOT EXISTS cl_ods.ods_msg_user_info_di(
user_id bigint COMMENT'用户id',
user_msg string COMMENT'用户信息',
user_mail string COMMENT'用户邮箱')COMMENT'用户信息表'
partitioned by (pt_mon string COMMENT'月分区',pt_day string COMMENT '天分区')
ROW format delimited fields terminated by ',';

-- 查看数据表 -- show create table cl_ods.ods_msg_user_info_di;
create table cl_ods.ods_msg_user_info_df(
user_id bigint comment '用户id',
user_msg string comment '用户信息',
user_mail string comment '用户邮箱',
pt_mon string comment '月',
pt_day string comment '天') comment '用户信息表'
row format delimited fields terminated by ',';-- ...

データを挿入

静的パーティションにデータを挿入します

静的パーティションは、データを挿入する前に指定され、通常、挿入、挿入、上書き、データのロードなどによって挿入されます。

-- overwrite 为可选项此值,会覆盖原始该分区数据
INSERT /*OVERWRITE*/ INTO TABLE cl_ods.ods_msg_user_info_di 
PARTITION(pt_mon='201801',pt_day='20180101') 
SELECT user_id,user_msg,user_mail 
FROM cl_ods.ods_msg_user_info_df 
WHERE pt_mon='201801' and pt_day='20180101';

混合パーティションにデータを挿入します

パーティションの一部は静的で、他の部分は動的です。動的パーティションモードを設定する必要があります。

set hive.exec.dynamic.partition=true;  
set hive.exec.dynamic.partition.mode=strick;

INSERT /*OVERWRITE*/ INTO TABLE cl_ods.ods_msg_user_info_di 
PARTITION(pt_mon='201801',pt_day) -- 此处pt_day 动态获取
SELECT user_id,user_msg,user_mail,pt_day
FROM cl_ods.ods_msg_user_info_df 
WHERE pt_mon='201801' and pt_day='20180101';

データを挿入するための動的パーティション

パーティションはクエリフィールドから自動的に取得されます

set hive.exec.dynamic.partition=true;  
set hive.exec.dynamic.partition.mode=nonstrick;

INSERT /*OVERWRITE*/ INTO TABLE cl_ods.ods_msg_user_info_di 
PARTITION(pt_mon,pt_day) -- 此处pt_day 动态获取
SELECT user_id,user_msg,user_mail,pt_mon, pt_day
FROM cl_ods.ods_msg_user_info_df 
WHERE pt_mon='201801' and pt_day='20180101';

補足

パーティションコマンドの表示

SHOW PARTITIONS partitons_table_name /*[partition(partition_key=partition_val)]*/;
-- eg
SHOW PARTITIONS cl_ods.ods_msg_user_info_di partiton(pt_mon='201801');

おすすめ

転載: blog.csdn.net/dbc_zt/article/details/109726266