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-47430][SQL] Support GROUP BY for MapType #45549

Closed

Conversation

stevomitric
Copy link
Contributor

@stevomitric stevomitric commented Mar 17, 2024

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
  • 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

| ArrayData $keyArrayA = a.keyArray();
| ArrayData $valueArrayA = a.valueArray();
| ArrayData $keyArrayB = b.keyArray();
| ArrayData $valueArrayB = b.valueArray();
Copy link
Contributor

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;
Copy link
Contributor

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,
Copy link
Contributor

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],
Copy link
Contributor

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.

@github-actions github-actions bot added the DOCS label Mar 26, 2024
@cloud-fan
Copy link
Contributor

cloud-fan commented Mar 26, 2024

image

there are still test failures

@stevomitric
Copy link
Contributor Author

image there are still test failures

Build should be fixed now.

@cloud-fan
Copy link
Contributor

thanks, merging to master!

@cloud-fan cloud-fan closed this in d57164a Mar 27, 2024
cloud-fan pushed a commit that referenced this pull request Mar 27, 2024
### 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>
sweisdb pushed a commit to sweisdb/spark that referenced this pull request Apr 1, 2024
### 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>
sweisdb pushed a commit to sweisdb/spark that referenced this pull request Apr 1, 2024
### 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants