zhang-arvin opened a new pull request, #20094:
URL: https://github.com/apache/druid/pull/20094

   ## Description
   
   Fixes #17949: UNNEST with nested arrays fails when the left side of the 
correlate contains GROUP BY aggregation.
   
   ### Root Cause
   
   `DruidCorrelateUnnestRel.toDruidQuery()` uses 
`computeLeftRequiresSubquery()` to determine whether to wrap the left query in 
a `QueryDataSource`. However, `computeLeftRequiresSubquery()` only checks the 
`PartialDruidQuery` stage (SCAN), but when UNNEST is pulled up above a GROUP 
BY, the left side may contain grouping/aggregation pushed into the `DruidQuery` 
itself. In this case, `getDataSource()` returns the raw table scan instead of a 
subquery that wraps the aggregation.
   
   ### Fix
   
   Added an additional check in `toDruidQuery()`: when the computed 
`updatedLeftQuery` is a `GroupByQuery` (i.e., contains grouping), wrap it in a 
`QueryDataSource` even if `computeLeftRequiresSubquery()` returns false. This 
ensures the grouping/aggregation logic is preserved in the UNNEST data source.
   
   ### Changes
   
   - 
`sql/src/main/java/org/apache/druid/sql/calcite/rel/DruidCorrelateUnnestRel.java`:
 Added `instanceof GroupByQuery` check in the `toDruidQuery()` method to detect 
when the left query contains grouping, and use `QueryDataSource` accordingly.


-- 
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