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 2023/03/09 15:53:45 UTC

[doris] 07/10: [fix](planner) insert default value should not change return type of function object in function set (#17536)

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

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

commit 2f095c657fd2bef3bf8f44662774cd0ef1840e9f
Author: morrySnow <10...@users.noreply.github.com>
AuthorDate: Wed Mar 8 17:08:28 2023 +0800

    [fix](planner) insert default value should not change return type of function object in function set (#17536)
    
    function now's return type changed to datetimev2 by mistake.
    It can be reproduced in the following way
    
    CREATE TABLE `testdt` (
      `c1` int(11) NULL,
      `c2` datetimev2 NULL DEFAULT CURRENT_TIMESTAMP
    ) ENGINE=OLAP
    DUPLICATE KEY(`c1`, `c2`)
    COMMENT 'OLAP'
    DISTRIBUTED BY HASH(`c1`) BUCKETS 10
    PROPERTIES (
    "replication_allocation" = "tag.location.default: 1",
    "in_memory" = "false",
    "storage_format" = "V2",
    "light_schema_change" = "true",
    "disable_auto_compaction" = "false"
    );
    
     insert into testdt2(c1) values(1);
    
    select now();
---
 .../org/apache/doris/analysis/FunctionCallExpr.java  |  3 ++-
 .../main/java/org/apache/doris/catalog/Function.java | 20 ++++++++++++++++++++
 .../correctness_p0/test_current_timestamp.groovy     |  4 ++++
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
index 6d45021179..a91a01c4a6 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
@@ -1058,7 +1058,8 @@ public class FunctionCallExpr extends Expr {
      * @throws AnalysisException
      */
     public void analyzeImplForDefaultValue(Type type) throws AnalysisException {
-        fn = getBuiltinFunction(fnName.getFunction(), new Type[0], Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF);
+        fn = new Function(getBuiltinFunction(fnName.getFunction(), new Type[0],
+                Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF));
         fn.setReturnType(type);
         this.type = type;
         for (int i = 0; i < children.size(); ++i) {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Function.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Function.java
index f1a608a9b8..6dc5319d93 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Function.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Function.java
@@ -163,6 +163,26 @@ public class Function implements Writable {
         this(id, name, argTypes, retType, hasVarArgs, TFunctionBinaryType.BUILTIN, true, vectorized, mode);
     }
 
+    public Function(Function other) {
+        if (other == null) {
+            return;
+        }
+        this.id = other.id;
+        this.name = new FunctionName(other.name.getDb(), other.name.getFunction());
+        this.hasVarArgs = other.hasVarArgs;
+        this.retType = other.retType;
+        this.userVisible = other.userVisible;
+        this.nullableMode = other.nullableMode;
+        this.vectorized = other.vectorized;
+        this.binaryType = other.binaryType;
+        this.location = other.location;
+        if (other.argTypes != null) {
+            this.argTypes = new Type[other.argTypes.length];
+            System.arraycopy(other.argTypes, 0, this.argTypes, 0, other.argTypes.length);
+        }
+        this.checksum = other.checksum;
+    }
+
     public FunctionName getFunctionName() {
         return name;
     }
diff --git a/regression-test/suites/correctness_p0/test_current_timestamp.groovy b/regression-test/suites/correctness_p0/test_current_timestamp.groovy
index e0cdecbcfc..53ac6d6838 100644
--- a/regression-test/suites/correctness_p0/test_current_timestamp.groovy
+++ b/regression-test/suites/correctness_p0/test_current_timestamp.groovy
@@ -49,6 +49,8 @@ suite("test_current_timestamp") {
     qt_insert_into """ select count(*) from ${tableName} where to_date(dt_4) = to_date(dt_5); """
     qt_insert_into """ select count(*) from ${tableName} where to_date(dt_6) = to_date(dt_7); """
 
+    sql """select now()"""
+
     // test stream load.
     streamLoad {
         table "${tableName}"
@@ -64,4 +66,6 @@ suite("test_current_timestamp") {
     qt_stream_load """ select count(*) from ${tableName} where id > 4 and to_date(dt_2) = to_date(dt_3); """
     qt_stream_load """ select count(*) from ${tableName} where id > 4 and to_date(dt_4) = to_date(dt_5); """
     qt_stream_load """ select count(*) from ${tableName} where id > 4 and to_date(dt_6) = to_date(dt_7); """
+
+    sql """select now()"""
  }


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