【问题标题】:Why apache-hudi is creating COPY_ON_WRITE table even if I have given MERGE_ON_READ?即使我给出了 MERGE_ON_READ,为什么 apache-hudi 仍在创建 COPY_ON_WRITE 表?
【发布时间】:2021-07-13 03:09:53
【问题描述】:

我正在尝试使用 MERGE_ON_READ 表类型创建一个简单的 hudi 表。 在 hoodie.properties 文件中执行代码后,我看到 hoodie.table.type=COPY_ON_WRITE

我在这里错过了什么吗?

此代码的 Jupyter Notebook: https://github.com/sannidhiteredesai/spark/blob/master/hudi_acct.ipynb

hudi_options = {
    "hoodie.table.name": "hudi_acct",
    "hoodie.table.type": "MERGE_ON_READ",
    "hoodie.datasource.write.operation": "upsert",
    "hoodie.datasource.write.recordkey.field": "acctid",
    "hoodie.datasource.write.precombine.field": "ts",
    "hoodie.datasource.write.partitionpath.field": "date",
    "hoodie.datasource.write.hive_style_partitioning": "true",
    "hoodie.upsert.shuffle.parallelism": 8,
    "hoodie.insert.shuffle.parallelism": 8,
}

input_df = spark.createDataFrame(
    [
        (100, "2015-01-01", "2015-01-01T13:51:39.340396Z", 10),
        (101, "2015-01-01", "2015-01-01T12:14:58.597216Z", 10),
        (102, "2015-01-01", "2015-01-01T13:51:40.417052Z", 10),
        (103, "2015-01-01", "2015-01-01T13:51:40.519832Z", 10),
        (104, "2015-01-02", "2015-01-01T12:15:00.512679Z", 10),
        (104, "2015-01-02", "2015-01-01T12:15:00.512679Z", 10),
        (104, "2015-01-02", "2015-01-02T12:15:00.512679Z", 20),
        (105, "2015-01-02", "2015-01-01T13:51:42.248818Z", 10),
    ],
    ("acctid", "date", "ts", "deposit"),
)

# INSERT
(
    input_df.write.format("org.apache.hudi")
    .options(**hudi_options)
    .mode("append")
    .save(hudi_dataset)
)


update_df = spark.createDataFrame(
    [(100, "2015-01-01", "2015-01-01T13:51:39.340396Z", 20)],
    ("acctid", "date", "ts", "deposit"))

# UPDATE
(
    update_df.write.format("org.apache.hudi")
    .options(**hudi_options)
    .mode("append")
    .save(hudi_dataset)
)

编辑: 执行上述代码后,我看到在 date=2015-01-01 分区中创建了 2 个 parquet 文件。在读取第二个镶木地板文件时,我希望只获得更新的 1 条记录,但我也可以看到该分区中的所有其他记录。

【问题讨论】:

  • 如果以下答案有帮助,请告诉我。

标签: pyspark apache-hudi


【解决方案1】:

问题在于"hoodie.table.type": "MERGE_ON_READ", 配置。您必须改用hoodie.datasource.write.table.type。如果您按如下方式更新配置,它将起作用。我已经测试过了。

hudi_options = {
    "hoodie.table.name": "hudi_acct",
    "hoodie.datasource.write.table.type": "MERGE_ON_WRITE",
    "hoodie.datasource.write.operation": "upsert",
    "hoodie.datasource.write.recordkey.field": "acctid",
    "hoodie.datasource.write.precombine.field": "ts",
    "hoodie.datasource.write.partitionpath.field": "date",
    "hoodie.datasource.write.hive_style_partitioning": "true",
    "hoodie.upsert.shuffle.parallelism": 8,
    "hoodie.insert.shuffle.parallelism": 8,
    "hoodie.compact.inline": "true",
    "hoodie.compact.inline.max.delta.commits": 10
}

【讨论】:

  • MERGE_ON_WRITE - 错误
【解决方案2】:

在使用insert将数据加载到hudi时,请您先试试mode("overwrite"),看看是否有效?

【讨论】:

  • 我尝试使用覆盖模式仍然显示与 COPY ON READ 相同的结果.....这与我的输入数据大小有关吗?因为输入数据和更新数据都非常小,hudi 默认使用 COPY_ON_WRITE 吗?
  • 不,它应该与您的数据大小无关。 hoodie.properties 中的表名是否正确?
  • 是的,表名是正确的。这是在 hoodie.properties hoodie.table.precombine.field=ts hoodie.table.name=hudi_acct hoodie.archivelog.folder=archived hoodie.table.type=COPY_ON_WRITE hoodie.table.version=1 hoodie.timeline.layout.version =1
猜你喜欢
  • 2019-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-30
  • 2018-06-29
  • 2018-01-26
相关资源
最近更新 更多