-
Notifications
You must be signed in to change notification settings - Fork 357
Fix 'isof' and 'cast' unquoted type params issue #3117
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
Conversation
src/Microsoft.OData.Core/UriParser/Binders/FunctionCallBinder.cs
Outdated
Show resolved
Hide resolved
...lTests/Microsoft.OData.Core.Tests/ScenarioTests/UriParser/FilterAndOrderByFunctionalTests.cs
Outdated
Show resolved
Hide resolved
...lTests/Microsoft.OData.Core.Tests/ScenarioTests/UriParser/FilterAndOrderByFunctionalTests.cs
Outdated
Show resolved
Hide resolved
...lTests/Microsoft.OData.Core.Tests/ScenarioTests/UriParser/FilterAndOrderByFunctionalTests.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.OData.Core/UriParser/Binders/FunctionCallBinder.cs
Outdated
Show resolved
Hide resolved
...ctionalTests/Microsoft.OData.Core.Tests/ScenarioTests/UriParser/EnumFilterFunctionalTests.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.OData.Core/UriParser/Binders/FunctionCallBinder.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.OData.Core/UriParser/Binders/FunctionCallBinder.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.OData.Core/UriParser/Binders/FunctionCallBinder.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.OData.Core/UriParser/Binders/FunctionCallBinder.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.OData.Core/UriParser/Binders/FunctionCallBinder.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.OData.Core/UriParser/Binders/FunctionCallBinder.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.OData.Core/UriParser/Binders/FunctionCallBinder.cs
Outdated
Show resolved
Hide resolved
bdf86ef to
f2c4d60
Compare
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 4 out of 4 changed files in this pull request and generated no suggestions.
|
/AzurePipelines run |
|
No pipelines are associated with this pull request. |
|
@WanjohiSammy the issues listed in the description that this PR aims to fix happen to be closed. What is the exact behaviour that this PR aims to change or rectify? Is it to support case-insensitivity in the |
…t to check for case-insensitive
src/Microsoft.OData.Core/UriParser/Parsers/FunctionCallParser.cs
Outdated
Show resolved
Hide resolved
In my view, it makes more sense to return an empty collection or false if the types are not related rather than to throw an error. The same way |
| /// Provides efficient push, pop, and peek operations with dynamic resizing. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of elements in the stack.</typeparam> | ||
| internal struct StackStruct<T> |
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.
This is only light-weight in the wrapper StackStruct is a struct and not an object. So it may save one allocation, but you still use a heap allocated array even for the base case. So It's not really much different from a regular Stack and I don't think it's worth creating a custom type.
This is different from the version I proposed which would use an inline array buffer (e.g. using InlineArray attribute, could use fixed array buffer, but the latter is unsafe and limited to simple primitive types).
But I wouldn't want to block this PR because of this. My suggestion would be to remove this altogether (since it doesn't provide much optimization over a standard Stack, then we can think of a lightweight stack helper in a separate PR that can be used across the codebase)
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.
@habbes I have reverted to use the regular stack
src/Microsoft.OData.Core/UriParser/Resolver/NormalizedModelElementsCache.cs
Outdated
Show resolved
Hide resolved
…mentsCache.cs Co-authored-by: Clément Habinshuti <[email protected]>
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.
Pull Request Overview
This pull request fixes the handling of unquoted type parameters in OData 'isof' and 'cast' functions to align with the OData V4 specification, which allows type parameters to be used without quotes.
Key changes include:
- Adding support for
SingleResourceCastNodehandling in theValidateIsOfOrCastmethod - Updating the
FunctionCallParserto properly link unquoted type parameters with their corresponding expression parameters through theNextTokenproperty - Ensuring primitive type parameters (like
Edm.Int32) are bound asConstantNodeinstead ofSingleValueCastNodewhen unquoted
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
FunctionCallParser.cs |
Enhanced argument parsing logic to handle unquoted type parameters in cast/isof functions by setting proper parent-child relationships |
FunctionCallBinder.cs |
Added support for SingleResourceCastNode in type validation and improved case-insensitive string comparison |
NormalizedModelElementsCache.cs |
Added shared cache instance for EDM core model to support primitive type detection |
| Test files | Comprehensive test coverage for both quoted and unquoted type parameters with various case sensitivity scenarios |
| return new ODataQueryOptionParser(edmModel, entityType, edmEntitySet, new Dictionary<string, string>() { { "$filter", text } }).ParseFilter(); | ||
| } | ||
|
|
||
| private FilterClause ParseFilter(string text, bool caseInsensitive, IEdmModel edmModel, IEdmEntityType edmEntityType, IEdmEntitySet edmEntitySet) | ||
| { | ||
| return new ODataQueryOptionParser(edmModel, entityType, edmEntitySet, new Dictionary<string, string>() { { "$filter", text } }) |
Copilot
AI
Aug 8, 2025
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 method parameter 'edmEntityType' is used but the local variable 'entityType' is passed to the constructor. This should be 'edmEntityType' to match the parameter name and avoid potential confusion.
| return new ODataQueryOptionParser(edmModel, entityType, edmEntitySet, new Dictionary<string, string>() { { "$filter", text } }).ParseFilter(); | |
| } | |
| private FilterClause ParseFilter(string text, bool caseInsensitive, IEdmModel edmModel, IEdmEntityType edmEntityType, IEdmEntitySet edmEntitySet) | |
| { | |
| return new ODataQueryOptionParser(edmModel, entityType, edmEntitySet, new Dictionary<string, string>() { { "$filter", text } }) | |
| return new ODataQueryOptionParser(edmModel, edmEntityType, edmEntitySet, new Dictionary<string, string>() { { "$filter", text } }).ParseFilter(); | |
| } | |
| private FilterClause ParseFilter(string text, bool caseInsensitive, IEdmModel edmModel, IEdmEntityType edmEntityType, IEdmEntitySet edmEntitySet) | |
| { | |
| return new ODataQueryOptionParser(edmModel, edmEntityType, edmEntitySet, new Dictionary<string, string>() { { "$filter", text } }) |
* Add support for unquoted type params in `isof` and `cast` methods --------- Co-authored-by: Clément Habinshuti <[email protected]>
* Add support for unquoted type params in `isof` and `cast` methods --------- Co-authored-by: Clément Habinshuti <[email protected]>
* Add support for unquoted type params in `isof` and `cast` methods --------- Co-authored-by: Clément Habinshuti <[email protected]>
Issues
This pull request fixes #1744.
Description
According to OData V4 spec
isofandcastfunction type parameter can be used without enclosed in quotes.The isof function has the following signatures
This update supports unquoted type parameters in
isofandcastfunctions through the following changes:SingleResourceCastNodeinValidateIsOfOrCastmethod since the unquoted type parameter is bind as SingleResourceCastNodeisofandcastfunction calls with two parameters, where the second parameter is an unquoted type parameter. For two parameters, the second unquoted type parameter's next token should point to the first parameter. Previously, this was only handled for quoted type parameters. The change has now been made to include unquoted type parameters as well.For example,
isof()function.With this change, the following queries with unquoted type param are now supported:
Lets say you have the following data model:
Executing the query
isof(NS.DerivedCategory)will throw the exception:This occurs because ODL checks if
NS.Productis related toNS.Categoryusing the CheckRelatedTo function and since the types are not related or one is not a derivative of the other, the exception is thrown.Main changes
This change aims to fix issue #3123 by binding the
EdmPrimitiveType DottedIdentifierTokentoConstantNodeinstead ofSingleValueCastNode. This is by ensuring that thenextTokenof the EdmPrimitiveType DottedIdentifierToken (e.g., Edm.Int64, Edm.String, Edm.Single, etc.) is null if the DottedIdentifierToken is a primitive type even ifcastorisofhas 2 arguments e.g,cast(ID, Edm.Int32) lt 10,isof(MyAddress, Fully.Qualified.Namespace.HomeAddress), etcChecklist (Uncheck if it is not completed)
Additional work necessary
If documentation update is needed, please add "Docs Needed" label to the issue and provide details about the required document change in the issue.