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

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


The following commit(s) were added to refs/heads/master by this push:
     new ba85b022128 [fix] (Nereids) fix date function rewrite on datetimev1 
column bug (#32569)
ba85b022128 is described below

commit ba85b0221285c79bca499d591d63935ec1e2c6ba
Author: Ziyan Lee <49580493+ziyan...@users.noreply.github.com>
AuthorDate: Sat Mar 23 22:15:39 2024 +0800

    [fix] (Nereids) fix date function rewrite on datetimev1 column bug (#32569)
---
 .../trees/expressions/literal/DateLiteral.java     |   4 +-
 .../datetimev1/test_datetimev1_date_function.out   |  32 ++++++
 .../test_datetimev1_date_function.groovy           | 124 +++++++++++++++++++++
 3 files changed, 158 insertions(+), 2 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateLiteral.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateLiteral.java
index 7dcd86a1504..a33cc32c16f 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateLiteral.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateLiteral.java
@@ -458,10 +458,10 @@ public class DateLiteral extends Literal {
     /**
      * 2020-01-01
      *
-     * @return 2020-01-01 24:00:00
+     * @return 2020-01-01 23:59:59
      */
     public DateTimeLiteral toEndOfTheDay() {
-        return new DateTimeLiteral(year, month, day, 24, 0, 0);
+        return new DateTimeLiteral(year, month, day, 23, 59, 59);
     }
 
     /**
diff --git 
a/regression-test/data/datatype_p0/datetimev1/test_datetimev1_date_function.out 
b/regression-test/data/datatype_p0/datetimev1/test_datetimev1_date_function.out
new file mode 100644
index 00000000000..81a89b2286f
--- /dev/null
+++ 
b/regression-test/data/datatype_p0/datetimev1/test_datetimev1_date_function.out
@@ -0,0 +1,32 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !date_function_test_datetimev1_gt --
+2020-01-06T21:02:03
+2020-01-07T09:29:39
+2020-01-08T11:33:55
+2020-01-09T14:43:42
+2020-01-10T23:59:59
+
+-- !date_function_test_datetimev1_gte --
+2020-01-05T17:58:59
+2020-01-06T21:02:03
+2020-01-07T09:29:39
+2020-01-08T11:33:55
+2020-01-09T14:43:42
+2020-01-10T23:59:59
+
+-- !date_function_test_datetimev1_lt --
+2020-01-01T19:29:39
+2020-01-02T18:28:38
+2020-01-03T23:37:47
+2020-01-04T21:42:43
+
+-- !date_function_test_datetimev1_lte --
+2020-01-01T19:29:39
+2020-01-02T18:28:38
+2020-01-03T23:37:47
+2020-01-04T21:42:43
+2020-01-05T17:58:59
+
+-- !date_function_test_datetimev1_eq --
+2020-01-05T17:58:59
+
diff --git 
a/regression-test/suites/datatype_p0/datetimev1/test_datetimev1_date_function.groovy
 
b/regression-test/suites/datatype_p0/datetimev1/test_datetimev1_date_function.groovy
new file mode 100644
index 00000000000..ec473a82027
--- /dev/null
+++ 
b/regression-test/suites/datatype_p0/datetimev1/test_datetimev1_date_function.groovy
@@ -0,0 +1,124 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_datetimev1_date_function", "nonConcurrent") {
+
+    /// legacy date/datetime format need to run in non concurrent mode.
+    sql """
+        admin set frontend config("enable_date_conversion" = "false");
+    """
+
+    def table_dup = "test_datetimev1_date_function_dup_tbl" // duplicate key
+
+    sql "drop table if exists ${table_dup};"
+
+    sql """
+        CREATE TABLE IF NOT EXISTS `${table_dup}` (
+            `date_key1` datetimev1 NULL COMMENT "",
+          ) ENGINE=OLAP
+          DUPLICATE KEY(`date_key1`)
+          COMMENT "OLAP"
+          DISTRIBUTED BY HASH(`date_key1`) BUCKETS 1
+          PROPERTIES (
+          "replication_allocation" = "tag.location.default: 1",
+          "in_memory" = "false",
+          "storage_format" = "V2"
+        )
+    """
+
+    def insert_data = { table_name ->
+        sql """
+            insert into ${table_name}
+                values
+                    ('2020-01-01 19:29:39'),
+                    ('2020-01-02 18:28:38'),
+                    ('2020-01-03 23:37:47'),
+                    ('2020-01-04 21:42:43'),
+                    ('2020-01-05 17:58:59'),
+                    ('2020-01-06 21:02:03'),
+                    ('2020-01-07 09:29:39'),
+                    ('2020-01-08 11:33:55'),
+                    ('2020-01-09 14:43:42'),
+                    ('2020-01-10 23:59:59');
+        """
+    }
+
+    insert_data(table_dup)
+
+    def run_compare_test = { table_name, col, col_value ->
+        def query1 = """
+            select
+                *
+            from
+                `${table_name}`
+            where
+                date(`${col}`) > ${col_value}
+            order by 1;
+        """
+        quickTest("date_function_test_datetimev1_gt", query1)
+
+        def query2 = """
+            select
+                *
+            from
+                `${table_name}`
+            where
+                date(`${col}`) >= ${col_value}
+            order by 1;
+        """
+        quickTest("date_function_test_datetimev1_gte", query2)
+
+        def query3 = """
+            select
+                *
+            from
+                `${table_name}`
+            where
+                date(`${col}`) < ${col_value}
+            order by 1;
+        """
+        quickTest("date_function_test_datetimev1_lt", query3)
+
+        def query4 = """
+            select
+                *
+            from
+                `${table_name}`
+            where
+                date(`${col}`) <= ${col_value}
+            order by 1;
+        """
+        quickTest("date_function_test_datetimev1_lte", query4)
+
+        def query5 = """
+            select
+                *
+            from
+                `${table_name}`
+            where
+                date(`${col}`) = ${col_value}
+            order by 1;
+        """
+        quickTest("date_function_test_datetimev1_eq", query5)
+    }
+
+    run_compare_test(table_dup, "date_key1", "'2020-01-05'")
+
+    sql """
+        admin set frontend config("enable_date_conversion" = "true");
+    """
+}


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

Reply via email to