-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[HUDI-8817] fix backward compatibility issue #12615
Draft
Davis-Zhang-Onehouse
wants to merge
1
commit into
apache:master
Choose a base branch
from
Davis-Zhang-Onehouse:HUDI-8817
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+227
−43
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
hudi-common/src/main/java/org/apache/hudi/common/config/HoodieWriteBaseConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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.common.config; | ||
|
||
import org.apache.hudi.common.table.HoodieTableVersion; | ||
import org.apache.hudi.common.table.timeline.versioning.TimelineLayoutVersion; | ||
|
||
import javax.annotation.concurrent.Immutable; | ||
|
||
import java.util.Properties; | ||
|
||
@Immutable | ||
public class HoodieWriteBaseConfig extends HoodieConfig { | ||
protected HoodieWriteBaseConfig(Properties props) { | ||
super(props); | ||
} | ||
|
||
protected HoodieWriteBaseConfig() { | ||
super(); | ||
} | ||
|
||
public static final ConfigProperty<Integer> WRITE_TABLE_VERSION = ConfigProperty | ||
.key("hoodie.write.table.version") | ||
.defaultValue(HoodieTableVersion.current().versionCode()) | ||
.withValidValues( | ||
String.valueOf(HoodieTableVersion.SIX.versionCode()), | ||
String.valueOf(HoodieTableVersion.current().versionCode()) | ||
) | ||
.sinceVersion("1.0.0") | ||
.withDocumentation("The table version this writer is storing the table in. This should match the current table version."); | ||
|
||
public static final ConfigProperty<String> TIMELINE_LAYOUT_VERSION_NUM = ConfigProperty | ||
.key("hoodie.timeline.layout.version") | ||
.defaultValue(Integer.toString(TimelineLayoutVersion.CURR_VERSION)) | ||
.withValidValues(Integer.toString(TimelineLayoutVersion.VERSION_0), | ||
Integer.toString(TimelineLayoutVersion.VERSION_1), | ||
Integer.toString(TimelineLayoutVersion.VERSION_2)) | ||
.markAdvanced() | ||
.sinceVersion("0.5.1") | ||
.withDocumentation("Controls the layout of the timeline. Version 0 relied on renames, Version 1 (default) models " | ||
+ "the timeline as an immutable log relying only on atomic writes for object storage."); | ||
|
||
public HoodieTableVersion getWriteVersion() { | ||
Integer versionCode = getInt(WRITE_TABLE_VERSION); | ||
if (versionCode != null) { | ||
WRITE_TABLE_VERSION.checkValues(versionCode.toString()); | ||
} | ||
return HoodieTableVersion.fromVersionCode(getIntOrDefault(WRITE_TABLE_VERSION)); | ||
} | ||
|
||
public Integer getTimelineLayoutVersion() { | ||
return getInt(TIMELINE_LAYOUT_VERSION_NUM); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
...ource/hudi-spark/src/test/scala/org/apache/hudi/functional/TestDefaultEightWriteSix.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* 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.common.table.HoodieTableMetaClient | ||
import org.apache.spark.sql.hudi.common.HoodieSparkSqlTestBase | ||
import org.junit.jupiter.api.Assertions.{assertEquals, assertNotEquals} | ||
import org.apache.hudi.common.config.HoodieWriteBaseConfig.WRITE_TABLE_VERSION | ||
import org.apache.hudi.common.table.HoodieTableConfig.VERSION | ||
import org.apache.hudi.hadoop.fs.HadoopFSUtils | ||
|
||
class TestDefaultEightWriteSix extends HoodieSparkSqlTestBase { | ||
|
||
test("Test default version eight write version six") { | ||
withSparkSqlSessionConfig(VERSION.key() -> "8", | ||
WRITE_TABLE_VERSION.key() -> "8") { | ||
withTempDir { tmp => | ||
val tableName = generateTableName | ||
val basePath = tmp.getCanonicalPath | ||
val writeVersionCode = 6 | ||
spark.sql( | ||
s""" | ||
| create table $tableName ( | ||
| id int, | ||
| ts long, | ||
| dt string | ||
| ) using hudi | ||
| tblproperties ( | ||
| type = 'mor', | ||
| primaryKey = 'id', | ||
| preCombineField = 'ts', | ||
| hoodie.write.table.version = $writeVersionCode | ||
| ) | ||
| partitioned by(dt) | ||
| location '$basePath' | ||
""".stripMargin) | ||
val metaClient = HoodieTableMetaClient.builder().setBasePath(basePath) | ||
.setConf(HadoopFSUtils.getStorageConf(spark.sessionState.newHadoopConf())).build() | ||
assertEquals(metaClient.getTableConfig.getTableVersion.versionCode(), writeVersionCode) | ||
} | ||
} | ||
} | ||
|
||
test("Test conflicting version config") { | ||
withTempDir { tmp => | ||
val tableName = generateTableName | ||
val basePath = tmp.getCanonicalPath | ||
val tableVersionCode = 6 | ||
val writeVersionCode = 8 | ||
spark.sql( | ||
s""" | ||
| create table $tableName ( | ||
| id int, | ||
| ts long, | ||
| dt string | ||
| ) using hudi | ||
| tblproperties ( | ||
| type = 'mor', | ||
| primaryKey = 'id', | ||
| preCombineField = 'ts', | ||
| hoodie.table.version = $tableVersionCode, | ||
| hoodie.write.table.version = $writeVersionCode | ||
| ) | ||
| partitioned by(dt) | ||
| location '$basePath' | ||
""".stripMargin) | ||
val metaClient = HoodieTableMetaClient.builder().setBasePath(basePath) | ||
.setConf(HadoopFSUtils.getStorageConf(spark.sessionState.newHadoopConf())).build() | ||
assertEquals(metaClient.getTableConfig.getTableVersion.versionCode(), tableVersionCode) | ||
} | ||
} | ||
|
||
test("Test default version eight write version six conflicting config") { | ||
withTempDir { tmp => | ||
val tableName = generateTableName | ||
val basePath = tmp.getCanonicalPath | ||
val tableVersionCode = 6 | ||
assertNotEquals(VERSION.defaultValue().versionCode(), tableVersionCode) | ||
spark.sql( | ||
s""" | ||
| create table $tableName ( | ||
| id int, | ||
| ts long, | ||
| dt string | ||
| ) using hudi | ||
| tblproperties ( | ||
| type = 'mor', | ||
| primaryKey = 'id', | ||
| preCombineField = 'ts', | ||
| hoodie.table.version = "$tableVersionCode" | ||
| ) | ||
| partitioned by(dt) | ||
| location '$basePath' | ||
""".stripMargin) | ||
val metaClient = HoodieTableMetaClient.builder().setBasePath(basePath) | ||
.setConf(HadoopFSUtils.getStorageConf(spark.sessionState.newHadoopConf())).build() | ||
assertEquals(metaClient.getTableConfig.getTableVersion.versionCode(), tableVersionCode) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic in meta client should not consider write table version. Otherwise, there is no point checking whether
hoodie.write.table.version
andhoodie.table.version
match.CommonClientUtils#validateTableVersion
has the validation. Does Spark SQL writer escape that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, SQL writer does not call this function at all for create table stmt