kgyrtkirk commented on code in PR #17354:
URL: https://github.com/apache/druid/pull/17354#discussion_r1823021823


##########
sql/src/main/java/org/apache/druid/sql/calcite/rel/logical/DruidUnion.java:
##########
@@ -66,24 +70,72 @@ public RelOptCost computeSelfCost(RelOptPlanner planner, 
RelMetadataQuery mq)
   @Override
   public SourceDesc getSourceDesc(PlannerContext plannerContext, 
List<SourceDesc> sources)
   {
-    List<DataSource> dataSources = new ArrayList<>();
-    RowSignature signature = null;
-    for (SourceDesc sourceDesc : sources) {
-      checkDataSourceSupported(sourceDesc.dataSource);
-      dataSources.add(sourceDesc.dataSource);
-      if (signature == null) {
-        signature = sourceDesc.rowSignature;
-      } else {
-        if (!signature.equals(sourceDesc.rowSignature)) {
-          throw DruidException.defensive(
-              "Row signature mismatch in Union inputs [%s] and [%s]",
-              signature,
-              sourceDesc.rowSignature
-          );
+    if (mayUseUnionDataSource(sources)) {
+      List<DataSource> dataSources = new ArrayList<>();
+      RowSignature signature = null;
+      for (SourceDesc sourceDesc : sources) {
+        checkDataSourceSupported(sourceDesc.dataSource);
+        dataSources.add(sourceDesc.dataSource);
+        if (signature == null) {
+          signature = sourceDesc.rowSignature;
+        } else {
+          if (!signature.equals(sourceDesc.rowSignature)) {
+            throw DruidException.defensive(
+                "Row signature mismatch in Union inputs [%s] and [%s]",
+                signature,
+                sourceDesc.rowSignature
+            );
+          }
+        }
+      }
+      return new SourceDesc(new UnionDataSource(dataSources), signature);
+    }
+    if (mayUseUnionQuery(sources)) {
+      RowSignature signature = null;
+      List<Query<?>> queries = new ArrayList<>();
+      for (SourceDesc sourceDesc : sources) {
+        QueryDataSource qds = (QueryDataSource) sourceDesc.dataSource;
+        queries.add(qds.getQuery());
+        if (signature == null) {
+          signature = sourceDesc.rowSignature;
+        } else {
+          if (!signature.equals(sourceDesc.rowSignature)) {
+            throw DruidException.defensive(
+                "Row signature mismatch in Union inputs [%s] and [%s]",
+                signature,
+                sourceDesc.rowSignature
+            );
+          }
         }
       }
+      return new SourceDesc(new QueryDataSource(new UnionQuery(queries)), 
signature);
+    }
+
+    throw DruidException.defensive("XXXOnly Table and Values are supported as 
inputs for Union [%s]", sources);
+  }

Review Comment:
   this should not happen - the exception was placed here in case some odd 
thing happens...
   updated the exception message



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