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

CSHARP-5446: Linq Aggregte Group(...) not support AddToSet #1599

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sanych-sun
Copy link
Member

No description provided.

@sanych-sun sanych-sun requested a review from a team as a code owner January 23, 2025 19:56
@sanych-sun sanych-sun requested review from BorisDog and rstam and removed request for a team and BorisDog January 23, 2025 19:56
Copy link
Contributor

@rstam rstam left a comment

Choose a reason for hiding this comment

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

One question before I LGTM.

case AstUnaryOperator.Avg: accumulatorOperator = AstUnaryAccumulatorOperator.Avg; return true;
case AstUnaryOperator.First: accumulatorOperator = AstUnaryAccumulatorOperator.First; return true;
case AstUnaryOperator.Last: accumulatorOperator = AstUnaryAccumulatorOperator.Last; return true;
case AstUnaryOperator.Max: accumulatorOperator = AstUnaryAccumulatorOperator.Max; return true;
case AstUnaryOperator.Min: accumulatorOperator = AstUnaryAccumulatorOperator.Min; return true;
case AstUnaryOperator.Push: accumulatorOperator = AstUnaryAccumulatorOperator.Push; return true;
case AstUnaryOperator.SetUnion: accumulatorOperator = AstUnaryAccumulatorOperator.AddToSet; return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

You should add a similar mapping for SetIntersection.

Even if we aren't currently generating any MQL with SetIntersection it's a valid optimization.

SetUnion and SetIntersection with a single argument (i.e. the unary versions) are equivalent.

@@ -786,8 +786,8 @@ public void IGrouping_Distinct_of_root_should_work()
var stages = Translate(collection, queryable);
var expectedStages = new[]
{
"{ $group : { _id : '$_id', _elements : { $push : '$$ROOT' } } }", // MQL could be optimized further
Copy link
Contributor

Choose a reason for hiding this comment

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

MQL could be optimized further! :)

And now it is.

@sanych-sun sanych-sun changed the title Csharp5446 CSHARP-5446: Linq Aggregte Group(...) not support AddToSet Jan 23, 2025
Copy link
Contributor

@rstam rstam left a comment

Choose a reason for hiding this comment

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

LGTM

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

Successfully merging this pull request may close these issues.

2 participants