Skip to content

CSHARP-5463: Investigate whether calls to EnsureQueryableMethodHasNestedAsQueryableSource are actually needed. #1669

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

Merged
merged 1 commit into from
Apr 30, 2025

Conversation

rstam
Copy link
Contributor

@rstam rstam commented Apr 12, 2025

We should probably have a Zoom meeting to discuss this one.

@rstam rstam requested review from sanych-sun and adelinowona April 12, 2025 00:18
@rstam rstam requested a review from a team as a code owner April 12, 2025 00:18
@@ -27,7 +27,7 @@ public static void EnsureQueryableMethodHasNestedAsQueryableSource(MethodCallExp
if (expression.Method.DeclaringType == typeof(Queryable) &&
sourceTranslation.Serializer is not INestedAsQueryableSerializer)
{
throw new ExpressionNotSupportedException(expression, because: "source serializer is not a NestedAsQueryableSerializer");
throw new ExpressionNotSupportedException(expression, because: "source argument is an unsupported IQueryable type");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe the message should be even more descriptive?

For example, it could include the type of the unsupported IQueryable...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we can really improve the error message:

  1. The type of IQueryable is not known unless the value is a constant
  2. The name of the type doesn't mean anything to the user anyway (e.g. EnumerableQuery)

var enumerable = new int[] { 1, 2, 3 };

var queryable = collection.AsQueryable()
.Select(x => enumerable.AsQueryable().Contains(1));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the nested AsQueryable we've been supporting all along.

var nestedQueryable = new int[] { 1, 2, 3 }.AsQueryable();

var queryable = collection.AsQueryable()
.Select(x => nestedQueryable.Contains(1)); // PartialEvaluator turns this into Select(x => true)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one doesn't trigger an error because the entire nested queryable expression is evaluated by the partial evaluator.

var nestedQueryable = new int[] { 1, 2, 3 }.AsQueryable();

var queryable = collection.AsQueryable()
.Select(x => nestedQueryable.Contains(x.Id));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one triggers an error because the translator doesn't know how to translate nestedAsQueryable.

@rstam rstam added the chore Label to hide PR from generated Release Notes label Apr 12, 2025
@rstam rstam added feature and removed feature labels Apr 29, 2025
.Select(x => enumerable.AsQueryable().Contains(1));

var stages = Translate(collection, queryable);
AssertStages(stages, "{ $project : { _v : { $in : [1, [1, 2, 3]] }, _id : 0 } }");
Copy link
Member

Choose a reason for hiding this comment

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

I would say it's danger to support such translation. It could render the entire collection into the wire. Is such translation works with LinqToSql or something like that? It could lead to loading the entire table into the memory and then rendering it into the MQL. We might want to forbid 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.

This is a NESTED AsQueryable.

It's the same thing as if they left out the AsQueryable.

@rstam rstam requested a review from sanych-sun April 30, 2025 19:43
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

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.

LGTM

@rstam rstam merged commit 4402701 into mongodb:main Apr 30, 2025
1 check was pending
Copy link
Member

@damieng damieng 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
chore Label to hide PR from generated Release Notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants