This is an automated email from the ASF dual-hosted git repository.
yihua 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 30e5275a4d66 [MINOR] Add tests for autoUpgrade config during table
creation (#13677)
30e5275a4d66 is described below
commit 30e5275a4d66e1fb79f8cdfd35ba8c7a8269aeca
Author: Lin Liu <[email protected]>
AuthorDate: Mon Aug 11 20:49:27 2025 -0700
[MINOR] Add tests for autoUpgrade config during table creation (#13677)
Co-authored-by: Y Ethan Guo <[email protected]>
---
.../apache/hudi/functional/TestCOWDataSource.scala | 49 +++++++++++++++++++++-
1 file changed, 47 insertions(+), 2 deletions(-)
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 9641bfc4a934..9c5d34d0960e 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
@@ -29,7 +29,7 @@ import
org.apache.hudi.common.config.TimestampKeyGeneratorConfig.{TIMESTAMP_INPU
import org.apache.hudi.common.fs.FSUtils
import org.apache.hudi.common.model.{HoodieRecord, WriteOperationType}
import org.apache.hudi.common.model.HoodieRecord.HoodieRecordType
-import org.apache.hudi.common.table.{HoodieTableConfig, HoodieTableMetaClient,
TableSchemaResolver}
+import org.apache.hudi.common.table.{HoodieTableConfig, HoodieTableMetaClient,
HoodieTableVersion, TableSchemaResolver}
import org.apache.hudi.common.table.timeline.{HoodieInstant, HoodieTimeline,
TimelineUtils}
import org.apache.hudi.common.testutils.{HoodieTestDataGenerator,
HoodieTestUtils}
import
org.apache.hudi.common.testutils.HoodieTestUtils.{INSTANT_FILE_NAME_GENERATOR,
INSTANT_GENERATOR}
@@ -59,7 +59,7 @@ import org.junit.jupiter.api.{AfterEach, BeforeEach,
Disabled, Test}
import org.junit.jupiter.api.Assertions.{assertDoesNotThrow, assertEquals,
assertFalse, assertTrue, fail}
import org.junit.jupiter.api.function.Executable
import org.junit.jupiter.params.ParameterizedTest
-import org.junit.jupiter.params.provider.{CsvSource, EnumSource, ValueSource}
+import org.junit.jupiter.params.provider.{Arguments, CsvSource, EnumSource,
MethodSource, ValueSource}
import java.sql.{Date, Timestamp}
import java.util.concurrent.{CountDownLatch, TimeUnit}
@@ -116,6 +116,43 @@ class TestCOWDataSource extends HoodieSparkClientTestBase
with ScalaAssertionSup
assertTrue(HoodieDataSourceHelpers.hasNewCommits(storage, basePath, "000"))
}
+ @ParameterizedTest
+ @MethodSource(Array("tableVersionCreationTestCases"))
+ def testTableVersionDuringTableCreation(autoUpgrade: String,
targetTableVersion: String): Unit = {
+ val writeOptions = scala.collection.mutable.Map(
+ HoodieWriteConfig.TBL_NAME.key -> "testTableCreation",
+ HoodieWriteConfig.AUTO_UPGRADE_VERSION.key -> autoUpgrade)
+ if (!targetTableVersion.equals("null")) {
+ writeOptions += (HoodieWriteConfig.WRITE_TABLE_VERSION.key ->
targetTableVersion)
+ }
+ val dataGen: HoodieTestDataGenerator = new
HoodieTestDataGenerator(System.currentTimeMillis())
+ val records = recordsToStrings(dataGen.generateInserts("001", 5))
+ val inputDF: Dataset[Row] = spark.read.json(jsc.parallelize(records, 2))
+ // Create table, and validate.
+ val failSet = Set("1", "2", "3", "4", "5", "7")
+ if (failSet.contains(targetTableVersion)) {
+ val exception: IllegalArgumentException =
+ assertThrows(classOf[IllegalArgumentException])(
+ inputDF.write.format("hudi").partitionBy("partition")
+ .options(writeOptions).mode(SaveMode.Overwrite).save(basePath))
+ assertTrue(exception.getMessage.contains(
+ "The value of hoodie.write.table.version should be one of 6,8,9"))
+ } else {
+ inputDF.write.format("hudi").partitionBy("partition")
+ .options(writeOptions).mode(SaveMode.Overwrite).save(basePath)
+ metaClient =
HoodieTableMetaClient.builder.setConf(storageConf).setBasePath(basePath).build
+ // If no write version is specified, use current.
+ if (!targetTableVersion.equals("null")) {
+ assertEquals(
+
HoodieTableVersion.fromVersionCode(Integer.valueOf(targetTableVersion)),
+ metaClient.getTableConfig.getTableVersion)
+ } else {
+ // Otherwise, the table version is the target table version.
+ assertEquals(HoodieTableVersion.current,
metaClient.getTableConfig.getTableVersion)
+ }
+ }
+ }
+
@ParameterizedTest
@EnumSource(value = classOf[HoodieRecordType], names = Array("AVRO",
"SPARK"))
def testNoPrecombine(recordType: HoodieRecordType) {
@@ -2038,4 +2075,12 @@ object TestCOWDataSource {
df.withColumn(c, when(col(c).isNotNull, col(c)).otherwise(lit(null)))
}
}
+
+ def tableVersionCreationTestCases = {
+ val autoUpgradeValues = Array("true", "false")
+ val targetVersions = Array("1", "2", "3", "4", "5", "6", "7", "8", "9",
"null")
+ autoUpgradeValues.flatMap(
+ (autoUpgrade: String) => targetVersions.map(
+ (targetVersion: String) => Arguments.of(autoUpgrade, targetVersion)))
+ }
}