-
Notifications
You must be signed in to change notification settings - Fork 28.3k
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
[SPARK-47296][SQL][COLLATION] Fail unsupported functions for non-binary collations #45422
Closed
Closed
Changes from all 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
mihailom-db 9b24fba
Incorporate requested changes
mihailom-db 831197a
Merge branch 'apache:master' into regexp-functions
mihailom-db 99b36b0
Refactor code and fix comments
mihailom-db 9051923
Fix newlines
mihailom-db 6986b8b
Add back newlines
mihailom-db 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
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
77 changes: 77 additions & 0 deletions
77
...t/src/main/scala/org/apache/spark/sql/catalyst/expressions/CollationTypeConstraints.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,77 @@ | ||
/* | ||
* 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.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.{AbstractDataType, DataType, StringType} | ||
|
||
object CollationTypeConstraints { | ||
|
||
def checkCollationCompatibility(collationId: Int, dataTypes: Seq[DataType]): TypeCheckResult = { | ||
val collationName = CollationFactory.fetchCollation(collationId).collationName | ||
// Additional check needed for collation compatibility | ||
dataTypes.collectFirst { | ||
case stringType: StringType if stringType.collationId != collationId => | ||
val collation = CollationFactory.fetchCollation(stringType.collationId) | ||
DataTypeMismatch( | ||
errorSubClass = "COLLATION_MISMATCH", | ||
messageParameters = Map( | ||
"collationNameLeft" -> collationName, | ||
"collationNameRight" -> collation.collationName | ||
) | ||
) | ||
} getOrElse TypeCheckResult.TypeCheckSuccess | ||
} | ||
|
||
} | ||
|
||
/** | ||
* StringTypeCollated is an abstract class for StringType with collation support. | ||
*/ | ||
abstract class StringTypeCollated extends AbstractDataType { | ||
override private[sql] def defaultConcreteType: DataType = StringType | ||
} | ||
|
||
/** | ||
* Use StringTypeBinary for expressions supporting only binary collation. | ||
*/ | ||
case object StringTypeBinary extends StringTypeCollated { | ||
override private[sql] def simpleString: String = "string_binary" | ||
override private[sql] def acceptsType(other: DataType): Boolean = | ||
other.isInstanceOf[StringType] && other.asInstanceOf[StringType].isBinaryCollation | ||
} | ||
|
||
/** | ||
* Use StringTypeBinaryLcase for expressions supporting only binary and lowercase collation. | ||
*/ | ||
case object StringTypeBinaryLcase extends StringTypeCollated { | ||
override private[sql] def simpleString: String = "string_binary_lcase" | ||
override private[sql] def acceptsType(other: DataType): Boolean = | ||
other.isInstanceOf[StringType] && (other.asInstanceOf[StringType].isBinaryCollation || | ||
other.asInstanceOf[StringType].isLowercaseCollation) | ||
} | ||
|
||
/** | ||
* Use StringTypeAnyCollation for expressions supporting all possible collation types. | ||
*/ | ||
case object StringTypeAnyCollation extends StringTypeCollated { | ||
override private[sql] def simpleString: String = "string_any_collation" | ||
override private[sql] def acceptsType(other: DataType): Boolean = other.isInstanceOf[StringType] | ||
} |
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.
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.
Can you remove even this guy and push the check into
StringTypeBinaryLcase
?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.
I am not sure this is possible. StringTypeBinaryLcase does not extend StringType, and the point of this function for now is to call it on StringType object in acceptsType to check if we should let the function proceed with that input.