yihua commented on code in PR #13677:
URL: https://github.com/apache/hudi/pull/13677#discussion_r2268195824
##########
hudi-common/src/main/java/org/apache/hudi/common/table/HoodieTableMetaClient.java:
##########
@@ -1473,10 +1474,7 @@ public Properties build() {
tableConfig.setValue(HoodieTableConfig.NAME, tableName);
tableConfig.setValue(HoodieTableConfig.TYPE, tableType.name());
- if (null == tableVersion) {
- tableVersion = HoodieTableVersion.current();
- }
-
+ tableVersion = getTableVersionProperly();
Review Comment:
This change might not be needed, because the `hoodie.write.table.version`
only allows 6, 8, and 9 as valid values. Could you try reverting the change
and tests in `TestHoodieTableMetaClient` and see if the new tests in
`TestUpgradeDowngrade` still pass?
##########
hudi-common/src/main/java/org/apache/hudi/common/table/HoodieTableMetaClient.java:
##########
@@ -1591,6 +1589,20 @@ public Properties build() {
return tableConfig.getProps();
}
+ HoodieTableVersion getTableVersionProperly() {
+ if (tableVersion == null) {
+ return HoodieTableVersion.current();
+ } else if (tableVersion.greaterThanOrEquals(HoodieTableVersion.SIX)) {
+ return tableVersion;
+ } else {
+ String errorMessage = String.format(
+ "Creating a table in version \"%d\" is not allowed in current Hudi
binary. "
Review Comment:
```suggestion
"Creating a table in version \"%d\" is not allowed in the
current Hudi release. "
```
##########
hudi-spark-datasource/hudi-spark/src/test/java/org/apache/hudi/table/upgrade/TestUpgradeDowngrade.java:
##########
@@ -347,6 +355,60 @@ public void
testMetadataTableUpgradeDowngradeFailure(HoodieTableVersion fromVers
"Exception message should contain metadata table failure message");
}
+ @ParameterizedTest
+ @CsvSource({"1","2","3","4","5","6","7","8","9","null"})
+ void testTableVersionDuringTableCreation(String targetTableVersion) {
+ SparkSession spark = spark();
+ Map<String, String> writeOptions = new HashMap<>();
+ if (!targetTableVersion.equals("null")) {
+ writeOptions.put(HoodieWriteConfig.WRITE_TABLE_VERSION.key(),
targetTableVersion);
+ }
+ writeOptions.put(HoodieWriteConfig.TBL_NAME.key(), "testTableCreation");
+ HoodieTestDataGenerator dataGen = new HoodieTestDataGenerator();
+ List<String> records = recordsToStrings(dataGen.generateInserts("001", 5));
+ Dataset<Row> inputDF = spark.read().json(jsc().parallelize(records, 2));
+
+ // Create table, and validate.
+ Set<String> failSet = new HashSet<>(Arrays.asList("1", "2", "3", "4",
"5"));
+ if (failSet.contains(targetTableVersion)) {
+ // This fails at HoodieTableMetaClient.
+ assertThrows(HoodieNotSupportedException.class, () -> {
+ inputDF.write().format("org.apache.hudi")
+ .partitionBy("partition")
+ .options(writeOptions)
+ .mode(SaveMode.Append)
+ .save(basePath());
+ });
+ } else if (targetTableVersion.equals("7")) {
+ // Fails at write table version check.
+ assertThrows(IllegalArgumentException.class, () -> {
+ inputDF.write().format("org.apache.hudi")
Review Comment:
```suggestion
inputDF.write().format("hudi")
```
##########
hudi-spark-datasource/hudi-spark/src/test/java/org/apache/hudi/table/upgrade/TestUpgradeDowngrade.java:
##########
@@ -347,6 +355,60 @@ public void
testMetadataTableUpgradeDowngradeFailure(HoodieTableVersion fromVers
"Exception message should contain metadata table failure message");
}
+ @ParameterizedTest
+ @CsvSource({"1","2","3","4","5","6","7","8","9","null"})
+ void testTableVersionDuringTableCreation(String targetTableVersion) {
Review Comment:
Also test with `hoodie.write.auto.upgrade` as `true` and `false`?
##########
hudi-spark-datasource/hudi-spark/src/test/java/org/apache/hudi/table/upgrade/TestUpgradeDowngrade.java:
##########
@@ -347,6 +355,60 @@ public void
testMetadataTableUpgradeDowngradeFailure(HoodieTableVersion fromVers
"Exception message should contain metadata table failure message");
}
+ @ParameterizedTest
+ @CsvSource({"1","2","3","4","5","6","7","8","9","null"})
+ void testTableVersionDuringTableCreation(String targetTableVersion) {
+ SparkSession spark = spark();
+ Map<String, String> writeOptions = new HashMap<>();
+ if (!targetTableVersion.equals("null")) {
+ writeOptions.put(HoodieWriteConfig.WRITE_TABLE_VERSION.key(),
targetTableVersion);
+ }
+ writeOptions.put(HoodieWriteConfig.TBL_NAME.key(), "testTableCreation");
+ HoodieTestDataGenerator dataGen = new HoodieTestDataGenerator();
+ List<String> records = recordsToStrings(dataGen.generateInserts("001", 5));
+ Dataset<Row> inputDF = spark.read().json(jsc().parallelize(records, 2));
+
+ // Create table, and validate.
+ Set<String> failSet = new HashSet<>(Arrays.asList("1", "2", "3", "4",
"5"));
+ if (failSet.contains(targetTableVersion)) {
+ // This fails at HoodieTableMetaClient.
+ assertThrows(HoodieNotSupportedException.class, () -> {
+ inputDF.write().format("org.apache.hudi")
Review Comment:
```suggestion
inputDF.write().format("hudi")
```
--
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]