bigint hive java类型_详解Apache Hudi如何配置各种类型分区

1. 引入

Apache Hudi支持多种分区方式数据集,如多级分区、单分区、时间日期分区、无分区数据集等,用户可根据实际需求选择合适的分区方式,下面来详细了解Hudi如何配置何种类型分区。

2. 分区处理

为说明Hudi对不同分区类型的处理,假定写入Hudi的Schema如下

{  "type" : "record",  "name" : "HudiSchemaDemo",  "namespace" : "hoodie.HudiSchemaDemo",  "fields" : [ {    "name" : "age",    "type" : [ "long", "null" ]  }, {    "name" : "location",    "type" : [ "string", "null" ]  }, {    "name" : "name",    "type" : [ "string", "null" ]  }, {    "name" : "sex",    "type" : [ "string", "null" ]  }, {    "name" : "ts",    "type" : [ "long", "null" ]  }, {    "name" : "date",    "type" : [ "string", "null" ]  } ]}

其中一条具体数据如下

{  "name": "zhangsan",   "ts": 1574297893837,   "age": 16,   "location": "beijing",   "sex":"male",   "date":"2020/08/16"}

2.1 单分区

单分区表示使用一个字段表示作为分区字段的场景,可具体分为非日期格式字段(如location)和日期格式字段(如date)

2.1.1 非日期格式字段分区

如使用上述location字段做为分区字段,在写入Hudi并同步至Hive时配置如下

df.write().format("org.apache.hudi").                options(getQuickstartWriteConfigs()).                option(DataSourceWriteOptions.TABLE_TYPE_OPT_KEY(), "COPY_ON_WRITE").                option(DataSourceWriteOptions.PRECOMBINE_FIELD_OPT_KEY(), "ts").                option(DataSourceWriteOptions.RECORDKEY_FIELD_OPT_KEY(), "name").                option(DataSourceWriteOptions.PARTITIONPATH_FIELD_OPT_KEY(), partitionFields).                option(DataSourceWriteOptions.KEYGENERATOR_CLASS_OPT_KEY(), keyGenerator).                option(TABLE_NAME, tableName).                option("hoodie.datasource.hive_sync.enable", true).                option("hoodie.datasource.hive_sync.table", tableName).                option("hoodie.datasource.hive_sync.username", "root").                option("hoodie.datasource.hive_sync.password", "123456").                option("hoodie.datasource.hive_sync.jdbcurl", "jdbc:hive2://localhost:10000").                option("hoodie.datasource.hive_sync.partition_fields", hivePartitionFields).                option("hoodie.datasource.write.table.type", "COPY_ON_WRITE").                option("hoodie.embed.timeline.server", false).                option("hoodie.datasource.hive_sync.partition_extractor_class", hivePartitionExtractorClass).                mode(saveMode).                save(basePath);

值得注意如下几个配置项

  • DataSourceWriteOptions.PARTITIONPATH_FIELD_OPT_KEY()配置为location
  • hoodie.datasource.hive_sync.partition_fields配置为location,与写入Hudi的分区字段相同;
  • DataSourceWriteOptions.KEYGENERATOR_CLASS_OPT_KEY()配置为org.apache.hudi.keygen.SimpleKeyGenerator,或者不配置该选项,默认为org.apache.hudi.keygen.SimpleKeyGenerator
  • hoodie.datasource.hive_sync.partition_extractor_class配置为org.apache.hudi.hive.MultiPartKeysValueExtractor

Hudi同步到Hive创建的表如下

CREATE EXTERNAL TABLE `notdateformatsinglepartitiondemo`(  `_hoodie_commit_time` string,  `_hoodie_commit_seqno` string,  `_hoodie_record_key` string,  `_hoodie_partition_path` string,  `_hoodie_file_name` string,  `age` bigint,  `date` string,  `name` string,  `sex` string,  `ts` bigint)PARTITIONED BY (  `location` string)ROW FORMAT SERDE  'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe'STORED AS INPUTFORMAT  'org.apache.hudi.hadoop.HoodieParquetInputFormat'OUTPUTFORMAT  'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'LOCATION  'file:/tmp/hudi-partitions/notDateFormatSinglePartitionDemo'TBLPROPERTIES (  'last_commit_time_sync'='20200816154250',  'transient_lastDdlTime'='1597563780')

查询表notdateformatsinglepartitiondemo

tips: 查询时请先将hudi-hive-sync-bundle-xxx.jar包放入$HIVE_HOME/lib下d0d98debc2cc7550611922717be1fc31.png

2.1.2 日期格式分区

如使用上述date字段做为分区字段,核心配置项如下

  • DataSourceWriteOptions.PARTITIONPATH_FIELD_OPT_KEY()配置为date
  • hoodie.datasource.hive_sync.partition_fields配置为date,与写入Hudi的分区字段相同;
  • DataSourceWriteOptions.KEYGENERATOR_CLASS_OPT_KEY()配置为org.apache.hudi.keygen.SimpleKeyGenerator,或者不配置该选项,默认为org.apache.hudi.keygen.SimpleKeyGenerator
  • hoodie.datasource.hive_sync.partition_extractor_class配置为org.apache.hudi.hive.SlashEncodedDayPartitionValueExtractor

Hudi同步到Hive创建的表如下

CREATE EXTERNAL TABLE `dateformatsinglepartitiondemo`(  `_hoodie_commit_time` string,  `_hoodie_commit_seqno` string,  `_hoodie_record_key` string,  `_hoodie_partition_path` string,  `_hoodie_file_name` string,  `age` bigint,  `location` string,  `name` string,  `sex` string,  `ts` bigint)PARTITIONED BY (  `date` string)ROW FORMAT SERDE  'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe'STORED AS INPUTFORMAT  'org.apache.hudi.hadoop.HoodieParquetInputFormat'OUTPUTFORMAT  'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'LOCATION  'file:/tmp/hudi-partitions/dateFormatSinglePartitionDemo'TBLPROPERTIES (  'last_commit_time_sync'='20200816155107',  'transient_lastDdlTime'='1597564276')

查询表dateformatsinglepartitiondemo

911b08d4bbe5774044de165d22c8aa91.png

2.2 多分区

多分区表示使用多个字段表示作为分区字段的场景,如上述使用location字段和sex字段,核心配置项如下

  • DataSourceWriteOptions.PARTITIONPATH_FIELD_OPT_KEY()配置为location,sex
  • hoodie.datasource.hive_sync.partition_fields配置为location,sex,与写入Hudi的分区字段相同;
  • DataSourceWriteOptions.KEYGENERATOR_CLASS_OPT_KEY()配置为org.apache.hudi.keygen.ComplexKeyGenerator
  • hoodie.datasource.hive_sync.partition_extractor_class配置为org.apache.hudi.hive.MultiPartKeysValueExtractor

Hudi同步到Hive创建的表如下

CREATE EXTERNAL TABLE `multipartitiondemo`(  `_hoodie_commit_time` string,  `_hoodie_commit_seqno` string,  `_hoodie_record_key` string,  `_hoodie_partition_path` string,  `_hoodie_file_name` string,  `age` bigint,  `date` string,  `name` string,  `ts` bigint)PARTITIONED BY (  `location` string,  `sex` string)ROW FORMAT SERDE  'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe'STORED AS INPUTFORMAT  'org.apache.hudi.hadoop.HoodieParquetInputFormat'OUTPUTFORMAT  'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'LOCATION  'file:/tmp/hudi-partitions/multiPartitionDemo'TBLPROPERTIES (  'last_commit_time_sync'='20200816160557',  'transient_lastDdlTime'='1597565166')

查询表multipartitiondemo

1ebcd49841a0f8d6c254dfeabb4d5163.png

2.3 无分区

无分区场景是指无分区字段,写入Hudi的数据集无分区。核心配置如下

  • DataSourceWriteOptions.PARTITIONPATH_FIELD_OPT_KEY()配置为空字符串;
  • hoodie.datasource.hive_sync.partition_fields配置为空字符串,与写入Hudi的分区字段相同;
  • DataSourceWriteOptions.KEYGENERATOR_CLASS_OPT_KEY()配置为org.apache.hudi.keygen.NonpartitionedKeyGenerator
  • hoodie.datasource.hive_sync.partition_extractor_class配置为org.apache.hudi.hive.NonPartitionedExtractor

Hudi同步到Hive创建的表如下

CREATE EXTERNAL TABLE `nonpartitiondemo`(  `_hoodie_commit_time` string,  `_hoodie_commit_seqno` string,  `_hoodie_record_key` string,  `_hoodie_partition_path` string,  `_hoodie_file_name` string,  `age` bigint,  `date` string,  `location` string,  `name` string,  `sex` string,  `ts` bigint)ROW FORMAT SERDE  'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe'STORED AS INPUTFORMAT  'org.apache.hudi.hadoop.HoodieParquetInputFormat'OUTPUTFORMAT  'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'LOCATION  'file:/tmp/hudi-partitions/nonPartitionDemo'TBLPROPERTIES (  'last_commit_time_sync'='20200816161558',  'transient_lastDdlTime'='1597565767')

查询表nonpartitiondemo

d3e006664af3703c56e3f4cb2f8abbed.png

2.4 Hive风格分区

除了上述几种常见的分区方式,还有一种Hive风格分区格式,如location=beijing/sex=male格式,以location,sex作为分区字段,核心配置如下

  • DataSourceWriteOptions.PARTITIONPATH_FIELD_OPT_KEY()配置为location,sex
  • hoodie.datasource.hive_sync.partition_fields配置为location,sex,与写入Hudi的分区字段相同;
  • DataSourceWriteOptions.KEYGENERATOR_CLASS_OPT_KEY()配置为org.apache.hudi.keygen.ComplexKeyGenerator
  • hoodie.datasource.hive_sync.partition_extractor_class配置为org.apache.hudi.hive.SlashEncodedDayPartitionValueExtractor
  • DataSourceWriteOptions.HIVE_STYLE_PARTITIONING_OPT_KEY()配置为true

生成的Hudi数据集目录结构会为如下格式

/location=beijing/sex=male

Hudi同步到Hive创建的表如下

CREATE EXTERNAL TABLE `hivestylepartitiondemo`(  `_hoodie_commit_time` string,  `_hoodie_commit_seqno` string,  `_hoodie_record_key` string,  `_hoodie_partition_path` string,  `_hoodie_file_name` string,  `age` bigint,  `date` string,  `name` string,  `ts` bigint)PARTITIONED BY (  `location` string,  `sex` string)ROW FORMAT SERDE  'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe'STORED AS INPUTFORMAT  'org.apache.hudi.hadoop.HoodieParquetInputFormat'OUTPUTFORMAT  'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'LOCATION  'file:/tmp/hudi-partitions/hiveStylePartitionDemo'TBLPROPERTIES (  'last_commit_time_sync'='20200816172710',  'transient_lastDdlTime'='1597570039')

查询表hivestylepartitiondemo

1fded941e46f5510231b10c06988b6a8.png

3. 总结

本篇文章介绍了Hudi如何处理不同分区场景,上述配置的分区类配置可以满足绝大多数场景,当然Hudi非常灵活,还支持自定义分区解析器,具体可查看KeyGeneratorPartitionValueExtractor类,其中所有写入Hudi的分区字段生成器都是KeyGenerator的子类,所有同步至Hive的分区值解析器都是PartitionValueExtractor的子类。上述示例代码都已经上传至https://github.com/leesf/hudi-demos,该仓库会持续补充各种使用Hudi的Demo,方便开发者快速了解Hudi,构建企业级数据湖,欢迎star & fork。

推荐阅读

Apache Hudi表自动同步至阿里云数据湖分析DLA

Apache Hudi + AWS S3 + Athena实践

官宣!AWS Athena正式可查Apache Hudi数据集

生态 | Apache Hudi插上Alluxio的翅膀

Apache Hudi重磅RFC解读之存量表高效迁移机制

958aef72dd200ab00e527ac81fb33440.png

d0987e1a9c44abc9cf077ae14dd55a45.png

65022b501b0448aa5bbe9bf3b91300ad.png

`

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/291704.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C#中的命名空间和程序集

前言今天这篇文章和大家一起学习下C#语言下的命名空间和程序集。在日常的编码工作中,我们对命名空间和程序集都不会很陌生。在创建项目文件时,IDE自动会为我们创建好一个大的命名空间和程序集。大多数业务代码都是在解决方案下各自的命令空间里进行编码的…

C/C++预处理宏的总结

1.定义顺序的无关性 #define PI 3.14 #define TWO_PI 2*PI 这两句谁前谁后无所谓,因为预处理器不断迭代来实现宏替换,直到源文件中没有宏了才停止。 2. 宏变量变成字符串 #define str(x) #x 例子:str (teststring) > "teststrin…

基于jQuery的ajax系列之用FormData实现页面无刷新上传

接着上一篇ajax系列之用jQuery的ajax方法向服务器发出get和post请求写,这篇主要写如何利用ajax和FormData实现页面无刷新的文件上传效果,主要用到了jQuery的ajax()方法和XMLHttpRequest Level 2的FormData接口。关于FormData,大家可以看MDN文…

linux网络编程之用多线程实现客户端到服务端的通信(基于udp)

1、开启一个线程接受数据,主线程发送数据的代码 #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <pthread.h> #include <netinet/in.h> #include <errno.h> #include <sys/time.h&g…

Apache FTPClient操作文件上传下载及公共类

我们在项目中可能需要使用ftp进行文件的上传、下载、获取服务器目录信息等相关操作&#xff0c;我们可以使用apache的FTPClient进行相关的操作&#xff0c;下面把相关公共方法与大家交流分享&#xff0c;每个方法前都有详细的注释进行讲解&#xff0c;不过在进行ftp测试的时候&…

abd shell关闭所有程序_在后台服务器上运行程序

之前总结过screen的用法&#xff0c;但还可以用nohup命令。nohup工具&#xff1a;Linux系统中有提供一个很好的不挂断地运行命令——nohup。我们使用nohup能很简单的控制使用&#xff0c;在此就简单的介绍一下nohup工具。nohup 命令nohup就是不挂起的意思( no hang up)。用途&a…

优秀的JavaScript模块是怎样炼成的

引言&#xff1a;如今的JavaScript已经是Web上最流行的语言&#xff0c;没有之一。从Github上的语言排行榜https://github.com/languages上即可看出&#xff0c;也是如今最为活跃的开源社区。随着Node的加入&#xff0c;JavaScript开枝散叶进入服务器领域&#xff0c;为这个语言…

解锁JDK 12的奇妙之旅:新特性详解

欢迎来到我的博客&#xff0c;代码的世界里&#xff0c;每一行都是一个故事 解锁JDK 12的奇妙之旅&#xff1a;新特性详解 前言switch表达式拓展NumberFormat对复杂数字的格式化字符串支持transform、indent操作新增方法Files.mismatch(Path, Path)Teeing Collector支持unicode…

.NET6之MiniAPI(十四):跨域CORS(上)

为了说明跨请求&#xff0c;创建了两个项目&#xff0c;一个mini api&#xff0c;端口是5001&#xff0c;另一个razor page项目&#xff0c;端口是5280。5280项目会在页面用ajax的方式来请求5001&#xff0c;形成跨域请求&#xff0c;由于是本地测试&#xff0c;host都是localh…

Linux文件锁学习-flock, lockf, fcntl

参考 linux中fcntl()、lockf、flock的区别 这三个函数的作用都是给文件加锁&#xff0c;那它们有什么区别呢&#xff1f; 首先flock和fcntl是系统调用&#xff0c;而lockf是库函数。lockf实际上是fcntl的封装&#xff0c;所以lockf和fcntl的底层实现是一样的&#xff0c;对文件…

linux网络编程之sockaddr_in和in_addr区别

1、struct in_addr struct in_addr就是32位IP地址。 struct in_addr { union {struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;struct { u_short s_w1,s_w2; } S_un_w;u_long S_addr;} S_un;#define s_addr S_un.S_addr }; 2、sockaddr_in struct sockaddr_in …

入驻

新手登录~

django model filter 条件过滤,及多表连接查询、反向查询,某字段的distinct

2019独角兽企业重金招聘Python工程师标准>>> 1.多表连接查询&#xff1a;当我知道这点的时候顿时觉得django太NX了。 class A(models.Model): name models.CharField(u名称) class B(models.Model): aa models.ForeignKey(A)B.objects.filter(aa__name__c…

利用tabluea分析数据的案例_利用德温特分析Dartsip的案例检索结果

德温特创新平台(Derwent Innovation)与Darts-ip知识产权案例数据库均是科睿唯安旗下的知识产权数据库&#xff0c;虽然这两个数据库的侧重点分别在于专利信息与知识产权判例&#xff0c;但若将两者结合使用则能发挥11>2的作用&#xff0c;打通专利全生命周期。关注我们的朋友…

浅谈C#可变参数params

前言前几天在群里看到群友写了一个基础框架&#xff0c;其中涉及到关于同一个词语可以添加多个近义词的一个场景。当时群友的设计是类似字典的设计&#xff0c;直接添加k-v的操作&#xff0c;本人看到后思考了一下觉得使用c#中的params可以更优雅的实现一个key同时添加一个集合…

Html、Css-----当有文字和图片的时候,需要文字和图片居中,怎么实现?不想文字换行怎么设置...

1 当有文字和图片的时候&#xff0c;需要文字和图片居中&#xff0c;怎么实现&#xff1f; <a href#" target"aa" style"white-space:nowrap;"><img src"img.jpg" align"absmiddle"/>文字</a> 在img标签中加入…

linux网络编程之怎么配置好unp.h文件

1、获取unp源码 下载地址:http://www.unpbook.com/src.html 然后用tar -zxvf unpv13e.tar.gz命令解压 2、进入unpv13e目录执行configure cd unpv13e ,然后执configure文件 3、打开README文件,使用make命令 打开README文件

Win10下安装wireshark不能正常使用,cmd管理员身份调用net start npf命令显示无法启动该服务

我安装wireshark完成后&#xff0c;刚开始运行wireshark并开始捕获时也不能正常捕获&#xff0c;然后发现是winpcap的原因。 我把我安装的wireshark版本和winpcap的版本资源和我个人出现问题的解决办法及经验已打包上传资源&#xff0c;伙伴们有需要的可以去参考借鉴一下~ PS…

CMD、AMD、commonJs 规范的写法

比较好的文章&#xff1a; http://www.jianshu.com/p/d67b...AMD 是 RequireJS 在推广过程中对模块定义的规范化产出。CMD 是 SeaJS 在推广过程中对模块定义的规范化产出。 //AMD 规范 /*** define(id?, dependencies?, factory); id 和 dependencies 是可选的。** define([d…

mft文件记录属性头包括_关于NTFS-MFT

一、Ntfs文件系统在磁盘上的分布一个ntfs文件系统由引导扇区、MFT(包含MFT元数据)和数据区组成。NTFS中存储了两份MFT备份以防MFT文件损坏&#xff0c;两个MFT备份的具体起始位置都存储在引导扇区中。image.png二、引导扇区($Boot)引导扇区是从NTFS文件系统的第一个扇区开始&am…