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

[SPARK-48000][SQL] Enable hash join support for all collations (StringType) #46599

Closed
wants to merge 19 commits into from

Conversation

uros-db
Copy link
Contributor

@uros-db uros-db commented May 15, 2024

What changes were proposed in this pull request?

Enable collation support for hash join on StringType. Note: support for complex types will be added separately.

  • Logical plan is rewritten in analysis to replace non-binary strings with CollationKey
  • CollationKey is a unary expression that transforms StringType to BinaryType
  • Collation keys allow correct & efficient string comparison under specific collation rules

Why are the changes needed?

Improve JOIN performance for collated strings.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

  • Unit tests for CollationKey in CollationExpressionSuite
  • E2e SQL tests for RewriteCollationJoin in CollationSuite
  • Various queries with JOIN in existing TPCDS collation test suite

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

No.

@github-actions github-actions bot added the SQL label May 15, 2024
@uros-db uros-db requested a review from dbatomic May 17, 2024 04:52
@uros-db uros-db changed the title [WIP][SPARK-48000][SQL] Enable hash join support for all collations (StringType) [SPARK-48000][SQL] Enable hash join support for all collations (StringType) May 17, 2024
@uros-db uros-db requested a review from cloud-fan May 17, 2024 05:08
Copy link
Contributor

@dbatomic dbatomic left a comment

Choose a reason for hiding this comment

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

LGTM + a couple of ~minor comments.

@uros-db uros-db requested a review from cloud-fan May 22, 2024 18:02
@@ -250,7 +250,8 @@ abstract class Optimizer(catalogManager: CatalogManager)
InsertMapSortInGroupingExpressions) :+
// This batch must be executed after the `RewriteSubquery` batch, which creates joins.
Batch("NormalizeFloatingNumbers", Once, NormalizeFloatingNumbers) :+
Batch("ReplaceUpdateFieldsExpression", Once, ReplaceUpdateFieldsExpression)
Batch("ReplaceUpdateFieldsExpression", Once, ReplaceUpdateFieldsExpression) :+
Batch("RewriteCollationJoin", Once, RewriteCollationJoin)
Copy link
Contributor

Choose a reason for hiding this comment

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

since this enlarges the query plan (adding CollationKey), we should do it as late as possible: the last rule in SparkOptimizer

Copy link
Contributor Author

@uros-db uros-db May 24, 2024

Choose a reason for hiding this comment

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

moved RewriteCollationJoin to SparkOptimizer.postHocOptimizationBatches (I think this would be the last possible place)

@cloud-fan
Copy link
Contributor

@uros-db unfortunately it has merge conflicts now...

@cloud-fan
Copy link
Contributor

thanks, merging to master!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants