-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-2706] refactor spark-sql to make consistent with DataFrame api #3936
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2d428e1
[HUDI-2706] refactor spark-sql to make consistent with DataFrame api
YannByron c49f4cd
[[HUDI-2706] solve comments
YannByron d326b7b
[[HUDI-2706] add HoodieOptionConfig UT
YannByron 905d341
[HUDI-2706] solve comments
YannByron 7012680
[HUDI-2706] optimize UTs
YannByron 2930c00
[HUDI-2706] duplicate code
YannByron 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -17,15 +17,19 @@ | |
|
|
||
| package org.apache.hudi | ||
|
|
||
| import java.util.Properties | ||
|
|
||
| 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.{HoodieConfig, TypedProperties} | ||
| import org.apache.hudi.common.table.HoodieTableConfig | ||
| import org.apache.hudi.exception.HoodieException | ||
| import org.apache.spark.sql.SparkSession | ||
| import org.apache.spark.sql.hudi.command.SqlKeyGenerator | ||
|
|
||
| import java.util.Properties | ||
| import scala.collection.JavaConversions.mapAsJavaMap | ||
| import scala.collection.JavaConverters.{mapAsScalaMapConverter, _} | ||
| import scala.collection.JavaConverters.mapAsScalaMapConverter | ||
| import org.apache.hudi.keygen.factory.HoodieSparkKeyGeneratorFactory | ||
| import scala.collection.JavaConverters._ | ||
|
|
||
| /** | ||
| * WriterUtils to assist in write path in Datasource and tests. | ||
|
|
@@ -102,4 +106,68 @@ object HoodieWriterUtils { | |
| properties.putAll(mapAsJavaMap(parameters)) | ||
| new HoodieConfig(properties) | ||
| } | ||
|
|
||
| def getOriginKeyGenerator(parameters: Map[String, String]): String = { | ||
| val kg = parameters.getOrElse(KEYGENERATOR_CLASS_NAME.key(), null) | ||
| if (classOf[SqlKeyGenerator].getCanonicalName == kg) { | ||
|
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. is there uts cover the logic?
Contributor
Author
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. ok |
||
| parameters.getOrElse(SqlKeyGenerator.ORIGIN_KEYGEN_CLASS_NAME, null) | ||
| } else { | ||
| kg | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Detects conflicts between new parameters and existing table configurations | ||
| */ | ||
| def validateTableConfig(spark: SparkSession, params: Map[String, String], | ||
| tableConfig: HoodieConfig): Unit = { | ||
| val resolver = spark.sessionState.conf.resolver | ||
| val diffConfigs = StringBuilder.newBuilder | ||
| params.foreach { case (key, value) => | ||
| val existingValue = getStringFromTableConfigWithAlternatives(tableConfig, key) | ||
| if (null != existingValue && !resolver(existingValue, value)) { | ||
| diffConfigs.append(s"$key:\t$value\t${tableConfig.getString(key)}\n") | ||
| } | ||
| } | ||
|
|
||
| if (null != tableConfig) { | ||
| val datasourceRecordKey = params.getOrElse(RECORDKEY_FIELD.key(), null) | ||
| val tableConfigRecordKey = tableConfig.getString(HoodieTableConfig.RECORDKEY_FIELDS) | ||
| if (null != datasourceRecordKey && null != tableConfigRecordKey | ||
| && datasourceRecordKey != tableConfigRecordKey) { | ||
| diffConfigs.append(s"RecordKey:\t$datasourceRecordKey\t$tableConfigRecordKey\n") | ||
| } | ||
|
|
||
| val datasourcePreCombineKey = params.getOrElse(PRECOMBINE_FIELD.key(), null) | ||
| val tableConfigPreCombineKey = tableConfig.getString(HoodieTableConfig.PRECOMBINE_FIELD) | ||
| if (null != datasourcePreCombineKey && null != tableConfigPreCombineKey | ||
| && datasourcePreCombineKey != tableConfigPreCombineKey) { | ||
| diffConfigs.append(s"PreCombineKey:\t$datasourcePreCombineKey\t$tableConfigPreCombineKey\n") | ||
| } | ||
|
|
||
| val datasourceKeyGen = getOriginKeyGenerator(params) | ||
| val tableConfigKeyGen = tableConfig.getString(HoodieTableConfig.KEY_GENERATOR_CLASS_NAME) | ||
| if (null != datasourceKeyGen && null != tableConfigKeyGen | ||
| && datasourceKeyGen != tableConfigKeyGen) { | ||
| diffConfigs.append(s"KeyGenerator:\t$datasourceKeyGen\t$tableConfigKeyGen\n") | ||
| } | ||
| } | ||
|
|
||
| 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 | ||
| } else { | ||
| if (allAlternatives.contains(key)) { | ||
| tableConfig.getString(allAlternatives(key)) | ||
| } else { | ||
| tableConfig.getString(key) | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.