-
Notifications
You must be signed in to change notification settings - Fork 352
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
Fixes #2794: Enable $root path #3157
base: main
Are you sure you want to change the base?
Conversation
5.1.1.14.5 $root The $root literal can be used in expressions to refer to resources of the same service. It can be used as a single-valued expression or within complex or collection literals. Example 108: all employees with the same last name as employee A1235 http://host/service/Employees?$filter=LastName eq $root/Employees('A1245')/LastName Example 109: products ordered by a set of customers, where the set of customers is passed as a JSON array containing the resource paths from $root to each customer. http://host/service/ProductsOrderedBy(Customers=@c)?@c=[$root/Customers('ALFKI'),$root/Customers('BLAUS')]
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.
Copilot reviewed 5 out of 16 changed files in this pull request and generated 2 comments.
Files not reviewed (11)
- src/Microsoft.OData.Client/Microsoft.OData.Client.csproj: Language not supported
- src/Microsoft.OData.Client/PublicAPI/net8.0/PublicAPI.Unshipped.txt: Language not supported
- src/Microsoft.OData.Core/PublicAPI/net8.0/PublicAPI.Unshipped.txt: Language not supported
- src/Microsoft.OData.Core/UriParser/Visitors/ISyntacticTreeVisitor.cs: Evaluated as low risk
- src/Microsoft.OData.Core/UriParser/SyntacticAst/QueryTokenKind.cs: Evaluated as low risk
- src/Microsoft.OData.Core/UriParser/SyntacticAst/RootPathToken.cs: Evaluated as low risk
- src/Microsoft.OData.Core/UriParser/TreeNodeKinds/QueryNodeKind.cs: Evaluated as low risk
- src/Microsoft.OData.Core/UriParser/Visitors/QueryNodeVisitor.cs: Evaluated as low risk
- src/Microsoft.OData.Core/UriParser/Visitors/SyntacticTreeVisitor.cs: Evaluated as low risk
- test/FunctionalTests/Microsoft.OData.Core.Tests/ScenarioTests/UriParser/FilterAndOrderByFunctionalTests.cs: Evaluated as low risk
- test/FunctionalTests/Microsoft.OData.Core.Tests/ScenarioTests/UriParser/ParameterAliasFunctionalTests.cs: Evaluated as low risk
@@ -1064,6 +1064,12 @@ private QueryToken ParsePrimary() | |||
expr = this.ParsePrimaryStart(); | |||
} | |||
|
|||
// Pase the $root path, for example: '$root/people(12)' |
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.
The comment contains a typo: 'Pase' should be 'Parse'.
// Pase the $root path, for example: '$root/people(12)' | |
// Parse the $root path, for example: '$root/people(12)' |
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.
ODataPathSegment lastSegment = path.LastSegment; | ||
if (lastSegment == null) | ||
{ | ||
throw new ODataException("Empty root path is not valid."); |
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.
The error message should be 'An empty root path is not valid.'
throw new ODataException("Empty root path is not valid."); | |
throw new ODataException("An empty root path is not valid."); |
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.
ODataPathSegment lastSegment = path.LastSegment; | ||
if (lastSegment == null) | ||
{ | ||
throw new ODataException("Empty root path is not valid."); |
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.
You can move this string to SRResources
// The $root literal can be used in expressions to refer to resources of the same service. It can be used as a single-valued expression or within complex or collection literals. | ||
if (!lastSegment.SingleResult) | ||
{ | ||
throw new ODataException("The $root literal can be used in expressions to refer to resources of the same service. It can be used as a single-valued expression or within complex or collection literals."); |
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.
Same apply here. Move this string to SRResources
{ | ||
ReadOnlySpan<char> dotIdentifier = this.lexer.ReadDottedIdentifier(false); | ||
rootPathToken.Segments.Add(dotIdentifier.ToString()); | ||
//lexer.NextToken(); |
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.
Should this be uncommented or you can add a comment on the top to explain why it is commented out.
{ | ||
if (parent != null) | ||
{ | ||
throw new ODataException("$root should be the top-level segment"); |
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.
Same apply here.
@@ -0,0 +1,40 @@ | |||
//--------------------------------------------------------------------- | |||
// <copyright file="EndPathToken.cs" company="Microsoft"> |
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.
Should this be RootPathToken.cs
instead of EndPathToken.cs
// <copyright file="EndPathToken.cs" company="Microsoft"> | |
// <copyright file="RootPathToken.cs" company="Microsoft"> | |
IEdmTypeReference typeReference = lastSegment.EdmType == null ? null : lastSegment.EdmType.ToTypeReference(true); | ||
return new RootPathNode(path, typeReference); | ||
|
||
// Keep them for discussion, will remove after discussion. |
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.
Do you want to create an issue on Github to start the discussion around this.
Fixes #2794: Enable $root path
5.1.1.14.5 $root
The $root literal can be used in expressions to refer to resources of the same service. It can be used as a single-valued expression or within complex or collection literals.
Example 108: all employees with the same last name as employee A1235
http://host/service/Employees?$filter=LastName eq $root/Employees('A1245')/LastName
Example 109: products ordered by a set of customers, where the set of customers is passed as a JSON array containing the resource paths from $root to each customer.
http://host/service/ProductsOrderedBy(Customers=@c)?@c=[$root/Customers('ALFKI'),$root/Customers('BLAUS')]