Commit 1e3fbf2
Add array_sort() and array_sort_desc() with lambda support for key extraction
This commit introduces a new overloaded functions
1. array_sort() that accepts an array and a lambda expression to extract sort keys, then sorts the array in ascending order based on those keys.
2. array_sort_desc() that accepts an array and a lambda expression to extract sort keys, then sorts the array in descending order based on those keys.
Such as,
array_sort(ARRAY['hello', 'hi', 'world'], x -> length(x))
-- Returns: ['hi', 'hello', 'world']
array_sort(ARRAY[row('apples', 23), row('bananas', 12)], x -> x[2])
-- Returns: [row('bananas', 12), row('apples', 23)]
array_sort_desc(ARRAY['hello', 'hi', 'world'], x -> length(x))
-- Returns: ['hello', 'world', 'hi']
array_sort_desc(ARRAY[row('apples', 23), row('bananas', 12)], x -> x[2])
-- Returns: [row('apples', 23), row('bananas', 12)]
The implementation leverages the same code generation approach to optimize key extraction based on element and key types.1 parent ecf1344 commit 1e3fbf2
6 files changed
Lines changed: 820 additions & 4 deletions
File tree
- presto-docs/src/main/sphinx/functions
- presto-main-base/src
- main/java/com/facebook/presto
- metadata
- operator/scalar
- test/java/com/facebook/presto/operator/scalar
- presto-native-sidecar-plugin/src/test/java/com/facebook/presto/sidecar
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
201 | 213 | | |
202 | 214 | | |
203 | 215 | | |
| |||
207 | 219 | | |
208 | 220 | | |
209 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
210 | 234 | | |
211 | 235 | | |
212 | 236 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
| |||
883 | 884 | | |
884 | 885 | | |
885 | 886 | | |
| 887 | + | |
| 888 | + | |
886 | 889 | | |
887 | 890 | | |
888 | 891 | | |
| |||
0 commit comments