Hive之重写分区表数据overwrite
hive之insert into 和 insert overwrite与数据分区insert into 在表中追加数据。insert overwrite 先删除表中数据,再重新写入。hive向分区表中插入数据静态插入数据:要求插入数据时指定与建表时相同的分区字段INSERT OVERWRITE TABLE student_a PARTITION (month=‘09’) SELECT * from
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
更多推荐
所有评论(0)