问题
I am writing a custom Presto Aggregation Function that produces the correct result if (and only if) the values are ordered in ascending order by the value that I am aggregating on. i.e.
The following will work:
SELECT key, MY_AGG_FUNC(value ORDER BY value ASC) FROM my_table GROUP BY key
The following will yield an incorrect result:
SELECT key, MY_AGG_FUNC(value) FROM my_table GROUP BY key
When developing the MY_AGG_FUNC
, is there a way to enforce ORDER BY value ASC
internally without relying on the caller to add it to the query?
As an alternative, is there a way to throw an Exception if the user does not specify the ORDER BY at all (or an incorrect ordering)?
回答1:
When developing the MY_AGG_FUNC, is there a way to enforce ORDER BY value ASC internally without relying on the caller to add it to the query?
There is no way to do that.
As an alternative, is there a way to throw an Exception if the user does not specify the ORDER BY at all (or an incorrect ordering)?
There is no way to do that, other than checking within the aggregation function implementation that received values are in ascending order.
来源:https://stackoverflow.com/questions/65373894/how-do-i-enforce-ordering-order-by-in-a-custom-presto-aggregation-function