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 #3165: UriParser - Aggregation method Average doesn't support Int16 #3168

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

davidKolar175
Copy link

Issues

This pull request fixes issue where the problem was that during the parsing of average aggregation function the parser could throw an exception saying that it does not support int16. (Or Byte and SByte for that matter)

Description

Easy fix that required just adding few cases into a switch.

Checklist (Uncheck if it is not completed)

  • Test cases added
  • Build and test with one-click build and test script passed (No since I don't have VS 2019 :/ but in VS 2020 no additional tests failed)

Additional work necessary

None

@davidKolar175
Copy link
Author

@microsoft-github-policy-service agree company="TescoSW"

@xuzhg
Copy link
Member

xuzhg commented Jan 23, 2025

The change looks straightforward, do you mind to add test to cover the changes?

@davidKolar175
Copy link
Author

Hello @xuzhg, the test has been added. ;)

@davidKolar175
Copy link
Author

@xuzhg Can I have a question? When will this change, after merging into master, be published in the new nuget version? Is it in matter of days or weeks? Also will I have to create PRs into other branches? Thanks

Comment on lines +179 to +181
case EdmPrimitiveTypeKind.SByte:
case EdmPrimitiveTypeKind.Byte:
case EdmPrimitiveTypeKind.Int16:
Copy link
Contributor

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 no Average 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 to Int32 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 and Byte for now. I think such scenarios are much less likely. Either way, this pull request doesn't add tests for those two additions.

Copy link
Author

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?

Copy link
Author

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 and UriParser should be agnostic to this. Why should a parser determine that having average over Int16 is forbidden? Especially when Sum is supported for Int16 by the parser.

Also, even if the types of sbyte and byte are less common, it still makes sense to average over them.

[Fact]
public void BindApplyWithAverageWithInt16PropertyShouldReturnApplyClause()
{
IEnumerable<QueryToken> tokens = _parser.ParseApply("aggregate(FavoriteNumber with average as AverageFavoriteNumber)");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FavoriteNumber is defined as UInt16 in the referenced Edm model. I'd advise that we also add a test for Int16 to cover all our bases

@WanjohiSammy
Copy link
Contributor

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.

UriParser - Aggregation method Average doesn't support Int16
4 participants