FrankChen021 commented on code in PR #20094:
URL: https://github.com/apache/druid/pull/20094#discussion_r4111377778
##########
sql/src/main/java/org/apache/druid/sql/calcite/rel/DruidCorrelateUnnestRel.java:
##########
@@ -278,7 +279,10 @@ public DruidQuery toDruidQuery(boolean
finalizeAggregations)
}
updatedLeftQuery =
Preconditions.checkNotNull(newLeftDruidRel.toDruidQuery(false), "leftQuery");
- if
(newLeftDruidRel.getPartialDruidQuery().stage().compareTo(PartialDruidQuery.Stage.SELECT_PROJECT)
<= 0) {
+ if (updatedLeftQuery.getQuery() instanceof GroupByQuery) {
Review Comment:
[P1] Grouping can be discarded before this check
**Finding:** This GroupByQuery check runs only after the
FIELD_ACCESS/simple-extraction rewrite above. That rewrite rebuilds
PartialDruidQuery in pq with scan/where/select/sort but without aggregate, so a
grouped left side that exposes an array column, including the issue's ARRAY_AGG
path, can become a scan or scan-project before updatedLeftQuery is inspected.
The check then stays false and the code can feed pre-group rows into UNNEST,
producing duplicate or incorrect nested-array results; the added constant-array
test does not enter this rewrite branch.
**Suggestion:** Preserve the aggregate when rebuilding the left relation, or
capture the grouped query before this rewrite and force that query into a
QueryDataSource; add a regression test that UNNESTs an ARRAY_AGG or other
grouped array result.
--
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]