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

Fixes #2794: Enable $root path #3157

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Fixes #2794: Enable $root path #3157

wants to merge 1 commit into from

Conversation

xuzhg
Copy link
Member

@xuzhg xuzhg commented Dec 23, 2024

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')]

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')]
Copy link

@Copilot Copilot AI left a 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)'
Copy link
Preview

Copilot AI Dec 23, 2024

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'.

Suggested change
// 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.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
ODataPathSegment lastSegment = path.LastSegment;
if (lastSegment == null)
{
throw new ODataException("Empty root path is not valid.");
Copy link
Preview

Copilot AI Dec 23, 2024

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.'

Suggested change
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.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
ODataPathSegment lastSegment = path.LastSegment;
if (lastSegment == null)
{
throw new ODataException("Empty root path is not valid.");
Copy link
Contributor

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.");
Copy link
Contributor

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();
Copy link
Contributor

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");
Copy link
Contributor

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">
Copy link
Contributor

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

Suggested change
// <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.
Copy link
Contributor

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.

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.

$root literal
2 participants