-
Notifications
You must be signed in to change notification settings - Fork 494
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
Query: Adds LINQ Support for FirstOrDefault #4286
Merged
microsoft-github-policy-service
merged 10 commits into
master
from
users/adityasa/FirstOrDefault
Jan 30, 2024
Merged
Query: Adds LINQ Support for FirstOrDefault #4286
microsoft-github-policy-service
merged 10 commits into
master
from
users/adityasa/FirstOrDefault
Jan 30, 2024
Conversation
This file contains 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
adityasa
requested review from
khdang,
sboshra,
neildsh,
kirankumarkolli,
ealsur,
FabianMeiswinkel and
kirillg
as code owners
January 27, 2024 23:12
adityasa
commented
Jan 27, 2024
adityasa
commented
Jan 27, 2024
adityasa
commented
Jan 27, 2024
adityasa
commented
Jan 27, 2024
adityasa
commented
Jan 27, 2024
adityasa
commented
Jan 27, 2024
adityasa
commented
Jan 27, 2024
adityasa
commented
Jan 27, 2024
Microsoft.Azure.Cosmos/src/Query/v2Query/DocumentQueryExecutionContextBase.cs
Outdated
Show resolved
Hide resolved
adityasa
commented
Jan 28, 2024
adityasa
force-pushed
the
users/adityasa/FirstOrDefault
branch
from
January 28, 2024 20:20
1dce38f
to
f70b19f
Compare
sboshra
reviewed
Jan 29, 2024
sboshra
reviewed
Jan 29, 2024
sboshra
reviewed
Jan 29, 2024
sboshra
reviewed
Jan 29, 2024
sboshra
reviewed
Jan 29, 2024
Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Linq/LinqCleanupTests.cs
Show resolved
Hide resolved
sboshra
reviewed
Jan 29, 2024
...re.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Linq/LinqScalarFunctionBaselineTests.cs
Outdated
Show resolved
Hide resolved
sboshra
reviewed
Jan 29, 2024
...re.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Linq/LinqScalarFunctionBaselineTests.cs
Show resolved
Hide resolved
sboshra
previously approved these changes
Jan 29, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adityasa
commented
Jan 29, 2024
Maya-Painter
approved these changes
Jan 29, 2024
Maya-Painter
approved these changes
Jan 30, 2024
sboshra
approved these changes
Jan 30, 2024
microsoft-github-policy-service
bot
deleted the
users/adityasa/FirstOrDefault
branch
January 30, 2024 05:09
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.
Query: Adds LINQ Support for FirstOrDefault
Description
This change adds LINQ support for Enumerable.FirstOrDefault. At the moment only following overload is supported:
public static TSource? FirstOrDefault<TSource> (this System.Collections.Generic.IEnumerable<TSource> source);
Specifically all of the following overloads are disallowed and suitable error is raised:
public static TSource FirstOrDefault<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,bool> predicate, TSource defaultValue);
public static TSource FirstOrDefault<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, TSource defaultValue);
public static TSource? FirstOrDefault<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,bool> predicate);
Since FirstOrDefault logic cannot entirely be expressed SQL query, it is achieved using a combination of SQL query and client side operation. Generated query in this case is of the form
SELECT TOP 1 VALUE
. CosmosQuery then executes a scalar FirstOrDefault operation on the results returned by the backend for such a query.For e.g.
LINQ Expression:
getQuery(b) .Select(data => data.Flag) .Where(flag => flag) .FirstOrDefault()
SQL Query:
SELECT TOP 1 VALUE root ["Flag"] FROM root WHERE root ["Flag"]
Type of change
Please delete options that are not relevant.
Closing issues
To automatically close an issue: closes #IssueNumber