-
Notifications
You must be signed in to change notification settings - Fork 524
Query: Adds DOCUMENTID extension method for LINQ #4489
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
microsoft-github-policy-service
merged 14 commits into
master
from
users/leminh/DocumentIdExtensionMethod
Jun 4, 2024
Merged
Changes from 6 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
19c2c20
Add extension method for doucmentid
37ea718
test coverage
7746749
additional test
014a6c3
Merge branch 'master' into users/leminh/DocumentIdExtensionMethod
fc53112
update contract
c71a2d4
update dotnet api
fc98b78
address code review
290cac6
Merge branch 'master' into users/leminh/DocumentIdExtensionMethod
leminh98 8fbc83c
Merge branch 'master' into users/leminh/DocumentIdExtensionMethod
leminh98 6f098cb
update csproj file
6e9fd7d
Merge branch 'users/leminh/DocumentIdExtensionMethod' of https://gith…
e9d11be
Merge branch 'master' into users/leminh/DocumentIdExtensionMethod
leminh98 de4fbf6
update missing baseline
9d47cb5
Merge branch 'users/leminh/DocumentIdExtensionMethod' of https://gith…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
38 changes: 38 additions & 0 deletions
38
Microsoft.Azure.Cosmos/src/Linq/BuiltinFunctions/OtherBuiltinSystemFunctions.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| //------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| //------------------------------------------------------------ | ||
|
|
||
| namespace Microsoft.Azure.Cosmos.Linq | ||
| { | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Globalization; | ||
| using System.Linq.Expressions; | ||
| using Microsoft.Azure.Cosmos.SqlObjects; | ||
|
|
||
| internal static class OtherBuiltinSystemFunctions | ||
| { | ||
| private static Dictionary<string, BuiltinFunctionVisitor> FunctionsDefinitions { get; set; } | ||
|
|
||
| static OtherBuiltinSystemFunctions() | ||
| { | ||
| FunctionsDefinitions = new Dictionary<string, BuiltinFunctionVisitor> | ||
| { | ||
| [nameof(CosmosLinqExtensions.DocumentId)] = new SqlBuiltinFunctionVisitor( | ||
| "DOCUMENTID", | ||
| true, | ||
| new List<Type[]>() | ||
| { | ||
| new Type[]{typeof(object)}, | ||
| }) | ||
| }; | ||
| } | ||
|
|
||
| public static SqlScalarExpression Visit(MethodCallExpression methodCallExpression, TranslationContext context) | ||
| { | ||
| return FunctionsDefinitions.TryGetValue(methodCallExpression.Method.Name, out BuiltinFunctionVisitor visitor) | ||
| ? visitor.Visit(methodCallExpression, context) | ||
| : throw new DocumentQueryException(string.Format(CultureInfo.CurrentCulture, ClientResources.MethodNotSupported, methodCallExpression.Method.Name)); | ||
| } | ||
| } | ||
| } | ||
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
50 changes: 50 additions & 0 deletions
50
.../BaselineTest/TestBaseline/LinqTranslationBaselineTests.TestDocumentIdBuiltinFunction.xml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| <Results> | ||
| <Result> | ||
| <Input> | ||
| <Description><![CDATA[In Select clause]]></Description> | ||
| <Expression><![CDATA[query.Select(doc => doc.DocumentId())]]></Expression> | ||
| </Input> | ||
| <Output> | ||
| <SqlQuery><![CDATA[ | ||
| SELECT VALUE DOCUMENTID(root) | ||
| FROM root]]></SqlQuery> | ||
| </Output> | ||
| </Result> | ||
| <Result> | ||
| <Input> | ||
| <Description><![CDATA[In Filter clause]]></Description> | ||
| <Expression><![CDATA[query.Where(doc => (doc.DocumentId() > 123))]]></Expression> | ||
| </Input> | ||
| <Output> | ||
| <SqlQuery><![CDATA[ | ||
| SELECT VALUE root | ||
| FROM root | ||
| WHERE (DOCUMENTID(root) > 123)]]></SqlQuery> | ||
| </Output> | ||
| </Result> | ||
| <Result> | ||
| <Input> | ||
| <Description><![CDATA[With non root term]]></Description> | ||
| <Expression><![CDATA[query.Where(doc => (Convert(doc.BooleanField, Object).DocumentId() > 123))]]></Expression> | ||
| </Input> | ||
| <Output> | ||
| <SqlQuery><![CDATA[ | ||
| SELECT VALUE root | ||
| FROM root | ||
| WHERE (DOCUMENTID(root["BooleanField"]) > 123)]]></SqlQuery> | ||
| </Output> | ||
| </Result> | ||
leminh98 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <Result> | ||
| <Input> | ||
| <Description><![CDATA[In Order by clause]]></Description> | ||
| <Expression><![CDATA[query.OrderBy(doc => doc.DocumentId())]]></Expression> | ||
| </Input> | ||
| <Output> | ||
| <SqlQuery><![CDATA[ | ||
| SELECT VALUE root | ||
| FROM root | ||
| ORDER BY DOCUMENTID(root) ASC]]></SqlQuery> | ||
| <ErrorMessage><![CDATA[Status Code: BadRequest,{"errors":[{"severity":"Error","code":2206,"message":"Unsupported ORDER BY clause. ORDER BY item expression could not be mapped to a document path."}]},0x800A0B00]]></ErrorMessage> | ||
| </Output> | ||
| </Result> | ||
| </Results> | ||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.