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

morrysnow 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 d7032d1cfc6 [Fix](Nereids) fix date and date time arithmatic (#40745) 
(#41533)
d7032d1cfc6 is described below

commit d7032d1cfc600481a4b058dec963d90d5fd9a845
Author: LiBinfeng <[email protected]>
AuthorDate: Mon Oct 21 15:44:19 2024 +0800

    [Fix](Nereids) fix date and date time arithmatic (#40745) (#41533)
    
    cherry-pick from master #40745
    fix date and time arithmatic of: hours_add, minutes_add, seconds_add,
    to_days
---
 .../functions/executable/DateTimeArithmetic.java   | 40 ++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeArithmetic.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeArithmetic.java
index 033bff2afd3..54add9565ca 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeArithmetic.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeArithmetic.java
@@ -174,6 +174,16 @@ public class DateTimeArithmetic {
     /**
      * datetime arithmetic function hours-add.
      */
+    @ExecFunction(name = "hours_add", argTypes = {"DATE", "INT"}, returnType = 
"DATE")
+    public static Expression hoursAdd(DateLiteral date, IntegerLiteral hour) {
+        return date.toBeginOfTheDay().plusHours(hour.getValue());
+    }
+
+    @ExecFunction(name = "hours_add", argTypes = {"DATEV2", "INT"}, returnType 
= "DATEV2")
+    public static Expression hoursAdd(DateV2Literal date, IntegerLiteral hour) 
{
+        return date.toBeginOfTheDay().plusHours(hour.getValue());
+    }
+
     @ExecFunction(name = "hours_add", argTypes = {"DATETIME", "INT"}, 
returnType = "DATETIME")
     public static Expression hoursAdd(DateTimeLiteral date, IntegerLiteral 
hour) {
         return date.plusHours(hour.getValue());
@@ -187,6 +197,16 @@ public class DateTimeArithmetic {
     /**
      * datetime arithmetic function minutes-add.
      */
+    @ExecFunction(name = "minutes_add", argTypes = {"DATE", "INT"}, returnType 
= "DATE")
+    public static Expression minutesAdd(DateLiteral date, IntegerLiteral 
minute) {
+        return date.toBeginOfTheDay().plusMinutes(minute.getValue());
+    }
+
+    @ExecFunction(name = "minutes_add", argTypes = {"DATEV2", "INT"}, 
returnType = "DATEV2")
+    public static Expression minutesAdd(DateV2Literal date, IntegerLiteral 
minute) {
+        return date.toBeginOfTheDay().plusMinutes(minute.getValue());
+    }
+
     @ExecFunction(name = "minutes_add", argTypes = {"DATETIME", "INT"}, 
returnType = "DATETIME")
     public static Expression minutesAdd(DateTimeLiteral date, IntegerLiteral 
minute) {
         return date.plusMinutes(minute.getValue());
@@ -200,6 +220,16 @@ public class DateTimeArithmetic {
     /**
      * datetime arithmetic function seconds-add.
      */
+    @ExecFunction(name = "seconds_add", argTypes = {"DATE", "INT"}, returnType 
= "DATE")
+    public static Expression secondsAdd(DateLiteral date, IntegerLiteral 
second) {
+        return date.toBeginOfTheDay().plusSeconds(second.getValue());
+    }
+
+    @ExecFunction(name = "seconds_add", argTypes = {"DATEV2", "INT"}, 
returnType = "DATEV2")
+    public static Expression secondsAdd(DateV2Literal date, IntegerLiteral 
second) {
+        return date.toBeginOfTheDay().plusSeconds(second.getValue());
+    }
+
     @ExecFunction(name = "seconds_add", argTypes = {"DATETIME", "INT"}, 
returnType = "DATETIME")
     public static Expression secondsAdd(DateTimeLiteral date, IntegerLiteral 
second) {
         return date.plusSeconds(second.getValue());
@@ -380,4 +410,14 @@ public class DateTimeArithmetic {
     private static int dateDiff(LocalDateTime date1, LocalDateTime date2) {
         return ((int) ChronoUnit.DAYS.between(date2.toLocalDate(), 
date1.toLocalDate()));
     }
+
+    @ExecFunction(name = "to_days", argTypes = {"DATE"}, returnType = "INT")
+    public static Expression toDays(DateLiteral date) {
+        return new IntegerLiteral((int) date.getDay());
+    }
+
+    @ExecFunction(name = "to_days", argTypes = {"DATEV2"}, returnType = "INT")
+    public static Expression toDays(DateV2Literal date) {
+        return new IntegerLiteral((int) date.getDay());
+    }
 }


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

Reply via email to