-
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 #3165: UriParser - Aggregation method Average doesn't support Int16 #3168
Open
davidKolar175
wants to merge
2
commits into
OData:main
Choose a base branch
from
davidKolar175:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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 |
---|---|---|
|
@@ -838,6 +838,27 @@ public void BindApplyWithGroupByComplexAndTypeCastShouldReturnApplyClause() | |
Assert.Empty(homeNode.ChildTransformations); | ||
} | ||
|
||
[Fact] | ||
public void BindApplyWithAverageWithInt16PropertyShouldReturnApplyClause() | ||
{ | ||
IEnumerable<QueryToken> tokens = _parser.ParseApply("aggregate(FavoriteNumber with average as AverageFavoriteNumber)"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
ApplyBinder binder = new ApplyBinder(FakeBindMethods.BindMethodReturningASingleFloatPrimitive, _bindingState); | ||
ApplyClause actual = binder.BindApply(tokens); | ||
|
||
Assert.NotNull(actual); | ||
AggregateTransformationNode aggregate = Assert.IsType<AggregateTransformationNode>(Assert.Single(actual.Transformations)); | ||
|
||
Assert.Equal(TransformationNodeKind.Aggregate, aggregate.Kind); | ||
Assert.NotNull(aggregate.AggregateExpressions); | ||
|
||
AggregateExpression statement = Assert.IsType<AggregateExpression>(Assert.Single(aggregate.AggregateExpressions)); | ||
Assert.NotNull(statement.Expression); | ||
Assert.Same(FakeBindMethods.FakeSingleFloatPrimitive, statement.Expression); | ||
Assert.Equal(AggregationMethod.Average, statement.Method); | ||
Assert.Equal("AverageFavoriteNumber", statement.Alias); | ||
} | ||
|
||
private static ConstantNode _booleanPrimitiveNode = new ConstantNode(true); | ||
|
||
private static SingleValueNode BindMethodReturnsBooleanPrimitive(QueryToken token) | ||
|
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.
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.
I just realized that the types we support here correspond with to the types supported by the generic
Average
method supported by the framework https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.average?view=net-9.0. There's noAverage
method that accepts a collection of Int16.Furthermore, we'd need to ensure parity with the ASP.NET Core OData library otherwise we'd end up with a bug in the dependent library due to the mappings here:
https://github.com/OData/AspNetCoreOData/blob/0ceeb086e4fd7a6396b4c6e0fd4f123283d55736/src/Microsoft.AspNetCore.OData/Query/ExpressionHelperMethods.cs#L86
We could cast
Int16
toInt32
in order to support your scenario, but we need to discuss this more broadly before moving forward with this change.Finally, I don't think we should add
SByte
andByte
for now. I think such scenarios are much less likely. Either way, this pull request doesn't add tests for those two additions.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.
Alright, I'll wait with the changes to the PR till your response with the result of your discussion. Is that ok?
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.
And just to add my two cents to this conversation. I do know that .NET's
Average
method does not contain sufficient override for Int16, but in my opinion thatis just another bug andUriParser
should be agnostic to this. Why should a parser determine that having average over Int16 is forbidden? Especially whenSum
is supported for Int16 by the parser.Also, even if the types of
sbyte
andbyte
are less common, it still makes sense to average over them.