You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "vladanvasi-db (via GitHub)" <gi...@apache.org> on 2024/11/05 17:20:57 UTC
[PR] [SPARK-50230][SQL] Added logic to support reading unknown collation name as utf8_binary [spark]
vladanvasi-db opened a new pull request, #48760:
URL: https://github.com/apache/spark/pull/48760
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a faster review.
7. If you want to add a new configuration, please read the guideline first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error type or message, please read the guideline first in
'common/utils/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
I propose adding a new `SQLConf` entry which enables spark to read an invalid collation name as `UTF8_BINARY`.
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
These changes are needed in case when spark needs to read a delta table which has metadata with other convention for naming collations. Instead of failing, when this conf is enabled, spark would return the `UTF8_BINARY` collation.
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
If no, write 'No'.
-->
No.
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
-->
This patch was tested by adding tests in `DataTypeSuite`.
### Was this patch authored or co-authored using generative AI tooling?
<!--
If generative AI tooling has been used in the process of authoring this patch, please include the
phrase: 'Generated-by: ' followed by the name of the tool and its version.
If no, write 'No'.
Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
-->
No.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-50230][SQL] Added logic to support reading unknown collation name as utf8_binary [spark]
Posted by "vladanvasi-db (via GitHub)" <gi...@apache.org>.
vladanvasi-db commented on PR #48760:
URL: https://github.com/apache/spark/pull/48760#issuecomment-2457759530
@MaxGekk @stefankandic @stevomitric can you please take a look at this PR?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-50230][SQL] Added logic to support reading unknown collation name as utf8_binary [spark]
Posted by "vladanvasi-db (via GitHub)" <gi...@apache.org>.
vladanvasi-db commented on PR #48760:
URL: https://github.com/apache/spark/pull/48760#issuecomment-2459387626
@MaxGekk can you please take a look at this PR, CI is passing and the PR is already approved by collation team?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-50230][SQL] Added logic to support reading unknown collation name as utf8_binary [spark]
Posted by "vladanvasi-db (via GitHub)" <gi...@apache.org>.
vladanvasi-db commented on code in PR #48760:
URL: https://github.com/apache/spark/pull/48760#discussion_r1832168975
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -770,6 +770,14 @@ object SQLConf {
.booleanConf
.createWithDefault(Utils.isTesting)
+ lazy val ALLOW_READING_UNKNOWN_COLLATIONS =
Review Comment:
I do not have strong reasoning why it is made `lazy`, I will change it to standard `val`.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-50230][SQL] Added logic to support reading unknown collation name as utf8_binary [spark]
Posted by "stefankandic (via GitHub)" <gi...@apache.org>.
stefankandic commented on code in PR #48760:
URL: https://github.com/apache/spark/pull/48760#discussion_r1829749638
##########
sql/api/src/main/scala/org/apache/spark/sql/internal/SqlApiConfHelper.scala:
##########
@@ -33,6 +33,7 @@ private[sql] object SqlApiConfHelper {
val SESSION_LOCAL_TIMEZONE_KEY: String = "spark.sql.session.timeZone"
val LOCAL_RELATION_CACHE_THRESHOLD_KEY: String = "spark.sql.session.localRelationCacheThreshold"
val DEFAULT_COLLATION: String = "spark.sql.session.collation.default"
+ val UNKNOWN_COLLATION_NAME_ENABLED: String = "spark.sql.collation.unknown.enabled"
Review Comment:
```suggestion
val ALLOW_READING_UKNOWN_COLLATIONS: String = "spark.sql.collation.allowReadingUnknownCollations"
```
##########
sql/api/src/main/scala/org/apache/spark/sql/types/DataType.scala:
##########
@@ -350,7 +350,14 @@ object DataType {
}
private def stringTypeWithCollation(collationName: String): StringType = {
- StringType(CollationFactory.collationNameToId(collationName))
+ try {
+ StringType(CollationFactory.collationNameToId(collationName))
+ }
+ catch {
+ case e: SparkException if e.getCondition == "COLLATION_INVALID_NAME" &&
Review Comment:
I'm not really a fan of catching exceptions like this and comparing its string values; can we maybe create a small wrapper around `SparkException` with something like `InvalidCollationNameException`?
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/types/DataTypeSuite.scala:
##########
@@ -876,6 +878,49 @@ class DataTypeSuite extends SparkFunSuite {
}
}
+ test("string field with invalid collation name") {
+ val collationProviders = Seq("spark", "icu")
+ collationProviders.foreach { provider =>
+ val json =
+ s"""
+ |{
+ | "type": "struct",
+ | "fields": [
+ | {
+ | "name": "c1",
+ | "type": "string",
+ | "nullable": false,
+ | "metadata": {
+ | "${DataType.COLLATIONS_METADATA_KEY}": {
+ | "c1": "$provider.INVALID"
Review Comment:
I think it would also make sense for this conf to bypass the case when the provider is uknown as well
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -770,6 +770,14 @@ object SQLConf {
.booleanConf
.createWithDefault(Utils.isTesting)
+ lazy val UNKNOWN_COLLATION_NAME_ENABLED =
Review Comment:
```suggestion
lazy val ALLOW_READING_UKNOWN_COLLATIONS =
```
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-50230][SQL] Added logic to support reading unknown collation name as utf8_binary [spark]
Posted by "MaxGekk (via GitHub)" <gi...@apache.org>.
MaxGekk commented on PR #48760:
URL: https://github.com/apache/spark/pull/48760#issuecomment-2462859524
+1, LGTM. Merging to master.
Thank you, @vladanvasi-db and @stefankandic for review.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-50230][SQL] Added logic to support reading unknown collation name as utf8_binary [spark]
Posted by "vladanvasi-db (via GitHub)" <gi...@apache.org>.
vladanvasi-db commented on code in PR #48760:
URL: https://github.com/apache/spark/pull/48760#discussion_r1832175043
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/types/DataTypeSuite.scala:
##########
@@ -876,6 +878,90 @@ class DataTypeSuite extends SparkFunSuite {
}
}
+ test("string field with invalid collation name") {
+ val collationProviders = Seq("spark", "icu")
+ collationProviders.foreach { provider =>
+ val json =
+ s"""
+ |{
+ | "type": "struct",
+ | "fields": [
+ | {
+ | "name": "c1",
+ | "type": "string",
+ | "nullable": false,
+ | "metadata": {
+ | "${DataType.COLLATIONS_METADATA_KEY}": {
+ | "c1": "$provider.INVALID"
+ | }
+ | }
+ | }
+ | ]
+ |}
+ |""".stripMargin
+
+ // Check that the exception will be thrown in case of invalid collation name and
+ // UNKNOWN_COLLATION_NAME config not enabled.
+ checkError(
+ exception = intercept[SparkException] {
+ DataType.fromJson(json)
+ },
+ condition = "COLLATION_INVALID_NAME",
+ parameters = Map(
+ "proposals" -> "id",
Review Comment:
As far as I understand, the proposal parameter is used to propose the collation that is "closest" to the name that is provided here(closest means it differs in least number of characters) and here, the returned value is `id`. It is handled in `CollationFactory.getClosestSuggestionOnInvalidName` method.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-50230][SQL] Added logic to support reading unknown collation name as utf8_binary [spark]
Posted by "MaxGekk (via GitHub)" <gi...@apache.org>.
MaxGekk commented on code in PR #48760:
URL: https://github.com/apache/spark/pull/48760#discussion_r1831686216
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -770,6 +770,14 @@ object SQLConf {
.booleanConf
.createWithDefault(Utils.isTesting)
+ lazy val ALLOW_READING_UNKNOWN_COLLATIONS =
+ buildConf(SqlApiConfHelper.ALLOW_READING_UNKNOWN_COLLATIONS)
+ .internal()
+ .doc("Enables spark to read unknown collation name as UTF8_BINARY.")
Review Comment:
Could you describe both cases when it is `false` what happens?
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -770,6 +770,14 @@ object SQLConf {
.booleanConf
.createWithDefault(Utils.isTesting)
+ lazy val ALLOW_READING_UNKNOWN_COLLATIONS =
Review Comment:
Just wonder why you made it `lazy`?
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/types/DataTypeSuite.scala:
##########
@@ -876,6 +878,90 @@ class DataTypeSuite extends SparkFunSuite {
}
}
+ test("string field with invalid collation name") {
+ val collationProviders = Seq("spark", "icu")
+ collationProviders.foreach { provider =>
+ val json =
+ s"""
+ |{
+ | "type": "struct",
+ | "fields": [
+ | {
+ | "name": "c1",
+ | "type": "string",
+ | "nullable": false,
+ | "metadata": {
+ | "${DataType.COLLATIONS_METADATA_KEY}": {
+ | "c1": "$provider.INVALID"
+ | }
+ | }
+ | }
+ | ]
+ |}
+ |""".stripMargin
+
+ // Check that the exception will be thrown in case of invalid collation name and
+ // UNKNOWN_COLLATION_NAME config not enabled.
+ checkError(
+ exception = intercept[SparkException] {
+ DataType.fromJson(json)
+ },
+ condition = "COLLATION_INVALID_NAME",
+ parameters = Map(
+ "proposals" -> "id",
Review Comment:
Probably, it is not related to the PR. Just wonder why `id` is among proposals.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-50230][SQL] Added logic to support reading unknown collation name as utf8_binary [spark]
Posted by "MaxGekk (via GitHub)" <gi...@apache.org>.
MaxGekk closed pull request #48760: [SPARK-50230][SQL] Added logic to support reading unknown collation name as utf8_binary
URL: https://github.com/apache/spark/pull/48760
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org