-
Notifications
You must be signed in to change notification settings - Fork 28.4k
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-47430][SQL] Support GROUP BY for MapType #45549
Conversation
…sSuite.scala Co-authored-by: Maxim Gekk <max.gekk@gmail.com>
…sSuite.scala Co-authored-by: Maxim Gekk <max.gekk@gmail.com>
Co-authored-by: Ruifeng Zheng <ruifengz@foxmail.com>
…essions/codegen/CodeGenerator.scala Co-authored-by: Wenchen Fan <cloud0fan@gmail.com>
...atalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala
Outdated
Show resolved
Hide resolved
| ArrayData $keyArrayA = a.keyArray(); | ||
| ArrayData $valueArrayA = a.valueArray(); | ||
| ArrayData $keyArrayB = b.keyArray(); | ||
| ArrayData $valueArrayB = b.valueArray(); |
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.
do the above 4 variables need to use freshName
? They are just local variables in this method.
| ArrayData $valueArrayA = a.valueArray(); | ||
| ArrayData $keyArrayB = b.keyArray(); | ||
| ArrayData $valueArrayB = b.valueArray(); | ||
| int $minLength = (lengthA > lengthB) ? lengthB : lengthA; |
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.
ditto
@@ -244,7 +244,9 @@ abstract class Optimizer(catalogManager: CatalogManager) | |||
RemoveRedundantAliases, | |||
RemoveNoopOperators) :+ | |||
// This batch must be executed after the `RewriteSubquery` batch, which creates joins. | |||
Batch("NormalizeFloatingNumbers", Once, NormalizeFloatingNumbers) :+ | |||
Batch("NormalizeFloatingNumbers", Once, | |||
InsertMapSortInGroupingExpressions, |
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 we create a new batch for this rule?
@@ -2155,8 +2155,8 @@ class DataFrameAggregateSuite extends QueryTest | |||
) | |||
} | |||
|
|||
test("SPARK-46536 Support GROUP BY CalendarIntervalType") { | |||
val numRows = 50 | |||
private def assertAggregateOnDataframe(dfSeq: Seq[DataFrame], |
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'd rather test one DataFrame at a time, and the caller calls assertAggregateOnDataframe
multiple times.
…essions/codegen/CodeGenerator.scala Co-authored-by: Wenchen Fan <cloud0fan@gmail.com>
thanks, merging to master! |
### What changes were proposed in this pull request? Added normalization of map keys when they are put in `ArrayBasedMapBuilder`. ### Why are the changes needed? As map keys need to be unique, we need to add normalization on floating point numbers and prevent the following case when building a map: `Map(0.0, -0.0)`. This further unblocks GROUP BY statement for Map Types as per [this discussion](#45549 (comment)). ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? New UTs in `ArrayBasedMapBuilderSuite` ### Was this patch authored or co-authored using generative AI tooling? No Closes #45721 from stevomitric/stevomitric/fix-map-dup. Authored-by: Stevo Mitric <stevo.mitric@databricks.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
### What changes were proposed in this pull request? Changes proposed in this PR include: - Relaxed checks that prevent aggregating of map types - Added new analyzer rule that uses `MapSort` expression proposed in [this PR](apache#45639) - Created codegen that compares two sorted maps ### Why are the changes needed? Adding new functionality to GROUP BY map types ### Does this PR introduce _any_ user-facing change? Yes, ability to use `GROUP BY MapType` ### How was this patch tested? With new UTs ### Was this patch authored or co-authored using generative AI tooling? No Closes apache#45549 from stevomitric/stevomitric/map-group-by. Lead-authored-by: Stevo Mitric <stevo.mitric@databricks.com> Co-authored-by: Stefan Kandic <stefan.kandic@databricks.com> Co-authored-by: Stevo Mitric <stevomitric2000@gmail.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
### What changes were proposed in this pull request? Added normalization of map keys when they are put in `ArrayBasedMapBuilder`. ### Why are the changes needed? As map keys need to be unique, we need to add normalization on floating point numbers and prevent the following case when building a map: `Map(0.0, -0.0)`. This further unblocks GROUP BY statement for Map Types as per [this discussion](apache#45549 (comment)). ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? New UTs in `ArrayBasedMapBuilderSuite` ### Was this patch authored or co-authored using generative AI tooling? No Closes apache#45721 from stevomitric/stevomitric/fix-map-dup. Authored-by: Stevo Mitric <stevo.mitric@databricks.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
What changes were proposed in this pull request?
Changes proposed in this PR include:
MapSort
expression proposed in this PRWhy are the changes needed?
Adding new functionality to GROUP BY map types
Does this PR introduce any user-facing change?
Yes, ability to use
GROUP BY MapType
How was this patch tested?
With new UTs
Was this patch authored or co-authored using generative AI tooling?
No