hive动态分区,分区数据的几种插入方式

首先列举下hive分区插入的方式:
1:从文件导入数据到hive指定分区方式
load data local inpath ‘filepath’ into table tableName partition(partitionColumn=’’);
2:先创建分区,再把文件通过任何别的方式把数据已对应格式(列分隔符可以是’\t’,’\001’等)放到对应hdfs路径下。
手动创建分区
alter table tableName add partition(partitionColume=’’);
分区的删除
alter table tableName drop partition(partitionColume=’’);
3:动态修复分区,项目上比较常用的方式。
常常是mr、spark或者flink把数据处理之后放到对应的分区目录下,但这样的数据分区表是不会识别的,因为分区表的分区元数据存储在meta store中(一般是mysql),也可以使用方式2把分区一个一个添加,但是如果分区很多就过于麻烦,可以直接使用下面的指令
msck repair table tableName
4:动态分区识别插入,比较常用
先设置动态分区相关参数
set hive.exec.dynamic.partition=true;

set hive.exec.dynamic.partition.mode=nonstrict;

set hive.exec.max.dynamic.partitions.pernode=10000;

常常从一张表中查询数据,插入到另一张表,并根据具体字段动态分区

insert overwrite table tb_test partition(partitionColumn)

select col_a,

col_b,

.....

col_last,

col_date  --这个字段不是实际插入到表中的哦,只是用来标识根据此字段的值来插入到不同的分区中

from tb_test0

该方式效果如下:
插入前:
插入前
插入后:
在这里插入图片描述
在这里插入图片描述
完美插入,最后一种很常用,不过不要忘记设置参数

猜你喜欢

转载自blog.csdn.net/qq_39719415/article/details/103184188
今日推荐