irpas技术客

Hive之重写分区表数据overwrite_侯侯侯先生_hive overwrite

irpas 3966

hive之insert into 和 insert overwrite与数据分区

insert into 在表中追加数据。 insert overwrite 先删除表中数据,再重新写入。

hive向分区表中插入数据

创建分区表:partitioned by (month string)

CREATE EXTERNAL TABLE `student_a`( `company_id` string COMMENT '公司id', `statistics_value` string COMMENT '风险值', `statistics_date` string COMMENT '统计时间', `create_date` date COMMENT '创建时间' ) partitioned by (month string) ROW FORMAT SERDE 'org.apache.hadoop.hive.ql.io.orc.OrcSerde' STORED AS ORC LOCATION 'hdfs://sjh-kf-cm01:8020/zjs/xy/xy_dws.db/student_a'; 静态插入数据:要求插入数据时指定与建表时相同的分区字段

INSERT OVERWRITE TABLE student_a PARTITION (month=‘09’) SELECT * from student_source;

动静混合分区插入:要求指定部分分区字段的值

INSERT OVERWRITE TABLE student_a PARTITION (Year=‘2021’,month) SELECT * from student_source;

动态分区插入,值指定分区,不指定值。需要设置开启自动分区

set hive.exec.dynamic.partition=true; set hive.exec.dynamic.partition.mode=nonstrict; INSERT OVERWRITE TABLE student_a PARTITION (month) SELECT * from student_source;

hive.exec.dynamic.partition 是否启动动态分区。false(不开启) true(开启)默认是 false hive.exec.dynamic.partition.mode 打开动态分区后,动态分区的模式,有 strict和 nonstrict 两个值可选,strict 要求至少包含一个静态分区列,nonstrict则无此要求。 hive.exec.max.dynamic.partitions 允许的最大的动态分区的个数。可以手动增加分区。默认1000 hive.exec.max.dynamic.partitions.pernode 一个 mapreduce job所允许的最大的动态分区的个数。默认是100


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。

标签: #hive #OVERWRITE #hive之insert #into # #Insert