<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Hudi 配置 | 一文徹底掌握 Apache Hudi 的主鍵和分區(qū)配置

          共 6804字,需瀏覽 14分鐘

           ·

          2021-04-10 11:22


          1. 介紹

          Hudi中的每個(gè)記錄都由HoodieKey唯一標(biāo)識(shí),HoodieKey由記錄鍵和記錄所屬的分區(qū)路徑組成。基于此設(shè)計(jì)Hudi可以將更新和刪除快速應(yīng)用于指定記錄。Hudi使用分區(qū)路徑字段對(duì)數(shù)據(jù)集進(jìn)行分區(qū),并且分區(qū)內(nèi)的記錄有唯一的記錄鍵。由于僅在分區(qū)內(nèi)保證唯一性,因此在不同分區(qū)之間可能存在具有相同記錄鍵的記錄。應(yīng)該明智地選擇分區(qū)字段,因?yàn)樗赡苡绊憯z取和查詢(xún)延遲。

          2. KeyGenerators(鍵生成器)

          Hudi提供了一些開(kāi)箱即用的鍵生成器,用戶可以基于此滿足大部分業(yè)務(wù)需求,或者自定義實(shí)現(xiàn)KeyGenerator,本篇博客將介紹所有不同類(lèi)型的且可用的KeyGenerators。

          KeyGenerator的接口定義在這里[1]

          在介紹不同類(lèi)型KeyGenerator之前,一些通用配置如下

          配置解釋
          hoodie.datasource.write.recordkey.field指定record key字段
          hoodie.datasource.write.partitionpath.field指定分區(qū)字段
          hoodie.datasource.write.keygenerator.class指定KeyGenerator類(lèi)全路徑名
          hoodie.datasource.write.partitionpath.urlencode當(dāng)設(shè)置為true,partitionPath將會(huì)使用url編碼,默認(rèn)值為false
          hoodie.datasource.write.hive_style_partitioning當(dāng)設(shè)置為true,使用hive風(fēng)格的分區(qū),分區(qū)將為key=value格式,默認(rèn)值為false

          如果使用TimestampBasedKeyGenerator,還會(huì)有其他額外的配置

          2.1 SimpleKeyGenerator[2]

          指定一個(gè)字段為Record Key,分區(qū)字段也指定一個(gè)字段,大部分情況使用該配置,其會(huì)從數(shù)據(jù)中解析出值并轉(zhuǎn)化為string類(lèi)型。

          2.2 ComplexKeyGenerator[3]

          可以指定一個(gè)或多個(gè)字段作為Record key或者分區(qū)字段,多個(gè)字段使用逗號(hào)分割,如 hoodie.datasource.write.recordkey.field :col1,col4

          2.3 GlobalDeleteKeyGenerator[4]

          基于全局索引的刪除不需要分區(qū)值,所以該生成器不需要使用分區(qū)值來(lái)生成HoodieKey。

          2.4 TimestampBasedKeyGenerator[5]

          該鍵生成器依賴(lài)timestamp分區(qū)字段,字段值將會(huì)被轉(zhuǎn)化為timestamp,而不是string類(lèi)型。Record key設(shè)置和前面一樣,使用該鍵生成器時(shí)需要一些額外的配置項(xiàng)如下

          配置說(shuō)明
          hoodie.deltastreamer.keygen.timebased.timestamp.type支持如下Timestamp類(lèi)型(UNIX_TIMESTAMP, DATE_STRING, MIXED, EPOCHMILLISECONDS, SCALAR)
          hoodie.deltastreamer.keygen.timebased.output.dateformat輸出日期類(lèi)型
          hoodie.deltastreamer.keygen.timebased.timezone數(shù)據(jù)格式的時(shí)區(qū)
          hoodie.deltastreamer.keygen.timebased.input.dateformat輸入日期類(lèi)型

          典型TimestampBasedKeyGenerator配置如下

          2.4.1 Timestamp類(lèi)型為GMT

          配置
          hoodie.deltastreamer.keygen.timebased.timestamp.type“EPOCHMILLISECONDS”
          hoodie.deltastreamer.keygen.timebased.output.dateformat“yyyy-MM-dd hh”
          hoodie.deltastreamer.keygen.timebased.timezone“GMT+8:00”

          輸入字段值為1578283932000L

          分區(qū)字段將為2020-01-06 12

          如果一些行輸入字段只為null

          分區(qū)字段將為1970-01-01 08

          2.4.2 Timestamp類(lèi)型為DATE_STRING

          Config field
          hoodie.deltastreamer.keygen.timebased.timestamp.type“DATE_STRING”
          hoodie.deltastreamer.keygen.timebased.output.dateformat“yyyy-MM-dd hh”
          hoodie.deltastreamer.keygen.timebased.timezone“GMT+8:00”
          hoodie.deltastreamer.keygen.timebased.input.dateformat“yyyy-MM-dd hh:mm:ss”

          輸入字段值為2020-01-06 12:12:12

          分區(qū)字段將為2020-01-06 12

          如果一些行輸入字段只為null

          分區(qū)字段將為1970-01-01 12:00:00

          2.4.3 標(biāo)量實(shí)例

          Config fieldValue
          hoodie.deltastreamer.keygen.timebased.timestamp.type“SCALAR”
          hoodie.deltastreamer.keygen.timebased.output.dateformat“yyyy-MM-dd hh”
          hoodie.deltastreamer.keygen.timebased.timezone“GMT”
          hoodie.deltastreamer.keygen.timebased.timestamp.scalar.time.unit“days”

          輸入字段值為20000L

          分區(qū)字段將為2024-10-04 12

          如果一些行輸入字段只為null

          分區(qū)字段將為1970-01-01 12

          2.4.4 ISO8601 Z單輸入格式

          Config fieldValue
          hoodie.deltastreamer.keygen.timebased.timestamp.type“DATE_STRING”
          hoodie.deltastreamer.keygen.timebased.input.dateformat“yyyy-MM-dd’T’HH:mm:ss.SSSZ”
          hoodie.deltastreamer.keygen.timebased.input.dateformat.list.delimiter.regex””
          hoodie.deltastreamer.keygen.timebased.input.timezone””
          hoodie.deltastreamer.keygen.timebased.output.dateformat“yyyyMMddHH”
          hoodie.deltastreamer.keygen.timebased.output.timezone“GMT”

          輸入字段值為2020-04-01T13:01:33.428Z

          分區(qū)字段將為2020040113

          2.4.5 ISO8601 Z多輸入格式

          Config fieldValue
          hoodie.deltastreamer.keygen.timebased.timestamp.type“DATE_STRING”
          hoodie.deltastreamer.keygen.timebased.input.dateformat“yyyy-MM-dd’T’HH:mm:ssZ,yyyy-MM-dd’T’HH:mm:ss.SSSZ”
          hoodie.deltastreamer.keygen.timebased.input.dateformat.list.delimiter.regex””
          hoodie.deltastreamer.keygen.timebased.input.timezone””
          hoodie.deltastreamer.keygen.timebased.output.dateformat“yyyyMMddHH”
          hoodie.deltastreamer.keygen.timebased.output.timezone“UTC”

          輸入字段值為2020-04-01T13:01:33.428Z

          分區(qū)字段將為2020040113

          2.4.6 ISO8601多輸入格式

          Config fieldValue
          hoodie.deltastreamer.keygen.timebased.timestamp.type“DATE_STRING”
          hoodie.deltastreamer.keygen.timebased.input.dateformat“yyyy-MM-dd’T’HH:mm:ssZ,yyyy-MM-dd’T’HH:mm:ss.SSSZ”
          hoodie.deltastreamer.keygen.timebased.input.dateformat.list.delimiter.regex””
          hoodie.deltastreamer.keygen.timebased.input.timezone””
          hoodie.deltastreamer.keygen.timebased.output.dateformat“yyyyMMddHH”
          hoodie.deltastreamer.keygen.timebased.output.timezone“UTC”

          輸入字段值為2020-04-01T13:01:33-05:00

          分區(qū)字段將為2020-04-01T13:01:33-05:00

          2.4.7 日期類(lèi)型

          Config fieldValue
          hoodie.deltastreamer.keygen.timebased.timestamp.type“DATE_STRING”
          hoodie.deltastreamer.keygen.timebased.input.dateformat“yyyy-MM-dd’T’HH:mm:ssZ,yyyy-MM-dd’T’HH:mm:ss.SSSZ,yyyyMMdd”
          hoodie.deltastreamer.keygen.timebased.input.dateformat.list.delimiter.regex””
          hoodie.deltastreamer.keygen.timebased.input.timezone“UTC”
          hoodie.deltastreamer.keygen.timebased.output.dateformat“MM/dd/yyyy”
          hoodie.deltastreamer.keygen.timebased.output.timezone“UTC”

          輸入字段只為220200401

          分區(qū)字段將為04/01/2020

          2.5 CustomKeyGenerator[6]

          CustomKeyGenerator是一種通用的KeyGenerator,綜合了SimpleKeyGenerator、ComplexKeyGenerator和TImestampBasedKeyGenerator的特性,可以配置鍵和分區(qū)路徑為單字段或組合字段,如果要定義基于常規(guī)字段和基于時(shí)間戳的字段的復(fù)雜分區(qū)路徑,此keyGenerator非常有用,配置項(xiàng)hoodie.datasource.write.partitionpath.field的值對(duì)應(yīng)格式應(yīng)為field1:PartitionKeyType1,field2:PartitionKeyType2…

          完整的分區(qū)路徑創(chuàng)建為<field1的PartitionKeyType1的值>/<field2的PartitionKeyType2的值>,依此類(lèi)推。每個(gè)分區(qū)鍵類(lèi)型可以是SIMPLE或TIMESTAMP。

          配置值示例:field_3:simple, field_5:timestamp

          如果使用SimpleKeyGenerator,則RecordKey的配置值可以是單個(gè)字段,如果使用ComplexKeyGenerator,則配置值可以是逗號(hào)分隔的字段名稱(chēng),例如:col1col3,col4

          2.6 NonPartitionedKeyGenerator[7]

          如果你的Hudi數(shù)據(jù)集未分區(qū),則可以使用NonPartitionedKeyGenerator,它將為所有記錄返回一個(gè)空分區(qū)。換句話說(shuō),所有記錄都寫(xiě)入到同一個(gè)分區(qū)(為空"")

          3. 總結(jié)

          本博客介紹了Apache Hudi中不同的record key生成器及其配置,希望可以讓你對(duì)Apache Hudi中可用的不同類(lèi)型的Key生成器有一個(gè)很好的了解,感謝一直以來(lái)對(duì)Hudi社區(qū)的支持。


          推薦閱讀

          Apache Flink 1.12.2集成Hudi 0.9.0運(yùn)行指南

          Lakehouse元數(shù)據(jù)管理技術(shù)深度解析

          干貨!Apache Hudi如何智能處理小文件問(wèn)題

          重磅!解鎖Apache Flink讀寫(xiě)Apache Hudi新姿勢(shì)

          Apache Hudi核心概念一網(wǎng)打盡

          引用鏈接

          [1] 在這里: https://github.com/apache/hudi/blob/master/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/keygen/KeyGenerator.java
          [2] SimpleKeyGenerator: https://github.com/apache/hudi/blob/master/hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/keygen/SimpleKeyGenerator.java
          [3] ComplexKeyGenerator: https://github.com/apache/hudi/blob/master/hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/keygen/ComplexKeyGenerator.java
          [4] GlobalDeleteKeyGenerator: https://github.com/apache/hudi/blob/master/hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/keygen/GlobalDeleteKeyGenerator.java
          [5] TimestampBasedKeyGenerator: https://github.com/apache/hudi/blob/master/hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/keygen/TimestampBasedKeyGenerator.java
          [6] CustomKeyGenerator: https://github.com/apache/hudi/blob/master/hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/keygen/CustomKeyGenerator.java
          [7] NonPartitionedKeyGenerator: https://github.com/apache/hudi/blob/master/hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/keygen/NonpartitionedKeyGenerator.java


          瀏覽 179
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  人人看,人人摸 | 欧美乱伦精品 | 欧美一级另类 | 美女自慰喷水网站 | 天天操天天操天天干 |