本文為您介紹如何使用E-MapReduce的Hudi MetaStore。

背景信息

Hudi每次操作數據都會新增時間線(instant),查詢時需要讀取所有時間線元數據,以獲得在該時間點上的有效分區或文件,其中Partition Listing和File Listing涉及大量IO操作,耗時較多。

湖格式和傳統表結構不同,有其特有的元數據,例如時間線和多版本的文件。因此,E-MapReduce提出了云上Hudi MetaStore,托管Hudi Table的instant元數據,并且設計了Partition和File的生命周期管理。目前已支持基于Hudi MetaStore進行Partition Listing和File Listing加速。

前提條件

已在華東1(杭州)、華東2(上海)或華北2(北京)地域創建EMR-3.45.0及后續版本或EMR-5.11.0及后續版本的集群,且元數據選擇了DLF統一元數據

參數介紹

您可以在Hudi服務配置頁面的hudi.default.conf頁簽,設置以下參數,使用Hudi MetaStore。

參數描述
hoodie.metastore.type選擇Hudi元數據的實現方式:
  • LOCAL:使用Hudi原生的元數據。
  • METASTORE:使用EMR的Hudi MetaStore的元數據。
hoodie.metadata.enable取值如下:
  • false:關閉Hudi自帶的元數據表。
    說明 設置為false,才可以使用EMR的Hudi MetaStore的元數據表。
  • true:使用Hudi自帶的元數據表。
您可以根據您的使用場景,配置不同的參數:
  • 不使用任何元數據表
    hoodie.metastore.type=LOCAL
    hoodie.metadata.enable=false
  • 使用Hudi自帶的元數據表
    hoodie.metastore.type=LOCAL
    hoodie.metadata.enable=true
  • 使用EMR Hudi MetaStore元數據表(默認情況)
    hoodie.metastore.type=METASTORE
    hoodie.metadata.enable=false

使用示例

以下內容以spark-sql為例,為您介紹如何使用EMR Hudi MetaStore元數據表,并開啟加速功能。

  1. 使用SSH方式登錄集群,詳情請參見登錄集群
  2. 執行以下命令,進入spark-sql命令行(以Spark3為例)。
    spark-sql --conf 'spark.serializer=org.apache.spark.serializer.KryoSerializer' \
              --conf 'spark.sql.extensions=org.apache.spark.sql.hudi.HoodieSparkSessionExtension'
    當返回信息中包含如下信息時,表示已進入spark-sql命令行。
    spark-sql>
  3. 執行以下命令,新建表。
    create table h0(
      id bigint,
      name string,
      price double
    ) using hudi
    tblproperties (
       primaryKey = 'id',
       preCombineField = 'id'
    ) location '/tmp/hudi_cases/h0';
  4. 執行以下命令,插入數據。
    insert into h0 select 1, 'a1', 10;
  5. 執行以下命令,退出spark-sql命令行。
    exit;
  6. 執行以下命令,查看Hudi表的.hoodie目錄內的文件hoodie.properties
    hdfs dfs -cat /tmp/hudi_cases/h0/.hoodie/hoodie.properties
    當返回信息中包含hoodie.metastore.type=METASTOREhoodie.metastore.table.id時,表示使用Hudi MetaStore成功。
    hoodie.metastore.catalog.id=
    hoodie.table.precombine.field=id
    hoodie.datasource.write.drop.partition.columns=false
    hoodie.table.type=COPY_ON_WRITE
    hoodie.archivelog.folder=archived
    hoodie.timeline.layout.version=1
    hoodie.table.version=5
    hoodie.metastore.type=METASTORE
    hoodie.table.recordkey.fields=id
    hoodie.datasource.write.partitionpath.urlencode=false
    hoodie.database.name=test_db
    hoodie.table.keygenerator.class=org.apache.hudi.keygen.NonpartitionedKeyGenerator
    hoodie.table.name=h0
    hoodie.datasource.write.hive_style_partitioning=true
    hoodie.metastore.table.id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    hoodie.table.checksum=3349919362
    hoodie.table.create.schema={"type"\:"record","name"\:"h0_record","namespace"\:"hoodie.h0","fields"\:[{"name"\:"_hoodie_commit_time","type"\:["string","null"]},{"name"\:"_hoodie_commit_seqno","type"\:["string","null"]},{"name"\:"_hoodie_record_key","type"\:["string","null"]},{"name"\:"_hoodie_partition_path","type"\:["string","null"]},{"name"\:"_hoodie_file_name","type"\:["string","null"]},{"name"\:"id","type"\:["long","null"]},{"name"\:"name","type"\:["string","null"]},{"name"\:"price","type"\:["double","null"]}]}