hive 分区partition表 创建 数据导入(动态分区插入、静态分区插入、动静态混合插入)

学习《hive 编程指南》一书,整理的知识,所以文章例子出自此书。

分区创建与数据导入的步骤:

1.创建分区表(以外部分区表为例)

create external table if not exists dividends(

ymd string,

dividend string)

partitioned by (ex_change string,symbol string)

row format delimited fields terminated by ‘,’;

2.创建还有分区表字段与分区字段的内部表(管理表)

内部表的字段应该包含红色字段,建表略

3.将数据导入2中创建的表。load data……

4.通过内部表静态或者动态将数据插入分区表

非常重要的动态分区属性:

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

在插入动态分区时,通常会检查日志中是否有清除的错误,因为这些配置参数值存在错误。我遇到的错误消息:

[En]

When inserting a dynamic partition, it is often customary to check the log for clear errors because of errors in the values of these configuration parameters. The error message I encountered:

Caused by: org.apache.hadoop.hive.ql.metadata.HiveFatalException: [Error 20004]: Fatal error occurred when node tried to create too many dynamic partitions. The maximum number of dynamic partitions is controlled by hive.exec.max.dynamic.partitions and hive.exec.max.dynamic.partitions.pernode. Maximum was set to: 100

因为分区的数量超过了表名的值,所以可以通过更改参数值来避免此类错误。

[En]

Because the number of partitions exceeds the value of the table name, such errors can be avoided by changing the parameter values.

1)静态插入数据

注意:方框中的字段位置以及个数一定要与分区表(dividends)的字段位置以及个数相符合,否则会报出类似如下的错误

FAILED: SemanticException [Error 10044]: Line 1:23 Cannot insert into target table because column number/types are different ‘symbol’: Table insclause-0 has 3 columns, but query has 4 columns.

从上面错误提示看出,查询的表有4列,而目标表格(也就是需要插入数据的表格)有3列,由于列的数目不一样,导致了上面的语句不能成功运行,所以我们需要保证查询结果列的数目和需要插入数据表格的列数目一致。

2)动静态混合分区插入

hive 分区partition表 创建 数据导入(动态分区插入、静态分区插入、动静态混合插入)

截图有错误信息,相信大家知道这是什么原因了吧!!!

一定要注意动态分区参数值以及1)的注意事项

3)动态分区插入

hive 分区partition表 创建 数据导入(动态分区插入、静态分区插入、动静态混合插入)

截图中的报错!!是配置参数值问题哦!

有什么问题请大家指教,本人初学 hive!内容中有借鉴部分。

Original: https://blog.csdn.net/oliang/article/details/47948801
Author: oliang
Title: hive 分区partition表 创建 数据导入(动态分区插入、静态分区插入、动静态混合插入)

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/13403/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

最近整理资源【免费获取】:   👉 程序员最新必读书单  | 👏 互联网各方向面试题下载 | ✌️计算机核心资源汇总