You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2021/12/02 13:08:31 UTC

[GitHub] [druid] LakshSingla commented on a change in pull request #12017: Fix the error case when there are multi top level unions

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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org