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

ODataListBinding: Filter cannot be applied to aggregated property #3997

Open
tofriede opened this issue Mar 11, 2024 · 4 comments
Open

ODataListBinding: Filter cannot be applied to aggregated property #3997

tofriede opened this issue Mar 11, 2024 · 4 comments

Comments

@tofriede
Copy link

OpenUI5 version: 1.121.0

Browser: Google Chrome

URL (minimal example if possible): https://github.com/tofriede/odata-v4-filter-aggregation

Steps to reproduce the problem:

  1. Create a sap.ui.model.odata.v4.ODataListBinding
  2. Aggregate a numeric property
  3. Apply a sap.ui.model.Filter based on the aggregated property

What is the expected result?

The list binding should execute an OData request with the query option $apply, in which the data is aggregated first and then the corresponding filter is applied. The fact that this should be possible is also mentioned in the documentation under Extension for Data Aggregation (section: Filtering).

What happens instead?

Before the request is fired, the ListBinding analyzes the applied filter and tries to determine the type of the aggregated property via the MetaModel. However, this fails because an alias must be used for the aggregation that is not known to the MetaModel, as this is defined on the client side.

image

return oMetaModel.fetchObject(sResolvedPath).then(function (oPropertyMetadata) {

Since the mapping of aliases and original property names is known to the ListBinding (getAggregation), it should also be able to identify the types of aggregated properties.

@ndeshev ndeshev self-assigned this Mar 11, 2024
@ThomasChadzelek ThomasChadzelek self-assigned this Mar 11, 2024
@ThomasChadzelek
Copy link
Member

Hello @tofriede !

Thanks a lot for using OData V4. We apologize for any inconvenience caused.

I confirm the issue you describe. In the meantime, please try to use the system query option $filter : "UnitPrice_avg gt 30"

Best regards,
Thomas

@ThomasChadzelek
Copy link
Member

ThomasChadzelek commented Mar 11, 2024

Our current thinking is that we cannot fix this as a bug easily. The needed type is not at all clear from the information we have. The average of an Edm.Int would normally not be an integer value as well. The OData response will contain the type information, but that is too late. Maybe it can be enhanced in future (and CPOUI5ODATAV4-2518 has been created to keep track of this), but as a next step, we should first improve our docs. Thanks for your understanding.

@ndeshev ndeshev removed their assignment Mar 12, 2024
@tofriede
Copy link
Author

Hello @ThomasChadzelek!

Thanks for the quick response. As far as I can see, the type is only needed to convert the filter values to a suitable literal that is used in the odata url. Since all numeric values are treated the same here (no quotes), using the type of the original property should not cause any problems. The exact type is not really needed at this point.

formatLiteral : function (vValue, sType) {

@ThomasChadzelek
Copy link
Member

ThomasChadzelek commented Mar 12, 2024

"Since all numeric values are treated the same here (no quotes)" - well, that is no strictly true, see Edm.Decimal and Edm.Int64 which are handled as strings in order to avoid loss of precision. But thanks for your suggestion, I will take note and see what we can do about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants