Re: [PR] fix(spark): set the ordering value whenever the table's merge mode needs one [hudi]
linliu-code closed pull request #19908: fix(spark): set the ordering value whenever the table's merge mode needs one URL: https://github.com/apache/hudi/pull/19908 -- 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]
Re: [PR] fix(spark): set the ordering value whenever the table's merge mode needs one [hudi]
linliu-code commented on PR #19908: URL: https://github.com/apache/hudi/pull/19908#issuecomment-5718752472 Closing this for now. On current master the condition this PR changes is not reachable with the default configuration: hoodie.write.merge.handle.class defaults to FileGroupReaderBasedMergeHandle, so requiresPayload is false and records already take the payload free path, where the ordering value is derived from the record data. The gap only opens when that config points at a merge handle that is not FileGroupReaderBasedMergeHandle, for example HoodieWriteMergeHandle, HoodieSortedMergeHandle or HoodieMergeHandleWithChangeLog. In that case a prepped Spark SQL write (UPDATE or DELETE, where shouldCombine is false) builds the payload through its single argument constructor and the record serves OrderingValues.getDefault(), an Integer, instead of the ordering field value. Comparing that against a long ordering column throws ClassCastException at merge time. Two notes for anyone picking this up later: 1. Removing the requiresPayload gate entirely is an alternative fix, but it only helps payload classes listed in HoodieRecordUtils.DEPRECATED_PAYLOADS, since isPayloadClassDeprecated is an exact set membership test on the class name and is not subclass aware. Any other payload class, including subclasses of the listed ones, keeps the old behaviour. 2. MERGE INTO is not affected, because MergeIntoHoodieTableCommand sets COMBINE_BEFORE_UPSERT from whether ordering fields are configured, which forces the ordering value to be computed. The HoodieStreamer ingestion path carries the same shouldCombine conflation in HoodieStreamerUtils and is not touched by this PR; op UPSERT is safe there because shouldCombine is forced true, while op DELETE and UPSERT_PREPPED are not. -- 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]
Re: [PR] fix(spark): set the ordering value whenever the table's merge mode needs one [hudi]
hudi-bot commented on PR #19908: URL: https://github.com/apache/hudi/pull/19908#issuecomment-5672930713 ## CI report: * 4638552c9f5358e8db8fce9e6f894a3d28c6af49 Azure: [SUCCESS](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17099) Bot commands @hudi-bot supports the following commands: - `@hudi-bot run azure` re-run the last Azure build -- 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]
Re: [PR] fix(spark): set the ordering value whenever the table's merge mode needs one [hudi]
hudi-bot commented on PR #19908: URL: https://github.com/apache/hudi/pull/19908#issuecomment-5671974109 ## CI report: * dc8ce261ead7dfadca661cf46f953f6d4db00fef Azure: [SUCCESS](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17064) * 4638552c9f5358e8db8fce9e6f894a3d28c6af49 Azure: [PENDING](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17099) Bot commands @hudi-bot supports the following commands: - `@hudi-bot run azure` re-run the last Azure build -- 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]
Re: [PR] fix(spark): set the ordering value whenever the table's merge mode needs one [hudi]
linliu-code commented on code in PR #19908:
URL: https://github.com/apache/hudi/pull/19908#discussion_r4010332392
##
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/TestHoodieCreateRecordUtils.scala:
##
@@ -259,6 +275,159 @@ class TestHoodieCreateRecordUtils {
.load(TestHoodieCreateRecordUtils.tempDir +
"/test_null_precombine_commit_time")
assertTrue(result.count() > 0, "Data should have been written successfully
with null precombine using COMMIT_TIME_ORDERING")
}
+ @Test
+ def testOrderingValueIsSetWhenCombineBeforeUpsertIsOff(): Unit = {
+val orderingValue =
buildRecordOrderingValue(RecordMergeMode.EVENT_TIME_ORDERING, isDelete = false)
+assertInstanceOf(classOf[java.lang.Long], orderingValue,
+ "the record must carry the ordering field's value, not the payload's
Integer default")
+assertEquals(TS, orderingValue)
+ }
+
+ /** Commit time ordered tables must keep serving the default, whatever the
ordering fields say. */
+ @Test
+ def testCommitTimeOrderingKeepsTheDefaultOrderingValue(): Unit = {
+assertEquals(OrderingValues.getDefault(),
+ buildRecordOrderingValue(RecordMergeMode.COMMIT_TIME_ORDERING, isDelete
= false))
+ }
+
+ /**
+ * Deletes carry the ordering field's value as well. A delete left on the
default is treated as
+ * commit time ordered by
BufferedRecordMergerFactory#deltaMergeDeleteRecord, which would let a
+ * stale delete remove a record with a higher ordering value.
+ */
+ @Test
+ def testDeleteAlsoGetsTheOrderingValue(): Unit = {
+val orderingValue =
buildRecordOrderingValue(RecordMergeMode.EVENT_TIME_ORDERING, isDelete = true)
+assertInstanceOf(classOf[java.lang.Long], orderingValue,
+ "the delete must carry the ordering field's value, not the payload's
Integer default")
+assertEquals(TS, orderingValue)
+ }
+
+ /** Commit time ordered tables keep serving the default for deletes too. */
+ @Test
+ def testCommitTimeOrderingDeleteKeepsTheDefaultOrderingValue(): Unit = {
+assertEquals(OrderingValues.getDefault(),
+ buildRecordOrderingValue(RecordMergeMode.COMMIT_TIME_ORDERING, isDelete
= true))
+ }
+
+ /**
+ * A delete row may carry only its key, with the ordering field left null.
Such a row must fall
+ * back to the default ordering value rather than failing the write. Every
other record
+ * representation already tolerates this:
HoodieSparkRecord#doGetOrderingValue,
+ * HoodieFlinkRecord#doGetOrderingValue and
HoodieAvroIndexedRecord#doGetOrderingValue.
+ */
+ @Test
+ def testDeleteWithNullOrderingFieldKeepsTheDefault(): Unit = {
+assertEquals(OrderingValues.getDefault(),
+ buildRecordOrderingValue(RecordMergeMode.EVENT_TIME_ORDERING, isDelete =
true, ts = null))
+ }
+
+ /**
+ * End to end on the path this change widens. With de-duplication off, a
delete whose ordering
+ * value is older than the stored record must lose. While deletes were left
on the default the
+ * delete was treated as commit time ordered and removed the row regardless
of its ordering value.
+ */
+ @Test
+ def testStaleDeleteLosesWhenCombineBeforeUpsertIsOff(): Unit = {
+val spark = TestHoodieCreateRecordUtils.spark
+val basePath = TestHoodieCreateRecordUtils.tempDir +
"/stale_delete_no_combine"
+val opts = Map(
+ "hoodie.insert.shuffle.parallelism" -> "1",
+ "hoodie.upsert.shuffle.parallelism" -> "1",
+ DataSourceWriteOptions.TABLE_TYPE.key ->
DataSourceWriteOptions.COW_TABLE_TYPE_OPT_VAL,
+ DataSourceWriteOptions.RECORDKEY_FIELD.key -> "uuid",
+ DataSourceWriteOptions.PARTITIONPATH_FIELD.key -> "partition",
+ HoodieTableConfig.ORDERING_FIELDS.key -> "ts",
+ HoodieTableConfig.RECORD_MERGE_MODE.key ->
RecordMergeMode.EVENT_TIME_ORDERING.name,
+ HoodieTableConfig.PAYLOAD_CLASS_NAME.key ->
classOf[DefaultHoodieRecordPayload].getName,
+ HoodieWriteConfig.TBL_NAME.key -> "test_stale_delete_no_combine",
+ // The trigger: no de-duplication of the incoming batch.
+ HoodieWriteConfig.COMBINE_BEFORE_UPSERT.key -> "false",
+ // Route the record through HoodieAvroRecord, whose payload defaults the
ordering value when
+ // none is set, rather than HoodieAvroIndexedRecord which derives it
lazily from the row.
+ HoodieWriteConfig.RECORD_MERGE_IMPL_CLASSES.key ->
classOf[HoodieAvroRecordMerger].getName,
+ HoodieWriteConfig.MERGE_HANDLE_CLASS_NAME.key ->
classOf[HoodieWriteMergeHandle[_, _, _, _]].getName)
+
+def write(row: Row, mode: SaveMode): Unit =
+ spark.createDataFrame(spark.sparkContext.parallelize(Seq(row)),
ORDERING_TEST_SCHEMA)
+.write.format("hudi").options(opts).mode(mode).save(basePath)
+
+write(Row("id1", TS, "par1", false), SaveMode.Overwrite)
+// A delete one tick older than the stored record.
+write(Row("id1", TS - 1, "par1", true), SaveMode.Append)
+
+assertEquals(1L,
Re: [PR] fix(spark): set the ordering value whenever the table's merge mode needs one [hudi]
hudi-bot commented on PR #19908: URL: https://github.com/apache/hudi/pull/19908#issuecomment-5671921498 ## CI report: * dc8ce261ead7dfadca661cf46f953f6d4db00fef Azure: [SUCCESS](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17064) * 4638552c9f5358e8db8fce9e6f894a3d28c6af49 UNKNOWN Bot commands @hudi-bot supports the following commands: - `@hudi-bot run azure` re-run the last Azure build -- 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]
Re: [PR] fix(spark): set the ordering value whenever the table's merge mode needs one [hudi]
hudi-agent commented on code in PR #19908:
URL: https://github.com/apache/hudi/pull/19908#discussion_r4010299729
##
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/HoodieCreateRecordUtils.scala:
##
@@ -155,9 +155,20 @@ object HoodieCreateRecordUtils {
} else {
avroRecWithoutMeta
}
-val hoodieRecord = if (shouldCombine && !orderingFields.isEmpty) {
+// `shouldCombine` says whether the incoming batch needs
de-duplicating, which is not the
+// same question as whether this record needs an ordering value.
Prepped Spark SQL writes
+// emit one row per key and so set it false, which used to leave
the record with no
+// ordering value on tables that order by event time.
+// Deletes take the ordering value too. A delete left on the
default is treated as commit
+// time ordered by
BufferedRecordMergerFactory#shouldKeepNewerRecord, so excluding them
+// here would let a stale delete remove a record with a higher
ordering value, while the
+// same delete written through a path where `shouldCombine` is
true would correctly lose.
+// A null ordering field stays tolerated for a delete, which may
carry only its key: the
+// value falls back to the default rather than failing the write.
+val shouldComputeOrderingValue = shouldCombine ||
requiresOrderingValue
+val hoodieRecord = if (shouldComputeOrderingValue &&
!orderingFields.isEmpty) {
val orderingVal = getOrderingValue(orderingFields, avroRec,
hoodieKey.getRecordKey,
-consistentLogicalTimestampEnabled, requiresOrderingValue)
+consistentLogicalTimestampEnabled, requiresOrderingValue &&
!isDelete)
Review Comment:
🤖 nit: `requiresOrderingValue && !isDelete` as a bare positional boolean is
hard to read at the call site — could you bind it to a named val (e.g.
`failOnNullOrderingValue`) or use a named argument so the "deletes may have a
null ordering field" intent is visible without reading the comment block above?
⚠️ AI-generated; verify before applying. React 👍/👎 to flag
quality.
--
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]
Re: [PR] fix(spark): set the ordering value whenever the table's merge mode needs one [hudi]
linliu-code commented on code in PR #19908:
URL: https://github.com/apache/hudi/pull/19908#discussion_r4007918544
##
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/HoodieCreateRecordUtils.scala:
##
@@ -155,7 +155,17 @@ object HoodieCreateRecordUtils {
} else {
avroRecWithoutMeta
}
-val hoodieRecord = if (shouldCombine && !orderingFields.isEmpty) {
+// `shouldCombine` says whether the incoming batch needs
de-duplicating, which is not the
+// same question as whether this record needs an ordering value.
Prepped Spark SQL writes
+// emit one row per key and so set it false, which used to leave
the record with no
+// ordering value on tables that order by event time.
+// Deletes are excluded from the widened branch so their semantics
do not change: a
+// delete carrying the default ordering value is treated as commit
time ordered by
+// BufferedRecordMergerFactory#deltaMergeDeleteRecord, and giving
it a real value would
+// make a delete lose to a stored record with a higher ordering
value. Deletes still get
+// an ordering value when `shouldCombine` is true, exactly as
before.
+val computeOrderingValue = shouldCombine || (requiresOrderingValue
&& !isDelete)
Review Comment:
Good catch, and yes it is intended. Added to Impact: a non-delete row with a
null value in the ordering column now fails the write with
`IllegalArgumentException: Ordering field '' has null value`, where such
rows previously passed through carrying the default.
Worth noting it is not a new rule so much as an alignment:
`getOrderingValue` already threw that for `requiresOrderingValue` writes, and
the `shouldCombine` path already reached it. This change makes the prepped and
non-prepped paths agree. Deletes are exempt, since a delete may carry only its
key.
##
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/HoodieCreateRecordUtils.scala:
##
@@ -155,7 +155,17 @@ object HoodieCreateRecordUtils {
} else {
avroRecWithoutMeta
}
-val hoodieRecord = if (shouldCombine && !orderingFields.isEmpty) {
+// `shouldCombine` says whether the incoming batch needs
de-duplicating, which is not the
+// same question as whether this record needs an ordering value.
Prepped Spark SQL writes
+// emit one row per key and so set it false, which used to leave
the record with no
+// ordering value on tables that order by event time.
+// Deletes are excluded from the widened branch so their semantics
do not change: a
+// delete carrying the default ordering value is treated as commit
time ordered by
+// BufferedRecordMergerFactory#deltaMergeDeleteRecord, and giving
it a real value would
+// make a delete lose to a stored record with a higher ordering
value. Deletes still get
Review Comment:
Done — it reads `shouldComputeOrderingValue` now.
##
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/HoodieCreateRecordUtils.scala:
##
@@ -155,9 +155,20 @@ object HoodieCreateRecordUtils {
} else {
avroRecWithoutMeta
}
-val hoodieRecord = if (shouldCombine && !orderingFields.isEmpty) {
+// `shouldCombine` says whether the incoming batch needs
de-duplicating, which is not the
+// same question as whether this record needs an ordering value.
Prepped Spark SQL writes
+// emit one row per key and so set it false, which used to leave
the record with no
+// ordering value on tables that order by event time.
+// Deletes take the ordering value too. A delete left on the
default is treated as commit
+// time ordered by
BufferedRecordMergerFactory#shouldKeepNewerRecord, so excluding them
+// here would let a stale delete remove a record with a higher
ordering value, while the
+// same delete written through a path where `shouldCombine` is
true would correctly lose.
+// A null ordering field stays tolerated for a delete, which may
carry only its key: the
+// value falls back to the default rather than failing the write.
+val computeOrderingValue = shouldCombine || requiresOrderingValue
+val hoodieRecord = if (computeOrderingValue &&
!orderingFields.isEmpty) {
val orderingVal = getOrderingValue(orderingFields, avroRec,
hoodieKey.getRecordKey,
-consistentLogicalTimestampEnabled, requiresOrderingValue)
+consistentLogicalTimestampEnabled, requiresOrderingValue &&
!isDelete)
Review Comment:
Description updated. The code and the body now agree: deletes take the
Re: [PR] fix(spark): set the ordering value whenever the table's merge mode needs one [hudi]
linliu-code commented on code in PR #19908:
URL: https://github.com/apache/hudi/pull/19908#discussion_r4007881456
##
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/HoodieCreateRecordUtils.scala:
##
@@ -155,9 +155,20 @@ object HoodieCreateRecordUtils {
} else {
avroRecWithoutMeta
}
-val hoodieRecord = if (shouldCombine && !orderingFields.isEmpty) {
+// `shouldCombine` says whether the incoming batch needs
de-duplicating, which is not the
+// same question as whether this record needs an ordering value.
Prepped Spark SQL writes
Review Comment:
Thanks — I checked this, and I don't think the MDT framing holds for this
particular flag.
`_hoodie.spark.sql.writes.prepped` (`SPARK_SQL_WRITES_PREPPED_KEY`) is set
in exactly four places on master, all of them user-facing SQL DML on ordinary
tables:
```
hudi-spark3-common/.../UpdateHoodieTableCommand.scala:60
hudi-spark3-common/.../DeleteHoodieTableCommand.scala:76
hudi-spark4-common/.../UpdateHoodieTableCommand.scala:61
hudi-spark4-common/.../DeleteHoodieTableCommand.scala:81
```
Nothing under `metadata/` sets or reads it, and the only other files that
mention it are the plumbing (`DataSourceOptions`, `HoodieSparkSqlWriter`,
`HoodieWriterUtils`). So `shouldCombine` being false here is not an MDT-only
situation: it is every `UPDATE` and every `DELETE` issued through Spark SQL
against a normal Hudi table.
That matches how this was found. The failure was a plain `UPDATE` on a
copy-on-write user table with a `bigint` precombine field and event-time
ordering, and it threw on every merged row:
```
java.lang.ClassCastException: class java.lang.Long cannot be cast to class
java.lang.Integer
at java.lang.Integer.compareTo(Integer.java:71)
at
BufferedRecordMergerFactory.shouldKeepNewerRecord(BufferedRecordMergerFactory.java:515)
at BufferedRecordMergerFactory$EventTimeRecordMerger.finalMerge(...)
at FileGroupRecordBuffer.hasNextBaseRecord(...)
at FileGroupReaderBasedMergeHandle.doMerge(...)
```
You are right that a separate prepped mechanism exists for the metadata
table, and that MDT does not do event-time merging — but that is
`UPSERT_PREPPED` / `preppedWriteOperation`, which is a different path from this
config key, and this change does not affect it.
One caveat on reachability worth stating plainly: the record only takes the
`HoodieAvroRecord` branch (and so serves the payload's `Integer` default) when
`requiresPayload` is true, which needs a merge handle that is not a
`FileGroupReaderBasedMergeHandle` subclass. On stock master with the default
handle, the same branch yields a `HoodieAvroIndexedRecord`, which derives the
ordering value from the record and is unaffected. So the loud failure needs a
non-default merge handle, while the underlying gate — a de-duplication flag
deciding whether a record gets its ordering value — is wrong independently of
that.
--
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]
Re: [PR] fix(spark): set the ordering value whenever the table's merge mode needs one [hudi]
danny0405 commented on code in PR #19908:
URL: https://github.com/apache/hudi/pull/19908#discussion_r4002010883
##
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/HoodieCreateRecordUtils.scala:
##
@@ -155,9 +155,20 @@ object HoodieCreateRecordUtils {
} else {
avroRecWithoutMeta
}
-val hoodieRecord = if (shouldCombine && !orderingFields.isEmpty) {
+// `shouldCombine` says whether the incoming batch needs
de-duplicating, which is not the
+// same question as whether this record needs an ordering value.
Prepped Spark SQL writes
Review Comment:
Prepped Spark SQL is used for MDT upsert, currently MDT does not even
support event time merging so it should be fine?
--
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]
Re: [PR] fix(spark): set the ordering value whenever the table's merge mode needs one [hudi]
linliu-code commented on code in PR #19908:
URL: https://github.com/apache/hudi/pull/19908#discussion_r3999876775
##
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/TestHoodieCreateRecordUtils.scala:
##
@@ -259,6 +275,159 @@ class TestHoodieCreateRecordUtils {
.load(TestHoodieCreateRecordUtils.tempDir +
"/test_null_precombine_commit_time")
assertTrue(result.count() > 0, "Data should have been written successfully
with null precombine using COMMIT_TIME_ORDERING")
}
+ @Test
+ def testOrderingValueIsSetWhenCombineBeforeUpsertIsOff(): Unit = {
+val orderingValue =
buildRecordOrderingValue(RecordMergeMode.EVENT_TIME_ORDERING, isDelete = false)
+assertInstanceOf(classOf[java.lang.Long], orderingValue,
+ "the record must carry the ordering field's value, not the payload's
Integer default")
+assertEquals(TS, orderingValue)
+ }
+
+ /** Commit time ordered tables must keep serving the default, whatever the
ordering fields say. */
+ @Test
+ def testCommitTimeOrderingKeepsTheDefaultOrderingValue(): Unit = {
+assertEquals(OrderingValues.getDefault(),
+ buildRecordOrderingValue(RecordMergeMode.COMMIT_TIME_ORDERING, isDelete
= false))
+ }
+
+ /**
+ * Deletes carry the ordering field's value as well. A delete left on the
default is treated as
+ * commit time ordered by
BufferedRecordMergerFactory#deltaMergeDeleteRecord, which would let a
+ * stale delete remove a record with a higher ordering value.
+ */
+ @Test
+ def testDeleteAlsoGetsTheOrderingValue(): Unit = {
+val orderingValue =
buildRecordOrderingValue(RecordMergeMode.EVENT_TIME_ORDERING, isDelete = true)
+assertInstanceOf(classOf[java.lang.Long], orderingValue,
+ "the delete must carry the ordering field's value, not the payload's
Integer default")
+assertEquals(TS, orderingValue)
+ }
+
+ /** Commit time ordered tables keep serving the default for deletes too. */
+ @Test
+ def testCommitTimeOrderingDeleteKeepsTheDefaultOrderingValue(): Unit = {
+assertEquals(OrderingValues.getDefault(),
+ buildRecordOrderingValue(RecordMergeMode.COMMIT_TIME_ORDERING, isDelete
= true))
+ }
+
+ /**
+ * A delete row may carry only its key, with the ordering field left null.
Such a row must fall
+ * back to the default ordering value rather than failing the write. Every
other record
+ * representation already tolerates this:
HoodieSparkRecord#doGetOrderingValue,
+ * HoodieFlinkRecord#doGetOrderingValue and
HoodieAvroIndexedRecord#doGetOrderingValue.
+ */
+ @Test
+ def testDeleteWithNullOrderingFieldKeepsTheDefault(): Unit = {
+assertEquals(OrderingValues.getDefault(),
+ buildRecordOrderingValue(RecordMergeMode.EVENT_TIME_ORDERING, isDelete =
true, ts = null))
+ }
+
+ /**
+ * End to end on the path this change widens. With de-duplication off, a
delete whose ordering
+ * value is older than the stored record must lose. While deletes were left
on the default the
+ * delete was treated as commit time ordered and removed the row regardless
of its ordering value.
+ */
+ @Test
+ def testStaleDeleteLosesWhenCombineBeforeUpsertIsOff(): Unit = {
+val spark = TestHoodieCreateRecordUtils.spark
+val basePath = TestHoodieCreateRecordUtils.tempDir +
"/stale_delete_no_combine"
+val opts = Map(
+ "hoodie.insert.shuffle.parallelism" -> "1",
+ "hoodie.upsert.shuffle.parallelism" -> "1",
+ DataSourceWriteOptions.TABLE_TYPE.key ->
DataSourceWriteOptions.COW_TABLE_TYPE_OPT_VAL,
+ DataSourceWriteOptions.RECORDKEY_FIELD.key -> "uuid",
+ DataSourceWriteOptions.PARTITIONPATH_FIELD.key -> "partition",
+ HoodieTableConfig.ORDERING_FIELDS.key -> "ts",
+ HoodieTableConfig.RECORD_MERGE_MODE.key ->
RecordMergeMode.EVENT_TIME_ORDERING.name,
+ HoodieTableConfig.PAYLOAD_CLASS_NAME.key ->
classOf[DefaultHoodieRecordPayload].getName,
+ HoodieWriteConfig.TBL_NAME.key -> "test_stale_delete_no_combine",
+ // The trigger: no de-duplication of the incoming batch.
+ HoodieWriteConfig.COMBINE_BEFORE_UPSERT.key -> "false",
+ // Route the record through HoodieAvroRecord, whose payload defaults the
ordering value when
+ // none is set, rather than HoodieAvroIndexedRecord which derives it
lazily from the row.
+ HoodieWriteConfig.RECORD_MERGE_IMPL_CLASSES.key ->
classOf[HoodieAvroRecordMerger].getName,
+ HoodieWriteConfig.MERGE_HANDLE_CLASS_NAME.key ->
classOf[HoodieWriteMergeHandle[_, _, _, _]].getName)
+
+def write(row: Row, mode: SaveMode): Unit =
+ spark.createDataFrame(spark.sparkContext.parallelize(Seq(row)),
ORDERING_TEST_SCHEMA)
+.write.format("hudi").options(opts).mode(mode).save(basePath)
+
+write(Row("id1", TS, "par1", false), SaveMode.Overwrite)
+// A delete one tick older than the stored record.
+write(Row("id1", TS - 1, "par1", true), SaveMode.Append)
+
+assertEquals(1L,
Re: [PR] fix(spark): set the ordering value whenever the table's merge mode needs one [hudi]
hudi-bot commented on PR #19908: URL: https://github.com/apache/hudi/pull/19908#issuecomment-5651365673 ## CI report: * dc8ce261ead7dfadca661cf46f953f6d4db00fef Azure: [SUCCESS](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17064) Bot commands @hudi-bot supports the following commands: - `@hudi-bot run azure` re-run the last Azure build -- 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]
Re: [PR] fix(spark): set the ordering value whenever the table's merge mode needs one [hudi]
linliu-code commented on PR #19908:
URL: https://github.com/apache/hudi/pull/19908#issuecomment-5650999365
One thing I would like a second opinion on, since this change makes it
reachable.
`BufferedRecordMergerFactory.shouldKeepNewerRecord` short-circuits when
either side is a commit time ordered delete, and its own comment gives the
reason: the default ordering value is a constant `0` (an `Integer`) and is "not
guaranteed to match the type of the old or new record's ordering value". Past
that early return it does a bare `compareTo`:
```java
private static boolean shouldKeepNewerRecord(BufferedRecord
oldRecord, BufferedRecord newRecord) {
if (newRecord.isCommitTimeOrderingDelete() ||
oldRecord.isCommitTimeOrderingDelete()) {
return true;
}
return
newRecord.getOrderingValue().compareTo(oldRecord.getOrderingValue()) >= 0;
}
```
The sibling `deltaMergeDeleteRecord` guards the same comparison with
`OrderingValues.isSameClass` before calling `compareTo`.
`shouldKeepNewerRecord` does not.
Before this change, every delete on the widened path carried the default and
took the early return, so it never reached that line. Now those deletes carry a
real ordering value and fall through to it. The case I could not rule out is an
ordering column written as `int` in an older base file and later evolved to
`long`: the stored value is an `Integer`, the incoming delete's is a `Long`,
and `Long.compareTo(Integer)` would throw.
I could not build a repro. On the payload path both sides come from the same
field through the same accessor, and `HoodieMergeHelper` composes a schema
evolution transformer for the base file reader, either of which may close it.
The missing guard is pre-existing and not introduced here; what changed is that
deletes can now reach it. Does anyone know whether schema evolution can produce
mismatched ordering value classes on that path, or is it already closed?
--
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]
Re: [PR] fix(spark): set the ordering value whenever the table's merge mode needs one [hudi]
hudi-agent commented on code in PR #19908:
URL: https://github.com/apache/hudi/pull/19908#discussion_r3998624175
##
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/HoodieCreateRecordUtils.scala:
##
@@ -155,9 +155,20 @@ object HoodieCreateRecordUtils {
} else {
avroRecWithoutMeta
}
-val hoodieRecord = if (shouldCombine && !orderingFields.isEmpty) {
+// `shouldCombine` says whether the incoming batch needs
de-duplicating, which is not the
+// same question as whether this record needs an ordering value.
Prepped Spark SQL writes
+// emit one row per key and so set it false, which used to leave
the record with no
+// ordering value on tables that order by event time.
+// Deletes take the ordering value too. A delete left on the
default is treated as commit
+// time ordered by
BufferedRecordMergerFactory#shouldKeepNewerRecord, so excluding them
Review Comment:
🤖 nit: this comment points at
`BufferedRecordMergerFactory#shouldKeepNewerRecord` while the test javadoc
(line 295 of the test) points at `#deltaMergeDeleteRecord` for the same
behaviour — could you make both reference the same method so a reader chasing
the default-means-commit-time rule lands in one place?
⚠️ AI-generated; verify before applying. React 👍/👎 to flag
quality.
##
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/HoodieCreateRecordUtils.scala:
##
@@ -155,9 +155,20 @@ object HoodieCreateRecordUtils {
} else {
avroRecWithoutMeta
}
-val hoodieRecord = if (shouldCombine && !orderingFields.isEmpty) {
+// `shouldCombine` says whether the incoming batch needs
de-duplicating, which is not the
+// same question as whether this record needs an ordering value.
Prepped Spark SQL writes
+// emit one row per key and so set it false, which used to leave
the record with no
+// ordering value on tables that order by event time.
+// Deletes take the ordering value too. A delete left on the
default is treated as commit
+// time ordered by
BufferedRecordMergerFactory#shouldKeepNewerRecord, so excluding them
+// here would let a stale delete remove a record with a higher
ordering value, while the
+// same delete written through a path where `shouldCombine` is
true would correctly lose.
+// A null ordering field stays tolerated for a delete, which may
carry only its key: the
+// value falls back to the default rather than failing the write.
+val computeOrderingValue = shouldCombine || requiresOrderingValue
+val hoodieRecord = if (computeOrderingValue &&
!orderingFields.isEmpty) {
val orderingVal = getOrderingValue(orderingFields, avroRec,
hoodieKey.getRecordKey,
-consistentLogicalTimestampEnabled, requiresOrderingValue)
+consistentLogicalTimestampEnabled, requiresOrderingValue &&
!isDelete)
Review Comment:
🤖 The PR description still says deletes are deliberately excluded from the
widened branch and stay commit-time ordered, but the code (and the comment
above) now gives deletes a real ordering value too. Could you update the
description so the semantics change for deletes on event-time tables is visible
to reviewers?
⚠️ AI-generated; verify before applying. React 👍/👎 to flag
quality.
--
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]
Re: [PR] fix(spark): set the ordering value whenever the table's merge mode needs one [hudi]
hudi-bot commented on PR #19908: URL: https://github.com/apache/hudi/pull/19908#issuecomment-5650855629 ## CI report: * d2961b57de48c3dd93d478d150a8efd19b11121f Azure: [SUCCESS](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17018) * dc8ce261ead7dfadca661cf46f953f6d4db00fef Azure: [PENDING](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17064) Bot commands @hudi-bot supports the following commands: - `@hudi-bot run azure` re-run the last Azure build -- 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]
Re: [PR] fix(spark): set the ordering value whenever the table's merge mode needs one [hudi]
hudi-bot commented on PR #19908: URL: https://github.com/apache/hudi/pull/19908#issuecomment-5650806639 ## CI report: * d2961b57de48c3dd93d478d150a8efd19b11121f Azure: [SUCCESS](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17018) * dc8ce261ead7dfadca661cf46f953f6d4db00fef UNKNOWN Bot commands @hudi-bot supports the following commands: - `@hudi-bot run azure` re-run the last Azure build -- 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]
Re: [PR] fix(spark): set the ordering value whenever the table's merge mode needs one [hudi]
hudi-bot commented on PR #19908: URL: https://github.com/apache/hudi/pull/19908#issuecomment-5639023614 ## CI report: * d2961b57de48c3dd93d478d150a8efd19b11121f Azure: [SUCCESS](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17018) Bot commands @hudi-bot supports the following commands: - `@hudi-bot run azure` re-run the last Azure build -- 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]
Re: [PR] fix(spark): set the ordering value whenever the table's merge mode needs one [hudi]
hudi-bot commented on PR #19908: URL: https://github.com/apache/hudi/pull/19908#issuecomment-5635931961 ## CI report: * 9f05cbb95bce0fa89b79b03157655cdd91d899c7 UNKNOWN Bot commands @hudi-bot supports the following commands: - `@hudi-bot run azure` re-run the last Azure build -- 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]
Re: [PR] fix(spark): set the ordering value whenever the table's merge mode needs one [hudi]
hudi-bot commented on PR #19908: URL: https://github.com/apache/hudi/pull/19908#issuecomment-5636012467 ## CI report: * 9f05cbb95bce0fa89b79b03157655cdd91d899c7 Azure: [PENDING](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17014) Bot commands @hudi-bot supports the following commands: - `@hudi-bot run azure` re-run the last Azure build -- 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]
Re: [PR] fix(spark): set the ordering value whenever the table's merge mode needs one [hudi]
hudi-bot commented on PR #19908: URL: https://github.com/apache/hudi/pull/19908#issuecomment-5637373314 ## CI report: * 9f05cbb95bce0fa89b79b03157655cdd91d899c7 Azure: [SUCCESS](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17014) * d2961b57de48c3dd93d478d150a8efd19b11121f UNKNOWN Bot commands @hudi-bot supports the following commands: - `@hudi-bot run azure` re-run the last Azure build -- 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]
Re: [PR] fix(spark): set the ordering value whenever the table's merge mode needs one [hudi]
hudi-bot commented on PR #19908: URL: https://github.com/apache/hudi/pull/19908#issuecomment-5637443197 ## CI report: * 9f05cbb95bce0fa89b79b03157655cdd91d899c7 Azure: [SUCCESS](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17014) * d2961b57de48c3dd93d478d150a8efd19b11121f Azure: [PENDING](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=17018) Bot commands @hudi-bot supports the following commands: - `@hudi-bot run azure` re-run the last Azure build -- 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]
Re: [PR] fix(spark): set the ordering value whenever the table's merge mode needs one [hudi]
hudi-agent commented on code in PR #19908:
URL: https://github.com/apache/hudi/pull/19908#discussion_r3991125593
##
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/HoodieCreateRecordUtils.scala:
##
@@ -155,7 +155,17 @@ object HoodieCreateRecordUtils {
} else {
avroRecWithoutMeta
}
-val hoodieRecord = if (shouldCombine && !orderingFields.isEmpty) {
+// `shouldCombine` says whether the incoming batch needs
de-duplicating, which is not the
+// same question as whether this record needs an ordering value.
Prepped Spark SQL writes
+// emit one row per key and so set it false, which used to leave
the record with no
+// ordering value on tables that order by event time.
+// Deletes are excluded from the widened branch so their semantics
do not change: a
+// delete carrying the default ordering value is treated as commit
time ordered by
+// BufferedRecordMergerFactory#deltaMergeDeleteRecord, and giving
it a real value would
+// make a delete lose to a stored record with a higher ordering
value. Deletes still get
Review Comment:
🤖 nit: since this is a boolean, `shouldComputeOrderingValue` (matching the
existing `shouldCombine` style) would read more clearly as a predicate than
`computeOrderingValue`.
⚠️ AI-generated; verify before applying. React 👍/👎 to flag
quality.
##
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/HoodieCreateRecordUtils.scala:
##
@@ -155,7 +155,17 @@ object HoodieCreateRecordUtils {
} else {
avroRecWithoutMeta
}
-val hoodieRecord = if (shouldCombine && !orderingFields.isEmpty) {
+// `shouldCombine` says whether the incoming batch needs
de-duplicating, which is not the
+// same question as whether this record needs an ordering value.
Prepped Spark SQL writes
+// emit one row per key and so set it false, which used to leave
the record with no
+// ordering value on tables that order by event time.
+// Deletes are excluded from the widened branch so their semantics
do not change: a
+// delete carrying the default ordering value is treated as commit
time ordered by
+// BufferedRecordMergerFactory#deltaMergeDeleteRecord, and giving
it a real value would
+// make a delete lose to a stored record with a higher ordering
value. Deletes still get
+// an ordering value when `shouldCombine` is true, exactly as
before.
+val computeOrderingValue = shouldCombine || (requiresOrderingValue
&& !isDelete)
Review Comment:
🤖 One side effect worth confirming is intended: `getOrderingValue` throws
`IllegalArgumentException` on a null ordering field when
`requiresOrderingValue` is true, and this branch is now reached for prepped
Spark SQL writes (UPDATE / MERGE INTO) and `combine.before.upsert=false`
upserts that previously passed such rows through with the default. So an
event-time-ordered table with nulls in the ordering column that used to accept
those writes will now fail them. That seems like the right call (and consistent
with `testNullPrecombineFieldThrowsClearError`), but could you call it out in
the PR description since it's a user-visible change beyond the
`ClassCastException` fix?
⚠️ AI-generated; verify before applying. React 👍/👎 to flag
quality.
--
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]
Re: [PR] fix(spark): set the ordering value whenever the table's merge mode needs one [hudi]
codecov-commenter commented on PR #19908: URL: https://github.com/apache/hudi/pull/19908#issuecomment-5636065851 ## [Codecov](https://app.codecov.io/gh/apache/hudi/pull/19908?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report :white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 80.19%. Comparing base ([`648996f`](https://app.codecov.io/gh/apache/hudi/commit/648996f002c3c9e24a1e2bf53f97fe03e8bc4c81?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`9f05cbb`](https://app.codecov.io/gh/apache/hudi/commit/9f05cbb95bce0fa89b79b03157655cdd91d899c7?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)). :warning: Report is 4 commits behind head on master. Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #19908 +/- ## - Coverage 80.20% 80.19% -0.02% - Complexity3466134772 +111 Files 2546 2546 Lines142452 142706 +254 Branches 1733017367 +37 + Hits 114260 114439 +179 - Misses2028120346 +65 - Partials 7911 7921 +10 ``` | [Components](https://app.codecov.io/gh/apache/hudi/pull/19908/components?src=pr&el=components&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | | |---|---|---| | [hudi-common](https://app.codecov.io/gh/apache/hudi/pull/19908/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `83.74% <ø> (-0.10%)` | :arrow_down: | | [hudi-client](https://app.codecov.io/gh/apache/hudi/pull/19908/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `83.28% <ø> (ø)` | | | [hudi-flink](https://app.codecov.io/gh/apache/hudi/pull/19908/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `85.57% <ø> (ø)` | | | [hudi-spark-datasource](https://app.codecov.io/gh/apache/hudi/pull/19908/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `73.27% <ø> (-0.01%)` | :arrow_down: | | [hudi-utilities](https://app.codecov.io/gh/apache/hudi/pull/19908/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `78.17% <ø> (ø)` | | | [hudi-cli](https://app.codecov.io/gh/apache/hudi/pull/19908/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `69.99% <ø> (ø)` | | | [hudi-hadoop](https://app.codecov.io/gh/apache/hudi/pull/19908/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `70.81% <ø> (ø)` | | | [hudi-sync](https://app.codecov.io/gh/apache/hudi/pull/19908/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `75.99% <ø> (ø)` | | | [hudi-io](https://app.codecov.io/gh/apache/hudi/pull/19908/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `81.61% <ø> (ø)` | | | [hudi-timeline-service](https://app.codecov.io/gh/apache/hudi/pull/19908/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `83.34% <ø> (ø)` | | | [hudi-cloud](https://app.codecov.io/gh/apache/hudi/pull/19908/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `80.99% <ø> (ø)` | | | [hudi-kafka-connect](https://app.codecov.io/gh/apache/hudi/pull/19908/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `53.20% <ø> (ø)` | | | [Flag](https://app.codecov.io/gh/apache/hudi/pull/19908/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | | |---|---|---| |
