Skip to content

Conversation

@rstam
Copy link
Contributor

@rstam rstam commented Feb 5, 2025

No description provided.

@rstam rstam requested a review from a team as a code owner February 5, 2025 05:13
Copy link
Contributor

@papafe papafe left a comment

Choose a reason for hiding this comment

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

Looks super good, and it's incredible how much easier is this compared to the other PR, good job!
I'm not LGTM at the moment mostly because OfTypeMethodToAggregationExpressionTranslator is a little bit over my head, so I'm waiting for someone else to take a look. And also waiting for the CI to be fixed 😄

@rstam
Copy link
Contributor Author

rstam commented Feb 5, 2025

This PR has a bit more in it than just the changes to ScalarDiscriminatorConvention and BsonSerializer which are the main changes.

I ended up with more changes than that because:

  1. I wrote tests for all the places a scalar discriminator might be used in polymorphic queries
  2. That led to finding some other things that needed to be fixed
  3. The tests also revealed some new AstSimplifier changes needed to generate simpler MQL

Copy link
Contributor

@adelinowona adelinowona left a comment

Choose a reason for hiding this comment

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

Nice LGTM!

Comment on lines 793 to 802
if (actualType == type || actualType.IsSubclassOf(type))
{
discriminators.Add(discriminator);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We could short circuit out of the loop after finding the actual type or a subtype as we shouldn't have two different subtypes with the same discriminator. Not sure if it's really worth it, maybe others have thoughts on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point that we are only expecting one match, so we could stop after finding it.

But I think even better would be to verify that there is only one match, replacing lines 791-797 with:

var matchingType = actualTypes.SingleOrDefault(t => t == type || t.IsSubclassOf(type));
if (matchingType != null)                                                              
{                                                                                      
    discriminators.Add(discriminator);                                                 
}                                                                                      

@rstam rstam requested a review from adelinowona February 8, 2025 23:26
protected void AssertStages(IEnumerable<BsonDocument> stages, IEnumerable<string> expectedStages)
{
stages.Should().Equal(expectedStages.Select(json => BsonDocument.Parse(json)));
stages.Should().Equal(expectedStages.Where(x => x != null).Select(json => BsonDocument.Parse(json)));
Copy link
Member

Choose a reason for hiding this comment

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

Should we sync the changes to newly created LinqIntegrationTest class for easier migration of the tests in future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Now that it is merge to master.

I will do that.

Copy link
Contributor

@BorisDog BorisDog left a comment

Choose a reason for hiding this comment

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

I like this much simpler alternative, great PR!
Just a few styling suggestions.

@rstam rstam requested a review from BorisDog February 20, 2025 15:18
Copy link
Member

@sanych-sun sanych-sun left a comment

Choose a reason for hiding this comment

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

LGTM

@rstam rstam force-pushed the 5481 branch 2 times, most recently from cfb1c33 to b26668f Compare February 26, 2025 02:32
Copy link
Contributor

@BorisDog BorisDog left a comment

Choose a reason for hiding this comment

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

LGTM!

@rstam rstam merged commit a98fe70 into mongodb:main Feb 27, 2025
28 of 30 checks passed
@sanych-sun sanych-sun added the bug Fixes issues or unintended behavior. label Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Fixes issues or unintended behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants