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-4882: Support Skip and Take in expressions. #1584

Closed
wants to merge 0 commits into from

Conversation

rstam
Copy link
Contributor

@rstam rstam commented Dec 31, 2024

No description provided.

@rstam rstam requested a review from a team as a code owner December 31, 2024 22:51
@rstam rstam requested review from JamesKovacs, sanych-sun, adelinowona and damieng and removed request for a team and JamesKovacs December 31, 2024 22:51
return args[0];
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sanych-sun let's discuss the pros and cons of doing these simplifications here vs in the AstSimplifier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussing this with Alex we have chosen to leave as is for the time being.

@@ -229,13 +230,14 @@ protected override Expression VisitMethodCall(MethodCallExpression node)
var result = base.VisitMethodCall(node);

var method = node.Method;
if (IsCustomLinqExtensionMethod(method))
if (IsCustomLinqExtensionMethod(method) ||
method.Is(QueryableMethod.AsQueryable))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't let the PartialEvaluator evaluate nested AsQueryable.

@damieng here's an example of the headaches that nested AsQueryable causes.

{
var sourceExpression = arguments[0];
var countExpression = arguments[1];
Expression skipExpression = null;
if (sourceExpression is MethodCallExpression sourceSkipExpression && sourceSkipExpression.Method.IsOneOf(__skipMethods))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All simplifications (this was just one) have been moved to AstSimplifier.

[InlineData(3, "{ $project : { _v : [2, 3, 4], _id : 0 } }", false)]
[InlineData(3, "{ $project : { _v : [2, 3, 4], _id : 0 } }", true)]
[InlineData(4, "{ $project : { _v : { $slice : [[1, 2, 3, 4], { $max : ['$One', 0] }, 2147483647] }, _id : 0 } }", false)]
[InlineData(4, "{ $project : { _v : { $slice : [[1, 2, 3, 4], { $max : ['$One', 0] }, 2147483647] }, _id : 0 } }", 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.

Testing nested AsQueryable doubles the number of tests.

@damieng here's another example of the headaches that nested AsQueryable causes.

collection.AsQueryable().Select(x => new[] { 1, 2, 3, 4 }.Skip(1).ToArray()),
4 => withNestedAsQueryable ?
collection.AsQueryable().Select(x => new[] { 1, 2, 3, 4 }.AsQueryable().Skip(x.One).ToArray()) :
collection.AsQueryable().Select(x => new[] { 1, 2, 3, 4 }.Skip(x.One).ToArray()),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Testing nested AsQueryable doubles the number of scenarios.

@damieng here's another example of the headaches that nested AsQueryable causes.

[InlineData(7, "{ $project : { _v : { $slice : [{ $slice : [[1, 2, 3, 4], { $max : ['$One', 0] }, 2147483647] }, 2, 2147483647] }, _id : 0 } }", false)]
[InlineData(7, "{ $project : { _v : { $slice : [{ $slice : [[1, 2, 3, 4], { $max : ['$One', 0] }, 2147483647] }, 2, 2147483647] }, _id : 0 } }", true)]
[InlineData(8, "{ $project : { _v : { $slice : [{ $slice : [[1, 2, 3, 4], { $max : ['$One', 0] }, 2147483647] }, { $max : ['$Two', 0] }, 2147483647] }, _id : 0 } }", false)]
[InlineData(8, "{ $project : { _v : { $slice : [{ $slice : [[1, 2, 3, 4], { $max : ['$One', 0] }, 2147483647] }, { $max : ['$Two', 0] }, 2147483647] }, _id : 0 } }", 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.

I stopped modifying test methods to test nested AsQueryable with this one.

I'm wondering whether there is a better way to handle testing nested AsQueryable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussing with Alex we don't have a better way to test nested AsQueryable yet so I will refactor the remaining test methods to test nested AsQueryable also.

QueryableMethod.Take,
};

private static MethodInfo[] __skipOrTakeMethodsWithCount =
Copy link
Member

Choose a reason for hiding this comment

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

Is this the same array as __skipOrTakeMethods? Why do we need both?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

@rstam rstam requested a review from sanych-sun January 3, 2025 00:50
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

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