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

Aggregation.default is mandatory for custom aggregate #1652

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions advanced/odata.md
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,7 @@ GET /Books?$apply=aggregate(stock with sum as stock) HTTP/1.1
#### Currencies and Units of Measure

If a property represents a monetary amount, it may have a related property that indicates the amount's *currency code*. Analogously, a property representing a measured quantity can be related to a *unit of measure*. To indicate that a property is a currency code or a unit of measure it can be annotated with the [Semantics Annotations](https://help.sap.com/docs/SAP_NETWEAVER_750/cc0c305d2fab47bd808adcad3ca7ee9d/fbcd3a59a94148f6adad80b9c97304ff.html) `@Semantics.currencyCode` or `@Semantics.unitOfMeasure`.
Copy link
Contributor

Choose a reason for hiding this comment

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

The documentation behind this link is not maintained anymore. We should replace the link with one of the options (at least that's what I found):

Suggested change
If a property represents a monetary amount, it may have a related property that indicates the amount's *currency code*. Analogously, a property representing a measured quantity can be related to a *unit of measure*. To indicate that a property is a currency code or a unit of measure it can be annotated with the [Semantics Annotations](https://help.sap.com/docs/SAP_NETWEAVER_750/cc0c305d2fab47bd808adcad3ca7ee9d/fbcd3a59a94148f6adad80b9c97304ff.html) `@Semantics.currencyCode` or `@Semantics.unitOfMeasure`.
If a property represents a monetary amount, it may have a related property that indicates the amount's *currency code*. Analogously, a property representing a measured quantity can be related to a *unit of measure*. To indicate that a property is a currency code or a unit of measure it can be annotated with the [Semantics Annotations](https://help.sap.com/docs/ABAP_PLATFORM_NEW/fc4c71aa50014fd1b43721701471913d/3ccd5cf7b98248618b1013a4a296e415.html) `@Semantics.currencyCode` or `@Semantics.unitOfMeasure`.

or

Suggested change
If a property represents a monetary amount, it may have a related property that indicates the amount's *currency code*. Analogously, a property representing a measured quantity can be related to a *unit of measure*. To indicate that a property is a currency code or a unit of measure it can be annotated with the [Semantics Annotations](https://help.sap.com/docs/SAP_NETWEAVER_750/cc0c305d2fab47bd808adcad3ca7ee9d/fbcd3a59a94148f6adad80b9c97304ff.html) `@Semantics.currencyCode` or `@Semantics.unitOfMeasure`.
If a property represents a monetary amount, it may have a related property that indicates the amount's *currency code*. Analogously, a property representing a measured quantity can be related to a *unit of measure*. To indicate that a property is a currency code or a unit of measure it can be annotated with the [Semantics Annotations](https://help.sap.com/docs/SAP_HANA_PLATFORM/691cb949c1034198800afde3e5be6570/57f00f85b92c4ee9a8b069f212b59573.html?locale=en-US&version=2.0.08&) `@Semantics.currencyCode` or `@Semantics.unitOfMeasure`.

Copy link
Contributor

Choose a reason for hiding this comment

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

I honestly don't know where the @Semantics annotations are specified.

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Where is the difference between @Semantics.currencyCode and @Semantics.amount.currencyCode, if there is any?

Copy link
Contributor

@agoerler agoerler Feb 20, 2025

Choose a reason for hiding this comment

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

@Semantics.currencyCode declares that the annotated element is a currency [code]

@Semantics.amount.currencyCode relates an annotated element, the amount, to the element that holds the currency [code] for this amount

Copy link
Author

Choose a reason for hiding this comment

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

These annotations determine how the backend (i.e. CAP) should aggregate values.

That is true for @Semantics.amount.currencyCode, but not for @Semantics.currencyCode. The latter can appear on a currency field like "Preferred currency of a customer", even in the absence of any amount fields.

Copy link
Contributor

Choose a reason for hiding this comment

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

@agoerler If there is no perfect fit, I think it's fair to think about documenting it ourselves. But that would be some effort, right? Who should be involved? I guess it's not just about duplicating the RAP docs, or?

Copy link
Contributor

Choose a reason for hiding this comment

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

@HeikoTheissen

What about

@Meassure.ISOCurrency ?

Would this be a standard conform way to express the same intent?

Copy link
Author

Choose a reason for hiding this comment

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

No, @Measure.ISOCurrency targets an amount and its value is the currency.
@Semantics.currency targets a currency and its value is a Boolean.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought as "replacement" for @Semantics.amount.currencyCode, which targets an amount and references the currency property.

The aggregation method (typically, sum) is specified with the `@Aggregation.default` annotation.

```cds
@Aggregation.CustomAggregate#amount : 'Edm.Decimal'
Expand All @@ -1195,6 +1196,7 @@ entity Sales {
key id : GUID;
productId : GUID;
@Semantics.amount.currencyCode: 'currency'
@Aggregation.default: #SUM
amount : Decimal(10,2);
@Semantics.currencyCode
currency : String(3);
Expand Down