LakshSingla commented on a change in pull request #12017:
URL: https://github.com/apache/druid/pull/12017#discussion_r761075609



##########
File path: 
sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidPlanner.java
##########
@@ -431,25 +431,26 @@ private PlannerResult planExplanation(
    */
   private String explainSqlPlanAsNativeQueries(DruidRel<?> rel) throws 
JsonProcessingException
   {
-    // Only if rel is an instance of DruidUnionRel, do we run multiple native 
queries corresponding to single SQL query
-    // Also, DruidUnionRel can only be a top level node, so we don't need to 
check for this condition in the subsequent
-    // child nodes
     ObjectMapper jsonMapper = plannerContext.getJsonMapper();
     List<DruidQuery> druidQueryList;
-    if (rel instanceof DruidUnionRel) {
-      druidQueryList = rel.getInputs().stream().map(childRel -> (DruidRel<?>) 
childRel).map(childRel -> {
-        if (childRel instanceof DruidUnionRel) {
-          log.error("DruidUnionRel can only be the outermost RelNode. This 
error shouldn't be encountered");
-          throw new ISE("DruidUnionRel is only supported at the outermost 
RelNode.");
-        }
-        return childRel.toDruidQuery(false);
-      }).collect(Collectors.toList());
-    } else {
-      druidQueryList = ImmutableList.of(rel.toDruidQuery(false));
+    try {
+      druidQueryList = flattenOutermostRel(rel)
+          .stream()
+          .map(druidRel -> druidRel.toDruidQuery(false))
+          .collect(Collectors.toList());
+
+    }
+    catch (UnsupportedOperationException unsupportedOperationException) {

Review comment:
       `DruidUnionRel` throws it for unsupported operations: 
`https://github.com/apache/druid/blob/1f95a42bb8b32c314934e8e2ecdeb6569c7e8db3/sql/src/main/java/org/apache/druid/sql/calcite/rel/DruidUnionRel.java#L125`
 (Those operations which can be done on queries which translate directly to 
native queries). Here `toDruidQuery` can throw the exception.




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