CSHARP-5973: Support SkipWhile/TakeWhile index overloads in LINQ provider#1954
Open
adelinowona wants to merge 6 commits intomongodb:mainfrom
Open
CSHARP-5973: Support SkipWhile/TakeWhile index overloads in LINQ provider#1954adelinowona wants to merge 6 commits intomongodb:mainfrom
adelinowona wants to merge 6 commits intomongodb:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds LINQ3 provider support for the indexed predicate overloads of SkipWhile/TakeWhile by translating them to $reduce with arrayIndexAs, and introduces tests/feature gating to validate behavior and server compatibility.
Changes:
- Extend method reflection metadata to recognize
SkipWhile((x, i) => ...)/TakeWhile((x, i) => ...)for bothEnumerableandQueryable. - Update the SkipWhile/TakeWhile aggregation-expression translator and serializer deduction logic to handle the index parameter and emit
$reduce: { arrayIndexAs: ... }. - Add translator, serializer-finder, and integration tests, plus a new
Feature.ReduceArrayIndexAsgate for integration coverage.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SkipWhileOrTakeWhileMethodToAggregationExpressionTranslatorTests.cs | Adds AST-level unit tests for both non-indexed and indexed SkipWhile/TakeWhile translations. |
| tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/SerializerFinders/EnumerableTests.cs | Verifies serializer-finder resolves serializers for the new indexed overloads. |
| tests/MongoDB.Driver.Tests/Linq/Integration/SkipWhileOrTakeWhileWithIndexTests.cs | Adds end-to-end integration tests for indexed overloads (gated on server feature support). |
| src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SkipWhileOrTakeWhileMethodToAggreggationExpressoinTranslator.cs | Implements index-parameter handling and passes arrayIndexAs through to $reduce. |
| src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/ExpressionToAggregationExpressionTranslator.cs | Generalizes TranslateLambdaBody to accept multiple parameter symbols (needed for indexed lambdas). |
| src/MongoDB.Driver/Linq/Linq3Implementation/SerializerFinders/SerializerFinderVisitMethodCall.cs | Ensures the index parameter has an Int32Serializer when deducing serializers for indexed overloads. |
| src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/QueryableMethod.cs | Adds Queryable.SkipWhile/TakeWhile MethodInfo for indexed predicate overloads. |
| src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/EnumerableOrQueryableMethod.cs | Adds method sets for indexed overloads and includes them in relevant groupings. |
| src/MongoDB.Driver/Linq/Linq3Implementation/Reflection/EnumerableMethod.cs | Adds Enumerable.SkipWhile/TakeWhile MethodInfo for indexed predicate overloads. |
| src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Visitors/AstNodeVisitor.cs | Updates reduce visitor to preserve the new ArrayIndexAs child node. |
| src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstReduceExpression.cs | Adds ArrayIndexAs support to $reduce AST node rendering and updating. |
| src/MongoDB.Driver/Linq/Linq3Implementation/Ast/Expressions/AstExpression.cs | Extends AstExpression.Reduce factory to accept arrayIndexAs. |
| src/MongoDB.Driver/Core/Misc/Feature.cs | Introduces Feature.ReduceArrayIndexAs used to gate integration tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
BorisDog
approved these changes
Apr 15, 2026
Contributor
BorisDog
left a comment
There was a problem hiding this comment.
LGTM + minor comment.
Also need a 2nd review from someone with LINQ expertise.
|
|
||
| var queryable = withNestedAsQueryable ? | ||
| collection.AsQueryable().Select(x => x.A.AsQueryable().TakeWhile((item, i) => i < 3).ToArray()) : | ||
| collection.AsQueryable().Select(x => x.A.TakeWhile((item, i) => i < 3).ToArray()); |
Contributor
There was a problem hiding this comment.
Let's have a test somewhere that uses both item and i in the expression itself, like you did in Enumerable_Select_with_index_should_work
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.