Repository navigation
ARROW-12763: [R] Optimize dplyr queries that use head/tail after arrange - #11405
nealrichardson wants to merge 4 commits into
Conversation
nealrichardson
commented
Oct 13, 2021
- Uses SelectKSinkNode for head/tail on sorted query. tail() is implemented by reversing the sort orders, taking the top K rows, and then reversing the resulting row order to match as if we had taken the (ordered) bottom K rows.
- Some subtle differences in expectation: row order appears to be locally deterministic (within chunks), but SelectK doesn't necessarily follow that when there are ties. Also, missing value handling by SelectK doesn't match R's expectations--there may be a sort option that isn't handled the same way in the SelectK algorithm (I don't see anywhere else to pass in another option but maybe I missed it)
westonpace
left a comment
There was a problem hiding this comment.
Looks good to me. I don't think it covers pathological cases like airquality %>% arrange(Temp) %>% head(10) %>% arrange(Wind) or airquality %>% head(10) %>% tail(5) but I'm pretty sure that's a given for our current dplyr implementation anyways.
|
|
||
| test_that("tail", { | ||
| batch <- record_batch(tbl) | ||
|
|
There was a problem hiding this comment.
Can you add a test case for a bare tail with no arrange? I think it might be treated as a head but I might not be following the logic right.
There was a problem hiding this comment.
I think there already was one from the last PR.
Those do work, though internally they can't be done in a single ExecPlan: |
Also I will note that neither of those looks pathological to me. Both are similar to queries I've seen in the wild frequently:
|
|
I'm running tpc-h benchmarks against these locally (we haven't yet re-enabled 2-6, 8-10 on conbench) |
Turns out there is a 7.0.0 followup to make TopK more efficient, so this is apparently correct. |
Even then, more efficient in terms of RAM, but not in terms of speed. |
|
Benchmark runs are scheduled for baseline = 8650c23 and contender = 02f11b9. 02f11b9 is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
