linliu-code commented on code in PR #19280:
URL: https://github.com/apache/hudi/pull/19280#discussion_r3574272441
##########
hudi-common/src/main/java/org/apache/hudi/common/model/HoodieAvroRecordMerger.java:
##########
@@ -71,10 +71,12 @@ public <T> BufferedRecord<T> merge(BufferedRecord<T> older,
BufferedRecord<T> ne
if (updatedRecord == previousAvroData || updatedRecord ==
HoodieRecord.SENTINEL) {
return older;
}
- if (updatedRecord == newerAvroRecord) {
- // simply return the newer record instead of creating a new record
- return newer;
- }
+ // Do NOT short-circuit `updatedRecord == newerAvroRecord` here. A
payload may mutate the
+ // incoming avro record IN PLACE and return that same reference (e.g.
+ // PostgresDebeziumAvroPayload fills the __debezium_unavailable_value
sentinel for TOASTed
+ // columns from the base value). Returning the original engine-backed
`newer` in that case
+ // would drop the mutation, because `newerAvroRecord` is a separate
avro conversion of
+ // `newer.getRecord()`. Always rebuild from `updatedRecord` so an
in-place mutation survives.
// Construct a new BufferedRecord with updated value
T resultRecord = recordContext.convertAvroRecord(updatedRecord);
return BufferedRecords.fromEngineRecord(resultRecord, updatedValue
Review Comment:
Good catch — this was exactly the concern that made me move off the
merger-side fix. The merger is now reverted to upstream: the `updatedRecord ==
newerAvroRecord` short-circuit is restored, so `return newer` still fires for
every normal merge and `newer`'s HoodieOperation is preserved. The fix now
lives entirely in `PostgresDebeziumAvroPayload`, which returns a *distinct*
record only when it actually fills a toasted column — so only that case falls
through to rebuild, and the operation-carrying short-circuit is untouched for
everything else.
##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/functional/TestDebeziumToastedValue.scala:
##########
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hudi.functional
+
+import org.apache.hudi.DataSourceWriteOptions
+import org.apache.hudi.DataSourceWriteOptions.{OPERATION, ORDERING_FIELDS,
RECORDKEY_FIELD, TABLE_TYPE}
+import org.apache.hudi.common.config.HoodieMetadataConfig
+import org.apache.hudi.common.model.HoodieTableType
+import org.apache.hudi.common.model.debezium.{DebeziumConstants,
PostgresDebeziumAvroPayload}
+import org.apache.hudi.common.table.HoodieTableMetaClient
+import org.apache.hudi.config.{HoodieCompactionConfig, HoodieWriteConfig}
+import org.apache.hudi.testutils.SparkClientFunctionalTestHarness
+
+import org.apache.spark.sql.SaveMode
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.params.ParameterizedTest
+import org.junit.jupiter.params.provider.ValueSource
+
+/**
+ * Functional test for [[PostgresDebeziumAvroPayload]]'s toasted /
unavailable-value handling on a
+ * Merge-on-Read table.
+ *
+ * Postgres TOAST semantics: when a Debezium UPDATE cannot capture a large
STRING/BYTES column that
+ * did not change, it ships the sentinel
[[PostgresDebeziumAvroPayload.DEBEZIUM_TOASTED_VALUE]]
+ * (`__debezium_unavailable_value`) for that column. When the base file and
delta log are merged at
+ * read time, such columns must KEEP the prior (base) value rather than be
overwritten with the
+ * sentinel.
+ *
+ * Covers table versions 6, 8 and 9.
+ */
+class TestDebeziumToastedValue extends SparkClientFunctionalTestHarness {
+
+ private val sentinel = PostgresDebeziumAvroPayload.DEBEZIUM_TOASTED_VALUE
+ private val columns = Seq(
+ "id",
+ "name",
+ "city",
+ DebeziumConstants.FLATTENED_OP_COL_NAME,
+ DebeziumConstants.FLATTENED_LSN_COL_NAME)
+
+ @ParameterizedTest
+ @ValueSource(strings = Array("6", "8", "9"))
+ def testToastedColumnKeepsPriorValueOnRead(tableVersion: String): Unit = {
+ val opts = Map(
+ HoodieWriteConfig.WRITE_PAYLOAD_CLASS_NAME.key() ->
classOf[PostgresDebeziumAvroPayload].getName,
+ HoodieMetadataConfig.ENABLE.key() -> "false",
+ // Preserve the table version across writes: disable auto-upgrade and
pin the write version so
+ // a later write cannot migrate the table to a newer version mid-test.
+ HoodieWriteConfig.AUTO_UPGRADE_VERSION.key() -> "false",
+ HoodieWriteConfig.WRITE_TABLE_VERSION.key() -> tableVersion)
+
+ // 1. Base records at LSN 10.
+ val base = Seq(
+ (1, "alice", "NYC", "c", 10L),
+ (2, "bob", "LA", "c", 10L))
+ spark.createDataFrame(base).toDF(columns: _*).write.format("hudi")
+ .option(RECORDKEY_FIELD.key(), "id")
+ .option(ORDERING_FIELDS.key(), DebeziumConstants.FLATTENED_LSN_COL_NAME)
+ .option(TABLE_TYPE.key(), HoodieTableType.MERGE_ON_READ.name())
+ .option(DataSourceWriteOptions.TABLE_NAME.key(), "toasted_table")
+ .option(OPERATION.key(),
DataSourceWriteOptions.BULK_INSERT_OPERATION_OPT_VAL)
+ .option(HoodieCompactionConfig.INLINE_COMPACT.key(), "false")
+ .option(HoodieWriteConfig.WRITE_TABLE_VERSION.key(), tableVersion)
Review Comment:
Done — dropped the redundant `.option(WRITE_TABLE_VERSION, ...)`; it is
already in `opts`.
##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/functional/TestDebeziumToastedValue.scala:
##########
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hudi.functional
+
+import org.apache.hudi.DataSourceWriteOptions
+import org.apache.hudi.DataSourceWriteOptions.{OPERATION, ORDERING_FIELDS,
RECORDKEY_FIELD, TABLE_TYPE}
+import org.apache.hudi.common.config.HoodieMetadataConfig
+import org.apache.hudi.common.model.HoodieTableType
+import org.apache.hudi.common.model.debezium.{DebeziumConstants,
PostgresDebeziumAvroPayload}
+import org.apache.hudi.common.table.HoodieTableMetaClient
+import org.apache.hudi.config.{HoodieCompactionConfig, HoodieWriteConfig}
+import org.apache.hudi.testutils.SparkClientFunctionalTestHarness
+
+import org.apache.spark.sql.SaveMode
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.params.ParameterizedTest
+import org.junit.jupiter.params.provider.ValueSource
+
+/**
+ * Functional test for [[PostgresDebeziumAvroPayload]]'s toasted /
unavailable-value handling on a
+ * Merge-on-Read table.
+ *
+ * Postgres TOAST semantics: when a Debezium UPDATE cannot capture a large
STRING/BYTES column that
+ * did not change, it ships the sentinel
[[PostgresDebeziumAvroPayload.DEBEZIUM_TOASTED_VALUE]]
+ * (`__debezium_unavailable_value`) for that column. When the base file and
delta log are merged at
+ * read time, such columns must KEEP the prior (base) value rather than be
overwritten with the
+ * sentinel.
+ *
+ * Covers table versions 6, 8 and 9.
+ */
+class TestDebeziumToastedValue extends SparkClientFunctionalTestHarness {
+
+ private val sentinel = PostgresDebeziumAvroPayload.DEBEZIUM_TOASTED_VALUE
+ private val columns = Seq(
+ "id",
+ "name",
+ "city",
+ DebeziumConstants.FLATTENED_OP_COL_NAME,
+ DebeziumConstants.FLATTENED_LSN_COL_NAME)
+
+ @ParameterizedTest
+ @ValueSource(strings = Array("6", "8", "9"))
+ def testToastedColumnKeepsPriorValueOnRead(tableVersion: String): Unit = {
+ val opts = Map(
+ HoodieWriteConfig.WRITE_PAYLOAD_CLASS_NAME.key() ->
classOf[PostgresDebeziumAvroPayload].getName,
+ HoodieMetadataConfig.ENABLE.key() -> "false",
+ // Preserve the table version across writes: disable auto-upgrade and
pin the write version so
+ // a later write cannot migrate the table to a newer version mid-test.
+ HoodieWriteConfig.AUTO_UPGRADE_VERSION.key() -> "false",
+ HoodieWriteConfig.WRITE_TABLE_VERSION.key() -> tableVersion)
+
+ // 1. Base records at LSN 10.
+ val base = Seq(
+ (1, "alice", "NYC", "c", 10L),
+ (2, "bob", "LA", "c", 10L))
+ spark.createDataFrame(base).toDF(columns: _*).write.format("hudi")
+ .option(RECORDKEY_FIELD.key(), "id")
+ .option(ORDERING_FIELDS.key(), DebeziumConstants.FLATTENED_LSN_COL_NAME)
+ .option(TABLE_TYPE.key(), HoodieTableType.MERGE_ON_READ.name())
+ .option(DataSourceWriteOptions.TABLE_NAME.key(), "toasted_table")
+ .option(OPERATION.key(),
DataSourceWriteOptions.BULK_INSERT_OPERATION_OPT_VAL)
+ .option(HoodieCompactionConfig.INLINE_COMPACT.key(), "false")
+ .option(HoodieWriteConfig.WRITE_TABLE_VERSION.key(), tableVersion)
+ .options(opts)
+ .mode(SaveMode.Overwrite)
+ .save(basePath)
+
+ // 2. Newer log records at LSN 20, each carrying the toasted sentinel in
one column:
+ // id=1 -> name updated, `city` toasted (must keep base "NYC")
+ // id=2 -> name toasted (must keep base "bob"), `city` updated
+ val update = Seq(
+ (1, "alice2", sentinel, "u", 20L),
+ (2, sentinel, "SF", "u", 20L))
+ spark.createDataFrame(update).toDF(columns: _*).write.format("hudi")
+ .option(OPERATION.key(), "upsert")
Review Comment:
Done — the update write now uses
`DataSourceWriteOptions.UPSERT_OPERATION_OPT_VAL` instead of the bare string.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]