How do I enforce ordering (ORDER BY) in a custom Presto Aggregation Function

筅森魡賤 提交于 2021-01-28 01:45:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!