somu-imply commented on code in PR #13799:
URL: https://github.com/apache/druid/pull/13799#discussion_r1127266826


##########
sql/src/main/java/org/apache/druid/sql/calcite/rel/DruidCorrelateUnnestRel.java:
##########
@@ -215,6 +254,26 @@ public DruidQuery toDruidQuery(boolean 
finalizeAggregations)
     );
   }
 
+  private PartialDruidQuery updateCorrPartialQueryFromLeft(PartialDruidQuery 
partialQueryFromLeft)
+  {
+    // The DruidCorrelateRule already creates the project and pushes it on the 
top level
+    // So get select project from partialQuery
+    // The filters are present on the partial query of the left
+    // The group by and having clauses would be on the top level
+    // Same for the sort
+    PartialDruidQuery corrQuery = PartialDruidQuery.create(correlateRel);
+    corrQuery = 
corrQuery.withWhereFilter(partialQueryFromLeft.getWhereFilter())
+                         .withSelectProject(partialQuery.getSelectProject());
+    if (partialQuery.getAggregate() != null) {
+      corrQuery = corrQuery.withAggregate(partialQuery.getAggregate())
+                           .withHavingFilter(partialQuery.getHavingFilter());
+    }
+    if (partialQuery.getSort() != null || partialQuery.getSortProject() != 
null) {
+      corrQuery = corrQuery.withSort(partialQuery.getSort());
+    }
+    return corrQuery;
+  }
+

Review Comment:
   The DruidCorrelateUnnestRule already put the select project on top of the 
correlateRel by adding all the things in right to the left. Also the group by, 
order by on the query are already present on the correlateRel. So we create the 
query by adding the select project (the one which is already projected on top 
with left + right), the filters from the left + aggregates (if present) + sorts 
if present on the top level



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