Indian-boult opened a new issue, #20342:
URL: https://github.com/apache/pinot/issues/20342

   A GROUP BY or DISTINCT on a left side column of a RIGHT or FULL JOIN can 
return the NULL group more than once in the multi-stage engine, with the counts 
split between the copies. It happens with the default planner and with 
`usePhysicalOptimizer=true`, with or without null handling.
   
   With `left_tbl` keys `a, a, b, c, d, e` and `right_tbl` keys `a, b, c, v, w, 
x, y, z`, where `right_tbl.metric_col` is 100 to 800 in that order
   
       SELECT l.key_col, COUNT(*), SUM(r.metric_col)
       FROM left_tbl l RIGHT JOIN right_tbl r ON l.key_col = r.key_col
       GROUP BY l.key_col
   
   returns `[null, 3, 1800]` and `[null, 2, 1200]` as two rows. The right 
answer is one row, `[null, 5, 3000]`. `SELECT DISTINCT l.key_col` over the same 
join returns null twice. With the physical optimizer, `COUNT(*) OVER (PARTITION 
BY l.key_col)` over a LEFT JOIN where `l` is the right side returns 2 for the 
null partition instead of 5.
   
   The unmatched right rows of a RIGHT or FULL join are emitted with null left 
columns on whichever worker holds the right row, so the join output is not hash 
distributed by the left key. `PinotRelDistributionTraitRule.deriveDistribution` 
still gives every join the distribution of its left input. 
`RelToPlanNodeConverter` then marks the aggregate exchange as pre-partitioned 
and skips the shuffle, so each worker builds its own NULL group. The physical 
optimizer does the same in 
`WorkerExchangeAssignmentRule.computeCurrentNodeDistribution`, and 
`inheritDistDescFromInputsForJoin` keeps the right input's distribution for 
LEFT and FULL joins, which splits the null partition of a window the same way.
   
   Closed #17873 was about RIGHT and FULL joins with only non-equi conditions, 
which is a different case.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to