You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2020/03/20 01:51:46 UTC

[incubator-doris] branch master updated: [Bug] Fix bug that of union statement (#3137)

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

morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 12d1b07  [Bug] Fix bug that of union statement (#3137)
12d1b07 is described below

commit 12d1b072ef7b42cadead89d69d36763973e1620c
Author: yangzhg <78...@qq.com>
AuthorDate: Fri Mar 20 09:51:38 2020 +0800

    [Bug] Fix bug that of union statement (#3137)
    
    fix a bug of const union query like `select null union select null`, this because the type of SlotDescriptor when clause is `select null` is null ,this will cause BE core dump, and FE find wrong cast function.
---
 be/src/runtime/raw_value.cpp                                     | 5 ++++-
 fe/src/main/java/org/apache/doris/analysis/CastExpr.java         | 6 +++---
 fe/src/main/java/org/apache/doris/analysis/SetOperationStmt.java | 9 ++++++++-
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/be/src/runtime/raw_value.cpp b/be/src/runtime/raw_value.cpp
index 3f2c36d..c0fa6fb 100644
--- a/be/src/runtime/raw_value.cpp
+++ b/be/src/runtime/raw_value.cpp
@@ -216,7 +216,10 @@ void RawValue::print_value(const void* value, const TypeDescriptor& type, int sc
         str->swap(tmp);
         return;
     }
-
+    case TYPE_NULL: {
+        *str = "NULL";
+        return;
+    }
     default:
         print_value(value, type, scale, &out);
     }
diff --git a/fe/src/main/java/org/apache/doris/analysis/CastExpr.java b/fe/src/main/java/org/apache/doris/analysis/CastExpr.java
index 072ef8e..2dafc9f 100644
--- a/fe/src/main/java/org/apache/doris/analysis/CastExpr.java
+++ b/fe/src/main/java/org/apache/doris/analysis/CastExpr.java
@@ -103,12 +103,12 @@ public class CastExpr extends Expr {
                 if (fromType.isStringType() && toType.isBoolean()) {
                     continue;
                 }
-                // Disable casting from boolean to decimal
+                // Disable casting from boolean to decimal or datetime or date
                 if (fromType.isBoolean() &&
-                        (toType == Type.DECIMAL || toType == Type.DECIMALV2)) {
+                        (toType == Type.DECIMAL || toType == Type.DECIMALV2 ||
+                                toType == Type.DATETIME || toType == Type.DATE)) {
                     continue;
                 }
-
                 // Disable no-op casts
                 if (fromType.equals(toType)) {
                     continue;
diff --git a/fe/src/main/java/org/apache/doris/analysis/SetOperationStmt.java b/fe/src/main/java/org/apache/doris/analysis/SetOperationStmt.java
index 75237d2..58b6178 100644
--- a/fe/src/main/java/org/apache/doris/analysis/SetOperationStmt.java
+++ b/fe/src/main/java/org/apache/doris/analysis/SetOperationStmt.java
@@ -188,6 +188,11 @@ public class SetOperationStmt extends QueryStmt {
         super.analyze(analyzer);
         Preconditions.checkState(operands.size() > 0);
 
+        // the first operand's operation usually null
+        if (operands.get(0).operation == null && operands.size() > 1) {
+            operands.get(0).setOperation(operands.get(1).getOperation());
+        }
+
         // Propagates DISTINCT from left to right,
         propagateDistinct();
 
@@ -649,7 +654,9 @@ public class SetOperationStmt extends QueryStmt {
             if (isAnalyzed()) {
                 return;
             }
-            if (queryStmt instanceof SelectStmt && ((SelectStmt) queryStmt).fromClause_.isEmpty()) {
+            // union statement support const expr, so not need to rewrite
+            if (operation != Operation.UNION && queryStmt instanceof SelectStmt
+                    && ((SelectStmt) queryStmt).fromClause_.isEmpty()) {
                 // rewrite select 1 to select * from (select 1) __DORIS_DUAL__ , because when using select 1 it will be
                 // transformed to a union node, select 1 is a literal, it doesn't have a tuple but will produce a slot,
                 // this will cause be core dump


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