Skip to content
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

[SQL] Add collations support to split regex expression #45856

Closed
wants to merge 6 commits into from

Conversation

nikolamand-db
Copy link
Contributor

What changes were proposed in this pull request?

With these changes, split expression should support any collation with binary equality and UTF8_BINARY_LCASE. Other collations are derived from external ICU implementation and do not support split operation with regex splitters, for these we'll throw TypeCheckFailure.

Why are the changes needed?

To introduce collations support for split expression.

Does this PR introduce any user-facing change?

Yes, user should now successfully split collated strings.

How was this patch tested?

Modified existing test in CollationRegexpExpressionsSuite.

Was this patch authored or co-authored using generative AI tooling?

No.

@github-actions github-actions bot added the SQL label Apr 3, 2024
override def inputTypes: Seq[DataType] = Seq(StringType, StringType, IntegerType)
override def dataType: DataType = ArrayType(str.dataType, containsNull = false)
override def inputTypes: Seq[AbstractDataType] =
Seq(StringTypeBinaryLcase, StringTypeAnyCollation, IntegerType)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does it mean for "regex" to be of type StringTypeAnyCollation, as it doesn't seem to me that collation is respected/needed for this parameter to begin with? for example, consider: [,] with UNICODE_CI collation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, why would we allow any collation for the regex string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to support session-level default collation. If the user changes it and passes regex string literal, it will be interpreted as collated string. We don't want to throw exception in such cases.

@uros-db
Copy link
Contributor

uros-db commented Apr 11, 2024

heads up: we’ve done some major code restructuring in #45978, so please sync these changes before moving on

@nikolamand-db you’ll likely need to rewrite the code in this PR, so please follow the guidelines outlined in https://issues.apache.org/jira/browse/SPARK-47410

Copy link
Contributor

@uros-db uros-db left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM @cloud-fan please review

if (collation.supportsBinaryEquality) {
return execBinary(string, regex, limit);
} else {
return execLowercase(string, regex, limit);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no execICU for this operation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's not supported yet, we should add assert(collation.supportsLowercaseEquality)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think final lazy val collationId: Int = str.dataType.asInstanceOf[StringType].collationId for StringTypeBinaryLcase won't allow that to happen. But an additional assert in the else branch couldn't hurt too

StringSplitTestCase("ABC", "[b]", "UTF8_BINARY_LCASE", Seq("A", "C")),
StringSplitTestCase("AAA", "[a]", "UTF8_BINARY_LCASE", Seq("", "", "", "")),
StringSplitTestCase("AAA", "[b]", "UTF8_BINARY_LCASE", Seq("AAA")),
StringSplitTestCase("aAbB", "[ab]", "UTF8_BINARY_LCASE", Seq("", "", "", "", "")),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please write unit tests for all corner cases, instead of end-to-end tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewritten tests, please check.

Copy link
Contributor

@uros-db uros-db left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like where this PR is going for regexp expressions, the way we do these appears very different compared to StringExpressions...

let's pause this PR for now while we figure it out

@nikolamand-db
Copy link
Contributor Author

Closing as we have new approach for all regex functions #46077.

@nikolamand-db nikolamand-db changed the title [SPARK-47297][SQL] Add collations support to split regex expression [SQL] Add collations support to split regex expression Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants