Commit e12b4ff
Add support for multiarg lambdas in array_sort (facebookincubator#13387)
Summary:
Pull Request resolved: facebookincubator#13387
This change aims to add support for array_sort with lambda that can take multiple arguments. Currently Velox tries to convert any multiple argument lambda to a single argument one using SimpleMatcher. This works for a large majority of the cases and is pretty fast, however there are still significant number of cases where we still require support for true multiple arguments in the lambda.
This preliminary PR supports that use case ; We do this by evaluating the lambda for all the argument vectors in an iteration. In every iteration we keep one of the arguments constant for an array and compare it to the rest of its array. This gives us the position of the constant element wrt to the other elements in the array. We can do this N times to sort the array.
To illustrate, say lambda takes two arguments, say x, y.
We will map y to the elements of the array A and assign x as A[i] for iteration i.
Thus in the ith iteration we will compare x[i] against every y (i.e every element in A).
At the end of each iteration, based on the number of -1, 0, 1's we will know the position of the element at index i.
NOTE:
1. This implementation requires that the lambda always return -1, 0, or 1. This is enforced by Presto Java too.
2. This implementation has a further restriction that for the lambda f, f(a,a) => 0 when a = a.
3. This implementation aims to rewrite the lambda to the single lambda arg case failing which it uses the multi arg lambda.
4. This implementation also only supports 1 lambda entry and not multiple lambda entries.
Differential Revision: D748523551 parent 4a55e54 commit e12b4ff
File tree
6 files changed
+415
-46
lines changed- velox
- core
- expression
- tests
- functions/prestosql
- tests
- vector
6 files changed
+415
-46
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
598 | 598 | | |
599 | 599 | | |
600 | 600 | | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
601 | 608 | | |
602 | 609 | | |
603 | 610 | | |
| |||
1089 | 1096 | | |
1090 | 1097 | | |
1091 | 1098 | | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
1092 | 1103 | | |
1093 | 1104 | | |
1094 | 1105 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
79 | 83 | | |
80 | 84 | | |
81 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
312 | 317 | | |
313 | 318 | | |
314 | 319 | | |
| |||
0 commit comments