-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-3726] Harden constraints around switching between different key generators #5205
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,14 +18,16 @@ | |
| package org.apache.hudi | ||
|
|
||
| import java.util.Properties | ||
| import org.apache.hudi.config.HoodieWriteConfig | ||
|
|
||
| import org.apache.hudi.DataSourceOptionsHelper.allAlternatives | ||
| import org.apache.hudi.DataSourceWriteOptions._ | ||
| import org.apache.hudi.common.config.HoodieMetadataConfig.ENABLE | ||
| import org.apache.hudi.common.config.{DFSPropertiesConfiguration, HoodieConfig, TypedProperties} | ||
| import org.apache.hudi.common.table.HoodieTableConfig | ||
| import org.apache.hudi.config.HoodieWriteConfig | ||
| import org.apache.hudi.exception.HoodieException | ||
| import org.apache.hudi.hive.HiveSyncConfig | ||
| import org.apache.hudi.keygen.{NonpartitionedKeyGenerator, SimpleKeyGenerator} | ||
| import org.apache.hudi.sync.common.HoodieSyncConfig | ||
| import org.apache.spark.sql.SparkSession | ||
| import org.apache.spark.sql.hudi.command.SqlKeyGenerator | ||
|
|
@@ -173,6 +175,29 @@ object HoodieWriterUtils { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Detects conflicts between datasourceKeyGen and existing table configuration keyGen | ||
| */ | ||
| def validateKeyGeneratorConfig(datasourceKeyGen: String, tableConfig: HoodieConfig): Unit = { | ||
| val diffConfigs = StringBuilder.newBuilder | ||
|
|
||
| if (null != tableConfig) { | ||
| val tableConfigKeyGen = tableConfig.getString(HoodieTableConfig.KEY_GENERATOR_CLASS_NAME) | ||
| if (null != tableConfigKeyGen && null != datasourceKeyGen) { | ||
| val nonPartitionedTableConfig = tableConfigKeyGen.equals(classOf[NonpartitionedKeyGenerator].getCanonicalName) | ||
| val simpleKeyDataSourceConfig = datasourceKeyGen.equals(classOf[SimpleKeyGenerator].getCanonicalName) | ||
| if (nonPartitionedTableConfig && simpleKeyDataSourceConfig) { | ||
| diffConfigs.append(s"KeyGenerator:\t$datasourceKeyGen\t$tableConfigKeyGen\n") | ||
|
Comment on lines
+186
to
+190
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i wonder if there are more case we need to catch here, as this check is very specific. What about the cases where users subclassed the built-in keygen ? Is there any generic way to prevent discrepancy.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, I also prefer to check all possible combination of switches. |
||
| } | ||
| } | ||
| } | ||
|
|
||
| if (diffConfigs.nonEmpty) { | ||
| diffConfigs.insert(0, "\nConfig conflict(key\tcurrent value\texisting value):\n") | ||
| throw new HoodieException(diffConfigs.toString.trim) | ||
| } | ||
| } | ||
|
|
||
| private def getStringFromTableConfigWithAlternatives(tableConfig: HoodieConfig, key: String): String = { | ||
| if (null == tableConfig) { | ||
| null | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.