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

lihaopeng pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new d7b39daba53 [fix](function)timediff with now function  causes a error 
signature
d7b39daba53 is described below

commit d7b39daba5350021ab3bdad0f906248d323c4567
Author: Mryange <[email protected]>
AuthorDate: Fri Aug 23 14:28:33 2024 +0800

    [fix](function)timediff with now function  causes a error signature
    
    https://github.com/apache/doris/pull/39322
    The derivation of precision for the datetime constant in version 2.0 is
    incorrect, it tends to be derived as the maximum precision.
    
    ```
    mysql [(none)]>select round(timediff(now(),'2024-08-15')/60/60,2);
    ERROR 1105 (HY000): errCode = 2, detailMessage = argument 1 requires 
datetimev2 type, however 'now()' is of datetime type
    ```
    The reason is that the function parameter types were modified in
    expectedInputTypes, which led to no match being found. The code here is
    from a long time ago. Because the precision of datetimev2 could not be
    deduced in the past, a separate implementation was made here. This code
    can be safely deleted.
---
 .../trees/expressions/functions/scalar/TimeDiff.java   | 18 ------------------
 .../data/correctness/test_time_diff_microseconds.out   |  3 +++
 .../data/correctness_p0/test_char_implicit_cast.out    |  4 ++--
 .../data/nereids_p0/test_char_implicit_cast.out        |  4 ++--
 .../data/query_p0/test_char_implicit_cast.out          |  4 ++--
 .../correctness/test_time_diff_microseconds.groovy     |  8 ++++++++
 6 files changed, 17 insertions(+), 24 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/TimeDiff.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/TimeDiff.java
index 2cff7c8886b..997475ca40e 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/TimeDiff.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/TimeDiff.java
@@ -21,7 +21,6 @@ import org.apache.doris.catalog.FunctionSignature;
 import org.apache.doris.nereids.trees.expressions.Expression;
 import 
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
 import 
org.apache.doris.nereids.trees.expressions.functions.PropagateNullableOnDateLikeV2Args;
-import org.apache.doris.nereids.trees.expressions.literal.StringLikeLiteral;
 import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression;
 import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
 import org.apache.doris.nereids.types.DateTimeType;
@@ -29,7 +28,6 @@ import org.apache.doris.nereids.types.DateTimeV2Type;
 import org.apache.doris.nereids.types.DateV2Type;
 import org.apache.doris.nereids.types.TimeType;
 import org.apache.doris.nereids.types.TimeV2Type;
-import org.apache.doris.nereids.types.coercion.AbstractDataType;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
@@ -96,20 +94,4 @@ public class TimeDiff extends ScalarFunction
         }
         return signature;
     }
-
-    @Override
-    public List<AbstractDataType> expectedInputTypes() {
-        FunctionSignature signature = getSignature();
-        if (getArgument(0) instanceof StringLikeLiteral) {
-            StringLikeLiteral str = (StringLikeLiteral) getArgument(0);
-            DateTimeV2Type left = 
DateTimeV2Type.forTypeFromString(str.getStringValue());
-            signature = signature.withArgumentType(0, left);
-        }
-        if (getArgument(1) instanceof StringLikeLiteral) {
-            StringLikeLiteral str = (StringLikeLiteral) getArgument(1);
-            DateTimeV2Type right = 
DateTimeV2Type.forTypeFromString(str.getStringValue());
-            signature = signature.withArgumentType(1, right);
-        }
-        return signature.argumentsTypes;
-    }
 }
diff --git a/regression-test/data/correctness/test_time_diff_microseconds.out 
b/regression-test/data/correctness/test_time_diff_microseconds.out
index dbeeb067f26..a04370f8139 100644
--- a/regression-test/data/correctness/test_time_diff_microseconds.out
+++ b/regression-test/data/correctness/test_time_diff_microseconds.out
@@ -27,3 +27,6 @@
 -- !select8 --
 48:00:00.11500
 
+-- !select9 --
+67:19:00.123000
+
diff --git a/regression-test/data/correctness_p0/test_char_implicit_cast.out 
b/regression-test/data/correctness_p0/test_char_implicit_cast.out
index 59f5d47377e..3dcd2252594 100644
--- a/regression-test/data/correctness_p0/test_char_implicit_cast.out
+++ b/regression-test/data/correctness_p0/test_char_implicit_cast.out
@@ -6,10 +6,10 @@
 7
 
 -- !test_timediff_varchar --
--24:00:00
+-24:00:00.000000
 
 -- !test_timediff_char --
--24:00:00
+-24:00:00.000000
 
 -- !test_money_format_varchar --
 123,456.00
diff --git a/regression-test/data/nereids_p0/test_char_implicit_cast.out 
b/regression-test/data/nereids_p0/test_char_implicit_cast.out
index 599dd6500dc..3dfa9bed934 100644
--- a/regression-test/data/nereids_p0/test_char_implicit_cast.out
+++ b/regression-test/data/nereids_p0/test_char_implicit_cast.out
@@ -6,10 +6,10 @@
 7
 
 -- !test_timediff_varchar --
--96:00:00
+-96:00:00.000000
 
 -- !test_timediff_varcharv2 --
--96:00:00.3337
+-96:00:00.333700
 
 -- !test_money_format_varchar --
 123,456.00
diff --git a/regression-test/data/query_p0/test_char_implicit_cast.out 
b/regression-test/data/query_p0/test_char_implicit_cast.out
index 59f5d47377e..3dcd2252594 100644
--- a/regression-test/data/query_p0/test_char_implicit_cast.out
+++ b/regression-test/data/query_p0/test_char_implicit_cast.out
@@ -6,10 +6,10 @@
 7
 
 -- !test_timediff_varchar --
--24:00:00
+-24:00:00.000000
 
 -- !test_timediff_char --
--24:00:00
+-24:00:00.000000
 
 -- !test_money_format_varchar --
 123,456.00
diff --git 
a/regression-test/suites/correctness/test_time_diff_microseconds.groovy 
b/regression-test/suites/correctness/test_time_diff_microseconds.groovy
index e754515250b..d1f86072387 100644
--- a/regression-test/suites/correctness/test_time_diff_microseconds.groovy
+++ b/regression-test/suites/correctness/test_time_diff_microseconds.groovy
@@ -92,4 +92,12 @@ suite("test_time_diff_microseconds") {
         cast('0001-01-03 00:00:00.114514' as Datetimev2(3) ) , 
         cast('0001-01-01 00:00:00.000000' as Datetimev2(5) ));
     """
+
+    sql """ 
+    select round(timediff(now(),'2024-08-15')/60/60,2);
+    """
+
+    qt_select9 """
+       select timediff('0001-01-03 19:19:00.123','0001-01-01 00:00:00.0000');
+    """
 }


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

Reply via email to