This is an automated email from the ASF dual-hosted git repository.

rohangarg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git


The following commit(s) were added to refs/heads/master by this push:
     new 32e8e074aee Planning could have failed if UNION ALL operator was 
completely removed (#16946)
32e8e074aee is described below

commit 32e8e074aee7c2bf69153fd6ddad52725883b5f2
Author: Zoltan Haindrich <[email protected]>
AuthorDate: Mon Sep 2 10:37:10 2024 +0200

    Planning could have failed if UNION ALL operator was completely removed 
(#16946)
---
 .../druid/segment/QueryableIndexCursorHolder.java  |  2 +-
 .../expression/builtin/CastOperatorConversion.java |  5 +-
 .../union_removed_branch_union_nulls.iq            | 66 ++++++++++++++++++++++
 3 files changed, 71 insertions(+), 2 deletions(-)

diff --git 
a/processing/src/main/java/org/apache/druid/segment/QueryableIndexCursorHolder.java
 
b/processing/src/main/java/org/apache/druid/segment/QueryableIndexCursorHolder.java
index 53412bf9da0..5188b385b36 100644
--- 
a/processing/src/main/java/org/apache/druid/segment/QueryableIndexCursorHolder.java
+++ 
b/processing/src/main/java/org/apache/druid/segment/QueryableIndexCursorHolder.java
@@ -77,7 +77,7 @@ public class QueryableIndexCursorHolder implements 
CursorHolder
   @Nullable
   private final Filter filter;
   @Nullable
-  private final QueryMetrics<? extends Query> metrics;
+  private final QueryMetrics<? extends Query<?>> metrics;
   private final List<OrderBy> ordering;
   private final QueryContext queryContext;
   private final int vectorSize;
diff --git 
a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/CastOperatorConversion.java
 
b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/CastOperatorConversion.java
index 7779d1b1747..ac34abe48d1 100644
--- 
a/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/CastOperatorConversion.java
+++ 
b/sql/src/main/java/org/apache/druid/sql/calcite/expression/builtin/CastOperatorConversion.java
@@ -92,10 +92,13 @@ public class CastOperatorConversion implements 
SqlOperatorConversion
                                               ? 
ExpressionType.fromColumnType(fromDruidType)
                                               : 
ExpressionType.fromColumnType(toDruidType);
 
-      if (fromExpressionType == null || toExpressionType == null) {
+      if (toExpressionType == null) {
         // We have no runtime type for these SQL types.
         return null;
       }
+      if (fromExpressionType == null) {
+        return DruidExpression.ofLiteral(toDruidType, 
DruidExpression.nullLiteral());
+      }
 
       final DruidExpression typeCastExpression;
 
diff --git 
a/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/union_removed_branch_union_nulls.iq
 
b/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/union_removed_branch_union_nulls.iq
new file mode 100644
index 00000000000..0711686e9ba
--- /dev/null
+++ 
b/sql/src/test/quidem/org.apache.druid.quidem.SqlQuidemTest/union_removed_branch_union_nulls.iq
@@ -0,0 +1,66 @@
+!set plannerStrategy DECOUPLED
+!set debug true
+!use druidtest://?numMergeBuffers=3
+!set outputformat mysql
+
+(SELECT COUNT(*), "channel" FROM "wikipedia" WHERE
+ added = '31'
+AND __time >= '2024-08-17T00:00:00+00:00' AND 'timestamp' > 1723856628000
+AND __time <= '2024-08-17T00:00:00+00:00' AND 'timestamp' <= 1723855690000
+GROUP BY "channel")
+UNION ALL
+(SELECT null,null)
+;
++--------+---------+
+| EXPR$0 | channel |
++--------+---------+
+|        |         |
++--------+---------+
+(1 row)
+
+!ok
+LogicalUnion(all=[true])
+  LogicalProject(EXPR$0=[$1], channel=[$0])
+    LogicalAggregate(group=[{0}], EXPR$0=[COUNT()])
+      LogicalProject(channel=[$1])
+        LogicalFilter(condition=[AND(=($18, CAST('31'):BIGINT NOT NULL), 
>=($0, CAST('2024-08-17T00:00:00+00:00'):TIMESTAMP(3) NOT NULL), 
>(CAST('timestamp'):BIGINT NOT NULL, 1723856628000), <=($0, 
CAST('2024-08-17T00:00:00+00:00'):TIMESTAMP(3) NOT NULL), 
<=(CAST('timestamp'):BIGINT NOT NULL, 1723855690000))])
+          LogicalTableScan(table=[[druid, wikipedia]])
+  LogicalValues(tuples=[[{ null, null }]])
+
+!convertedPlan
+DruidProject(EXPR$0=[CAST($0):BIGINT], channel=[CAST($1):VARCHAR], 
druid=[logical])
+  DruidValues(tuples=[[{ null, null }]])
+
+!druidPlan
+{
+  "queryType" : "scan",
+  "dataSource" : {
+    "type" : "inline",
+    "columnNames" : [ "EXPR$0", "EXPR$1" ],
+    "rows" : [ [ null, null ] ]
+  },
+  "intervals" : {
+    "type" : "intervals",
+    "intervals" : [ 
"-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ]
+  },
+  "virtualColumns" : [ {
+    "type" : "expression",
+    "name" : "v0",
+    "expression" : "null",
+    "outputType" : "LONG"
+  }, {
+    "type" : "expression",
+    "name" : "v1",
+    "expression" : "null",
+    "outputType" : "STRING"
+  } ],
+  "resultFormat" : "compactedList",
+  "columns" : [ "v0", "v1" ],
+  "columnTypes" : [ "LONG", "STRING" ],
+  "granularity" : {
+    "type" : "all"
+  },
+  "legacy" : false
+}
+!nativePlan
+


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to