This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git
The following commit(s) were added to refs/heads/master by this push:
new e4c229dab66e fix: write HoodieWriteMergeHandle merge results without
re-wrapping the payload (#20764)
e4c229dab66e is described below
commit e4c229dab66ecfc7f7a51dd114482f9d0c09c674
Author: Sivabalan Narayanan <[email protected]>
AuthorDate: Sat Nov 21 04:35:03 2026 +0000
fix: write HoodieWriteMergeHandle merge results without re-wrapping the
payload (#20764)
* fix: write HoodieWriteMergeHandle merge results without re-wrapping the
payload
HoodieWriteMergeHandle wrapped the merge result in a new instance of the
incoming payload class via constructHoodieRecord. For ExpressionPayload
(MERGE INTO), shouldIgnore then called getInsertValue on the merged row,
which:
- decoded the row's bytes with the MERGE source schema instead of the
table schema, failing or shifting values when the source columns are
NOT NULL and the table's are nullable; and
- re-applied the NOT MATCHED clause to the merged row, so a matched
update was silently dropped when that clause's condition was false.
Build the record with constructFinalHoodieRecord, as the file group
reader path already does, so the merge result is written as-is.
Closes #20762
* test: [DO NOT MERGE] default hoodie.write.merge.handle.class to
HoodieWriteMergeHandle for CI
Temporary commit so the full CI suite runs MERGE INTO and datasource writes
through HoodieWriteMergeHandle with the fix. To be reverted before the PR
leaves draft.
* Revert "test: [DO NOT MERGE] default hoodie.write.merge.handle.class to
HoodieWriteMergeHandle for CI"
This reverts commit 7757ee7fa0c89e2bcd41ca41551963a0e1e5caf2.
* test: run key MERGE INTO and COW write tests on both merge handles
- Add HoodieSparkSqlTestBase#testWithMergeHandles, which registers a test
once per merge handle (FileGroupReaderBasedMergeHandle and
HoodieWriteMergeHandle) with hoodie.write.merge.handle.class set.
- Rename TestMergeIntoWithWriteMergeHandle to
TestMergeIntoAcrossMergeHandles and run it on both handles.
- Run key COW MERGE INTO tests in TestMergeIntoTable, TestMergeIntoTable2
and TestPartialUpdateForMergeInto, and TestCOWDataSource
testCopyOnWriteUpserts/testCopyOnWriteDeletes, on both handles.
- TestPartialUpdateForMergeInto#validateLogBlock: order log files with
HoodieLogFile's comparator. A string sort compares the write token,
which holds the Spark stage id, before the instant, so it misordered
the files once stage ids in the JVM crossed 1000.
* test: cover MOR base file merges in TestMergeIntoAcrossMergeHandles
Run each case on COW and MOR tables with the SIMPLE index. It cannot
index log files, so MOR updates to a small file group are merged into
its base file through the merge handle instead of appended to a log
file; assert no log file was written so the test keeps covering that
path. Without the fix, the non-nullable source and NOT MATCHED cases
fail through HoodieWriteMergeHandle on MOR exactly as on COW.
---
.../org/apache/hudi/io/HoodieWriteMergeHandle.java | 4 +-
.../apache/hudi/functional/TestCOWDataSource.scala | 18 +-
.../sql/hudi/common/HoodieSparkSqlTestBase.scala | 24 +++
.../others/TestMergeIntoAcrossMergeHandles.scala | 198 +++++++++++++++++++++
.../sql/hudi/dml/others/TestMergeIntoTable.scala | 14 +-
.../sql/hudi/dml/others/TestMergeIntoTable2.scala | 4 +-
.../dml/others/TestPartialUpdateForMergeInto.scala | 13 +-
7 files changed, 253 insertions(+), 22 deletions(-)
diff --git
a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/HoodieWriteMergeHandle.java
b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/HoodieWriteMergeHandle.java
index 37718fdbbd08..e0d5fceedd0f 100644
---
a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/HoodieWriteMergeHandle.java
+++
b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/io/HoodieWriteMergeHandle.java
@@ -387,7 +387,9 @@ public class HoodieWriteMergeHandle<T, I, K, O> extends
HoodieAbstractMergeHandl
readerContext.getRecordContext(), props, orderingFields,
deleteContext);
BufferedRecord<T> mergeResult = recordMerger.merge(oldBufferedRecord,
newBufferedRecord, readerContext.getRecordContext(), props);
HoodieSchema combineRecordSchema =
readerContext.getRecordContext().getSchemaFromBufferRecord(mergeResult);
- HoodieRecord combinedRecord =
readerContext.getRecordContext().constructHoodieRecord(mergeResult);
+ // The merge result is final: build it without the payload, which
would decode it with the payload's own
+ // schema and re-apply payload logic (e.g. the NOT MATCHED clause of
ExpressionPayload) to the merged row.
+ HoodieRecord combinedRecord =
readerContext.getRecordContext().constructFinalHoodieRecord(mergeResult);
if (combinedRecord.shouldIgnore(combineRecordSchema, props)) {
// If it is an IGNORE_RECORD, just copy the old record, and do not
update the new record.
copyOldRecord = true;
diff --git
a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/functional/TestCOWDataSource.scala
b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/functional/TestCOWDataSource.scala
index 3bf0e029b072..98fcdf5d7d19 100644
---
a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/functional/TestCOWDataSource.scala
+++
b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/functional/TestCOWDataSource.scala
@@ -857,9 +857,12 @@ class TestCOWDataSource extends HoodieSparkClientTestBase
with ScalaAssertionSup
}
@ParameterizedTest
- @EnumSource(value = classOf[HoodieRecordType], names = Array("AVRO",
"SPARK"))
- def testCopyOnWriteDeletes(recordType: HoodieRecordType): Unit = {
- val (writeOpts, readOpts) = getWriterReaderOpts(recordType)
+ @CsvSource(Array(
+ "AVRO,org.apache.hudi.io.FileGroupReaderBasedMergeHandle",
"AVRO,org.apache.hudi.io.HoodieWriteMergeHandle",
+ "SPARK,org.apache.hudi.io.FileGroupReaderBasedMergeHandle",
"SPARK,org.apache.hudi.io.HoodieWriteMergeHandle"))
+ def testCopyOnWriteDeletes(recordType: HoodieRecordType, mergeHandleClass:
String): Unit = {
+ val (writeOpts, readOpts) = getWriterReaderOpts(recordType,
+ CommonOptionUtils.commonOpts ++
Map(HoodieWriteConfig.MERGE_HANDLE_CLASS_NAME.key -> mergeHandleClass))
// Insert Operation
val records1 = recordsToStrings(dataGen.generateInserts("000",
100)).asScala.toList
@@ -887,10 +890,12 @@ class TestCOWDataSource extends HoodieSparkClientTestBase
with ScalaAssertionSup
assertEquals(snapshotDF2.count(), 80)
}
- @Test
- def testCopyOnWriteUpserts(): Unit = {
+ @ParameterizedTest
+ @ValueSource(strings =
Array("org.apache.hudi.io.FileGroupReaderBasedMergeHandle",
"org.apache.hudi.io.HoodieWriteMergeHandle"))
+ def testCopyOnWriteUpserts(mergeHandleClass: String): Unit = {
val recordType = HoodieRecordType.AVRO
- val (writeOpts, readOpts) = getWriterReaderOpts(recordType)
+ val (writeOpts, readOpts) = getWriterReaderOpts(recordType,
+ CommonOptionUtils.commonOpts ++
Map(HoodieWriteConfig.MERGE_HANDLE_CLASS_NAME.key -> mergeHandleClass))
// Insert Operation
val records1 = recordsToStrings(dataGen.generateInserts("000",
100)).asScala.toList
@@ -911,7 +916,6 @@ class TestCOWDataSource extends HoodieSparkClientTestBase
with ScalaAssertionSup
inputDF2.write.format("org.apache.hudi")
.options(writeOpts)
.option(DataSourceWriteOptions.OPERATION.key,
DataSourceWriteOptions.UPSERT_OPERATION_OPT_VAL)
- .option("hoodie.write.merge.handle.class",
"org.apache.hudi.io.FileGroupReaderBasedMergeHandle")
.mode(SaveMode.Append)
.save(basePath)
val metaClient =
HoodieTableMetaClient.builder().setBasePath(basePath).setConf(storageConf).build()
diff --git
a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/common/HoodieSparkSqlTestBase.scala
b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/common/HoodieSparkSqlTestBase.scala
index ace64841b78b..05b1a72a0e77 100644
---
a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/common/HoodieSparkSqlTestBase.scala
+++
b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/common/HoodieSparkSqlTestBase.scala
@@ -32,6 +32,7 @@ import org.apache.hudi.common.util.OrderingValues
import org.apache.hudi.config.HoodieWriteConfig
import org.apache.hudi.hadoop.fs.HadoopFSUtils
import org.apache.hudi.index.HoodieInMemoryHashIndex
+import org.apache.hudi.io.{FileGroupReaderBasedMergeHandle,
HoodieWriteMergeHandle}
import org.apache.hudi.storage.{HoodieStorage, StoragePath}
import org.apache.hudi.testutils.HoodieClientTestUtils.{createMetaClient,
getSparkConfForTest}
@@ -139,6 +140,29 @@ class HoodieSparkSqlTestBase extends FunSuite with
BeforeAndAfterAll {
}
}
+ /**
+ * Merge handles a write can merge base file records through: the default
file group reader based handle,
+ * and [[HoodieWriteMergeHandle]], which merges with the incoming record's
payload.
+ */
+ protected val mergeHandleClasses: Seq[String] = Seq(
+ classOf[FileGroupReaderBasedMergeHandle[_, _, _, _]].getName,
+ classOf[HoodieWriteMergeHandle[_, _, _, _]].getName)
+
+ /**
+ * Registers the test once per class in [[mergeHandleClasses]], with
`hoodie.write.merge.handle.class` set to
+ * that class and its simple name appended to the test name.
+ */
+ protected def testWithMergeHandles(testName: String, testTags:
Tag*)(testFun: => Any)
+ (implicit pos: source.Position): Unit = {
+ mergeHandleClasses.foreach { mergeHandleClass =>
+ test(s"$testName
(${mergeHandleClass.substring(mergeHandleClass.lastIndexOf('.') + 1)})",
testTags: _*) {
+ withSQLConf(HoodieWriteConfig.MERGE_HANDLE_CLASS_NAME.key ->
mergeHandleClass) {
+ testFun
+ }
+ }
+ }
+ }
+
protected def getTableStoragePath(tableName: String): String = {
new File(sparkWareHouse, tableName).getCanonicalPath
}
diff --git
a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/dml/others/TestMergeIntoAcrossMergeHandles.scala
b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/dml/others/TestMergeIntoAcrossMergeHandles.scala
new file mode 100644
index 000000000000..89d9c00ac666
--- /dev/null
+++
b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/dml/others/TestMergeIntoAcrossMergeHandles.scala
@@ -0,0 +1,198 @@
+/*
+ * 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.spark.sql.hudi.dml.others
+
+import org.apache.hudi.config.HoodieIndexConfig
+
+import org.apache.spark.sql.Row
+import org.apache.spark.sql.hudi.common.HoodieSparkSqlTestBase
+import org.apache.spark.sql.types.{IntegerType, LongType, StringType,
StructField, StructType}
+import org.junit.jupiter.api.Assertions.assertTrue
+
+import java.nio.file.{Files, Paths}
+
+import scala.collection.JavaConverters._
+
+/**
+ * MERGE INTO updates of existing keys merged into base files, run through
every merge handle in
+ * [[HoodieSparkSqlTestBase.mergeHandleClasses]], on COW and MOR tables.
+ *
+ * A merge handle must write the merge result as-is. The merged row is in the
table schema
+ * (nullable columns), while [[ExpressionPayload]] decodes its bytes with the
MERGE source schema
+ * and re-applies the NOT MATCHED clause, so the merge result must not be
wrapped in an
+ * ExpressionPayload again, which HoodieWriteMergeHandle used to do.
+ *
+ * The tables use the SIMPLE index, which cannot index log files, so MOR
updates to a small file
+ * group are merged into its base file through the merge handle rather than
appended to a log file.
+ */
+class TestMergeIntoAcrossMergeHandles extends HoodieSparkSqlTestBase {
+
+ private val tableTypes = Seq("cow", "mor")
+
+ private def createTableWithRows(tableName: String, location: String,
tableType: String): Unit = {
+ spark.sql(
+ s"""
+ |create table $tableName (
+ | name string,
+ | city string,
+ | rating int,
+ | ts bigint,
+ | country string
+ |) using hudi
+ | partitioned by (country)
+ | tblproperties (
+ | type = '$tableType',
+ | primaryKey = 'country,name',
+ | preCombineField = 'ts'
+ | )
+ | location '$location'
+ """.stripMargin)
+ spark.sql(
+ s"""
+ |insert into $tableName values
+ | ('a1', 'phoenix', 1, 1000, 'US'),
+ | ('a2', 'nyc', 2, 1000, 'US'),
+ | ('a3', 'toronto', 3, 1000, 'CA')
+ """.stripMargin)
+ }
+
+ private def checkRows(tableName: String)(expected: Seq[Any]*): Unit =
+ checkAnswer(s"select name, city, rating, ts, country from $tableName order
by name")(expected: _*)
+
+ /** Asserts the writes merged into base files: on MOR an append to a log
file would bypass the merge handle. */
+ private def assertNoLogFiles(location: String): Unit = {
+ val logFiles = Files.walk(Paths.get(location)).iterator().asScala
+ .map(_.toString)
+ .filter(path => !path.contains("/.hoodie/") && path.contains(".log."))
+ .toList
+ assertTrue(logFiles.isEmpty, s"Expected updates to be merged into base
files, found log files: $logFiles")
+ }
+
+ /** Registers the test for each table type and merge handle, with the SIMPLE
index. */
+ private def testOnTableTypesAndMergeHandles(testName: String)(testFun:
String => Unit): Unit =
+ tableTypes.foreach { tableType =>
+ testWithMergeHandles(s"$testName ($tableType)") {
+ withSQLConf(HoodieIndexConfig.INDEX_TYPE.key -> "SIMPLE") {
+ testFun(tableType)
+ }
+ }
+ }
+
+ /** Registers a view whose columns are all nullable, as a scan of a table
gives. */
+ private def createNullableSourceView(viewName: String, rows: Row*): Unit = {
+ val sourceSchema = StructType(Seq(
+ StructField("name", StringType, nullable = true),
+ StructField("city", StringType, nullable = true),
+ StructField("rating", IntegerType, nullable = true),
+ StructField("ts", LongType, nullable = true),
+ StructField("country", StringType, nullable = true)))
+ spark.createDataFrame(rows.asJava,
sourceSchema).createOrReplaceTempView(viewName)
+ }
+
+ testOnTableTypesAndMergeHandles("Test MergeInto update with a non-nullable
source") { tableType =>
+ withTempDir { tmp =>
+ val tableName = generateTableName
+ val location = s"${tmp.getCanonicalPath}/$tableName"
+ createTableWithRows(tableName, location, tableType)
+
+ // A subquery of constants: every source column is NOT NULL, the table's
are nullable.
+ spark.sql(
+ s"""
+ |merge into $tableName t
+ |using (
+ | select 'a1' as name, 'scottsdale' as city, 9 as rating, 2000L as
ts, 'US' as country
+ | union all
+ | select 'a4', 'sf', 5, 2001L, 'US'
+ |) s
+ |on t.country = s.country and t.name = s.name
+ |when matched then update set *
+ |when not matched then insert *
+ """.stripMargin)
+
+ checkRows(tableName)(
+ Seq("a1", "scottsdale", 9, 2000L, "US"),
+ Seq("a2", "nyc", 2, 1000L, "US"),
+ Seq("a3", "toronto", 3, 1000L, "CA"),
+ Seq("a4", "sf", 5, 2001L, "US"))
+ assertNoLogFiles(location)
+ }
+ }
+
+ testOnTableTypesAndMergeHandles("Test MergeInto update with a nullable
source") { tableType =>
+ withTempDir { tmp =>
+ val tableName = generateTableName
+ val location = s"${tmp.getCanonicalPath}/$tableName"
+ createTableWithRows(tableName, location, tableType)
+
+ // Source columns match the table's nullability, so this passed even
before the fix.
+ val sourceView = s"${tableName}_source"
+ createNullableSourceView(sourceView,
+ Row("a1", "scottsdale", 9, 2000L, "US"),
+ Row("a4", "sf", 5, 2001L, "US"))
+
+ spark.sql(
+ s"""
+ |merge into $tableName t
+ |using $sourceView s
+ |on t.country = s.country and t.name = s.name
+ |when matched then update set *
+ |when not matched then insert *
+ """.stripMargin)
+
+ checkRows(tableName)(
+ Seq("a1", "scottsdale", 9, 2000L, "US"),
+ Seq("a2", "nyc", 2, 1000L, "US"),
+ Seq("a3", "toronto", 3, 1000L, "CA"),
+ Seq("a4", "sf", 5, 2001L, "US"))
+ assertNoLogFiles(location)
+ }
+ }
+
+ testOnTableTypesAndMergeHandles("Test MergeInto update is not filtered by
the NOT MATCHED condition") { tableType =>
+ withTempDir { tmp =>
+ val tableName = generateTableName
+ val location = s"${tmp.getCanonicalPath}/$tableName"
+ createTableWithRows(tableName, location, tableType)
+
+ // A nullable source, so the source and table schemas agree and only the
clause handling is exercised.
+ val sourceView = s"${tableName}_source"
+ createNullableSourceView(sourceView,
+ Row("a1", "scottsdale", 9, 2000L, "US"),
+ Row("a4", "sf", 50, 2001L, "US"))
+
+ // The NOT MATCHED condition is false for the matched key's source row,
so it must not affect its update.
+ spark.sql(
+ s"""
+ |merge into $tableName t
+ |using $sourceView s
+ |on t.country = s.country and t.name = s.name
+ |when matched then update set *
+ |when not matched and s.rating > 10 then insert *
+ """.stripMargin)
+
+ checkRows(tableName)(
+ Seq("a1", "scottsdale", 9, 2000L, "US"),
+ Seq("a2", "nyc", 2, 1000L, "US"),
+ Seq("a3", "toronto", 3, 1000L, "CA"),
+ Seq("a4", "sf", 50, 2001L, "US"))
+ assertNoLogFiles(location)
+ }
+ }
+}
diff --git
a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/dml/others/TestMergeIntoTable.scala
b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/dml/others/TestMergeIntoTable.scala
index 6f480eae6134..94ef91a31264 100644
---
a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/dml/others/TestMergeIntoTable.scala
+++
b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/dml/others/TestMergeIntoTable.scala
@@ -40,7 +40,7 @@ import org.slf4j.LoggerFactory
class TestMergeIntoTable extends HoodieSparkSqlTestBase with
ScalaAssertionSupport {
private val log = LoggerFactory.getLogger(getClass)
- test("Test MergeInto Basic") {
+ testWithMergeHandles("Test MergeInto Basic") {
Seq(true, false).foreach { sparkSqlOptimizedWrites =>
withRecordType()(withTempDir { tmp =>
withSparkSqlSessionConfig("hoodie.payload.combined.schema.validate" ->
"false",
@@ -182,7 +182,7 @@ class TestMergeIntoTable extends HoodieSparkSqlTestBase
with ScalaAssertionSuppo
*
* The test also provides test coverage for "Test merge into allowed
patterns of assignment clauses".
*/
- test("Test MergeInto with more than once update actions") {
+ testWithMergeHandles("Test MergeInto with more than once update actions") {
withTempDir { tmp =>
val targetTable = generateTableName
@@ -311,7 +311,7 @@ class TestMergeIntoTable extends HoodieSparkSqlTestBase
with ScalaAssertionSuppo
spark.sessionState.conf.unsetConf("hoodie.index.type")
}
- test("Test MergeInto with ignored record") {
+ testWithMergeHandles("Test MergeInto with ignored record") {
withRecordType()(withTempDir { tmp =>
withSQLConf("hoodie.payload.combined.schema.validate" -> "true") {
val sourceTable = generateTableName
@@ -670,7 +670,7 @@ class TestMergeIntoTable extends HoodieSparkSqlTestBase
with ScalaAssertionSuppo
}
}
- test("Test MergeInto For PreCombineField") {
+ testWithMergeHandles("Test MergeInto For PreCombineField") {
withRecordType()(withTempDir { tmp =>
withSQLConf("hoodie.payload.combined.schema.validate" -> "true",
MERGE_SMALL_FILE_GROUP_CANDIDATES_LIMIT.key() -> "0") {
Seq("cow", "mor").foreach { tableType =>
@@ -915,7 +915,7 @@ class TestMergeIntoTable extends HoodieSparkSqlTestBase
with ScalaAssertionSuppo
}
}
- test("Test MergeInto with combination of delete update insert") {
+ testWithMergeHandles("Test MergeInto with combination of delete update
insert") {
withRecordType()(withTempDir { tmp =>
withSQLConf("hoodie.payload.combined.schema.validate" -> "true") {
val sourceTable = generateTableName
@@ -1210,7 +1210,7 @@ class TestMergeIntoTable extends HoodieSparkSqlTestBase
with ScalaAssertionSuppo
})
}
- test("Test MereInto With Null Fields") {
+ testWithMergeHandles("Test MereInto With Null Fields") {
withRecordType()(withTempDir { tmp =>
withSQLConf("hoodie.payload.combined.schema.validate" -> "true") {
val types = Seq(
@@ -1487,7 +1487,7 @@ class TestMergeIntoTable extends HoodieSparkSqlTestBase
with ScalaAssertionSuppo
}
}
- test("Test MergeInto with partial update and insert") {
+ testWithMergeHandles("Test MergeInto with partial update and insert") {
withSQLConf(MERGE_SMALL_FILE_GROUP_CANDIDATES_LIMIT.key() -> "0") {
diff --git
a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/dml/others/TestMergeIntoTable2.scala
b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/dml/others/TestMergeIntoTable2.scala
index b0cb96f81866..7d321f2c32fb 100644
---
a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/dml/others/TestMergeIntoTable2.scala
+++
b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/dml/others/TestMergeIntoTable2.scala
@@ -748,7 +748,7 @@ class TestMergeIntoTable2 extends HoodieSparkSqlTestBase {
})
}
- test("Test Merge into where manually set DefaultHoodieRecordPayload") {
+ testWithMergeHandles("Test Merge into where manually set
DefaultHoodieRecordPayload") {
withRecordType()(withTempDir { tmp =>
val tableName = generateTableName
// Create a cow table with default payload class, check whether it will
be overwritten by ExpressionPayload.
@@ -1250,7 +1250,7 @@ class TestMergeIntoTable2 extends HoodieSparkSqlTestBase {
})
}
- test("Test MergeInto with commit time/event time ordering coverage") {
+ testWithMergeHandles("Test MergeInto with commit time/event time ordering
coverage") {
Seq("cow", "mor").foreach { tableType =>
withTempDir { tmp =>
Seq(RecordMergeMode.COMMIT_TIME_ORDERING.name(),
diff --git
a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/dml/others/TestPartialUpdateForMergeInto.scala
b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/dml/others/TestPartialUpdateForMergeInto.scala
index f7e666ca0962..e5b0bb3fa913 100644
---
a/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/dml/others/TestPartialUpdateForMergeInto.scala
+++
b/hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/dml/others/TestPartialUpdateForMergeInto.scala
@@ -38,17 +38,17 @@ import
org.apache.spark.sql.hudi.common.HoodieSparkSqlTestBase.getMetaClientAndF
import org.apache.spark.sql.types.{DoubleType, IntegerType, StringType,
StructField}
import org.junit.jupiter.api.Assertions.{assertEquals, assertFalse, assertTrue}
-import java.util.{Collections, List, Optional}
+import java.util.{List, Optional}
import scala.collection.JavaConverters._
class TestPartialUpdateForMergeInto extends HoodieSparkSqlTestBase {
- test("Test partial update with COW and Avro log format") {
+ testWithMergeHandles("Test partial update with COW and Avro log format") {
testPartialUpdate("cow", "avro")
}
- test("Test partial update with COW and Avro log format and commit time
ordering") {
+ testWithMergeHandles("Test partial update with COW and Avro log format and
commit time ordering") {
testPartialUpdate("cow", "avro", commitTimeOrdering = true)
}
@@ -68,7 +68,7 @@ class TestPartialUpdateForMergeInto extends
HoodieSparkSqlTestBase {
testPartialUpdate("mor", "parquet", commitTimeOrdering = true)
}
- test("Test partial update and insert with COW and Avro log format") {
+ testWithMergeHandles("Test partial update and insert with COW and Avro log
format") {
testPartialUpdateWithInserts("cow", "avro")
}
@@ -744,7 +744,10 @@ class TestPartialUpdateForMergeInto extends
HoodieSparkSqlTestBase {
.findFirst()
assertTrue(fileSlice.isPresent)
val logFilePathList: List[String] =
HoodieTestUtils.getLogFileListFromFileSlice(fileSlice.get)
- Collections.sort(logFilePathList)
+ // Order by delta commit time. A plain string sort compares the write
token first, which holds the Spark stage
+ // id, so it misorders the files once stage ids in the JVM cross a power
of ten.
+ logFilePathList.sort((a: String, b: String) =>
+ HoodieLogFile.getLogFileComparator.compare(new HoodieLogFile(a), new
HoodieLogFile(b)))
val schema = new TableSchemaResolver(metaClient).getTableSchema
for (i <- 0 until expectedNumLogFile) {