如何在自定义 Presto 聚合函数中强制执行排序 (ORDER BY) [英] How do I enforce ordering (ORDER BY) in a custom Presto Aggregation Function
问题描述
我正在编写一个自定义 Presto 聚合函数,当(且仅当)值按我聚合的值按升序排序时,该函数会产生正确的结果.即
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.
以下将起作用:
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
在开发 MY_AGG_FUNC
时,有没有办法在内部强制执行 ORDER BY value ASC
而不依赖调用者将其添加到查询中?
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?
作为替代方案,如果用户根本没有指定 ORDER BY(或不正确的排序),有没有办法抛出异常?
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)?
推荐答案
在开发 MY_AGG_FUNC 时,有没有办法在内部强制执行 ORDER BY 值 ASC,而无需依赖调用者将其添加到查询中?
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?
没有办法做到这一点.
作为替代方案,如果用户根本没有指定 ORDER BY(或不正确的排序),有没有办法抛出异常?
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.
这篇关于如何在自定义 Presto 聚合函数中强制执行排序 (ORDER BY)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!