-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-47296][SQL][COLLATION] Fail unsupported functions for non-binary collations #45422
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
e0485fc
Fail all 10 regexp expressions for non-binary collations
uros-db 355eee9
Reformat code
uros-db cde9eff
Refactoring and better test coverage
uros-db 616335b
Lockdown using StringType
uros-db e6bec45
Merge branch 'apache:master' into regexp-functions
uros-db 77e606c
Lockdown for regexpExpressions
uros-db ee72ed3
Renaming and small fixes
uros-db 8bc10f5
Code style fixes
uros-db 8ee0f58
Move StringType lockdown condition to case object
uros-db d3a9e70
Fix checkInputDataTypes
uros-db c11c458
Implicit cast for new StringTypes
uros-db 4778951
Implicit cast for new StringTypes
uros-db 1582f24
Separate suite for stringExpressions
uros-db 8d75846
Collation test fix
uros-db 63caef6
Reformat
uros-db 38c3906
Remove extra changes
uros-db 1d60cef
Rewrite collation mismatch check
uros-db 2f5aba9
Improve lockdown handling
uros-db b9b185d
Add ANSI type coercion
uros-db 3fed6cb
Better ANSI type coercion explanation
uros-db 638c6d4
Fix type coercion
uros-db af7611f
Fix ANSI type coercion
uros-db ceabb4a
Merge branch 'apache:master' into regexp-functions
uros-db 0f4a6b1
Fix failing tests
mihailomilosevic2001 9b24fba
Incorporate requested changes
mihailomilosevic2001 831197a
Merge branch 'apache:master' into regexp-functions
mihailomilosevic2001 99b36b0
Refactor code and fix comments
mihailomilosevic2001 9051923
Fix newlines
mihailomilosevic2001 6986b8b
Add back newlines
mihailomilosevic2001 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
89 changes: 89 additions & 0 deletions
89
...t/src/main/scala/org/apache/spark/sql/catalyst/expressions/CollationTypeConstraints.scala
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 |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /* | ||
| * 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.spark.sql.catalyst.expressions | ||
|
|
||
| import org.apache.spark.SparkException | ||
| import org.apache.spark.sql.catalyst.analysis.TypeCheckResult | ||
| import org.apache.spark.sql.catalyst.analysis.TypeCheckResult.DataTypeMismatch | ||
| import org.apache.spark.sql.catalyst.util.CollationFactory | ||
| import org.apache.spark.sql.types.{DataType, StringType} | ||
|
|
||
| object CollationTypeConstraints { | ||
| def checkCollationCompatibility( | ||
| superCheck: => TypeCheckResult, | ||
| collationId: Int, | ||
| rightDataType: DataType): TypeCheckResult = { | ||
| val checkResult = superCheck | ||
| if (checkResult.isFailure) return checkResult | ||
| // Additional check needed for collation compatibility | ||
| val rightCollationId: Int = rightDataType.asInstanceOf[StringType].collationId | ||
| if (collationId != rightCollationId) { | ||
| return DataTypeMismatch( | ||
| errorSubClass = "COLLATION_MISMATCH", | ||
| messageParameters = Map( | ||
| "collationNameLeft" -> CollationFactory.fetchCollation(collationId).collationName, | ||
| "collationNameRight" -> CollationFactory.fetchCollation(rightCollationId).collationName | ||
| ) | ||
| ) | ||
| } | ||
| TypeCheckResult.TypeCheckSuccess | ||
| } | ||
|
|
||
| object CollationSupportLevel extends Enumeration { | ||
| type CollationSupportLevel = Value | ||
|
|
||
| val SUPPORT_BINARY_ONLY: Value = Value(0) | ||
| val SUPPORT_LOWERCASE: Value = Value(1) | ||
| val SUPPORT_ALL_COLLATIONS: Value = Value(2) | ||
| } | ||
|
|
||
| def checkCollationSupport( | ||
| superCheck: => TypeCheckResult, | ||
| collationId: Int, | ||
| functionName: String, | ||
| collationSupportLevel: CollationSupportLevel.CollationSupportLevel) | ||
| : TypeCheckResult = { | ||
| val checkResult = superCheck | ||
| if (checkResult.isFailure) return checkResult | ||
| // Additional check needed for collation support | ||
| val collation = CollationFactory.fetchCollation(collationId) | ||
| collationSupportLevel match { | ||
| case CollationSupportLevel.SUPPORT_BINARY_ONLY => | ||
| if (!collation.isBinaryCollation) { | ||
| throwUnsupportedCollation(functionName, collation.collationName) | ||
| } | ||
| case CollationSupportLevel.SUPPORT_LOWERCASE => | ||
| if (!collation.isBinaryCollation && !collation.isLowercaseCollation) { | ||
| throwUnsupportedCollation(functionName, collation.collationName) | ||
| } | ||
| case CollationSupportLevel.SUPPORT_ALL_COLLATIONS => // No additional checks needed | ||
| case _ => throw new IllegalArgumentException("Invalid collation support level.") | ||
uros-db marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| TypeCheckResult.TypeCheckSuccess | ||
| } | ||
|
|
||
| private def throwUnsupportedCollation(functionName: String, collationName: String): Unit = { | ||
| throw new SparkException( | ||
| errorClass = "UNSUPPORTED_COLLATION.FOR_FUNCTION", | ||
| messageParameters = Map( | ||
| "functionName" -> functionName, | ||
uros-db marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "collationName" -> collationName), | ||
| cause = null | ||
| ) | ||
| } | ||
| } | ||
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.