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

englefly 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 4fcd93ac00 [Enhancement](Nereids)add datelikev2 type support for fold 
constant. #18275
4fcd93ac00 is described below

commit 4fcd93ac003108dd68cfbe2b4fffc39f1b528169
Author: mch_ucchi <[email protected]>
AuthorDate: Mon Apr 3 08:47:47 2023 +0800

    [Enhancement](Nereids)add datelikev2 type support for fold constant. #18275
    
    add datelikev2 type support for fold constant.
    date_add / years_add / mouths_add / days_add / hours_add / minutes_add / 
seconds_add and xxx_sub.
---
 .../expressions/functions/ExecutableFunctions.java | 124 ++++++++++++++++-----
 1 file changed, 99 insertions(+), 25 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ExecutableFunctions.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ExecutableFunctions.java
index ee16509705..e01729bbaa 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ExecutableFunctions.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ExecutableFunctions.java
@@ -592,13 +592,18 @@ public class ExecutableFunctions {
                 t1.getPrecision(), t1.getScale() - t2.getScale()), result);
     }
 
+    @ExecFunction(name = "date_sub", argTypes = { "DATE", "INT" }, returnType 
= "DATE")
+    public static DateLiteral dateSub(DateLiteral date, IntegerLiteral day) 
throws AnalysisException {
+        return dateAdd(date, new IntegerLiteral(-day.getValue()));
+    }
+
     @ExecFunction(name = "date_sub", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
     public static DateTimeLiteral dateSub(DateTimeLiteral date, IntegerLiteral 
day) throws AnalysisException {
         return dateAdd(date, new IntegerLiteral(-day.getValue()));
     }
 
-    @ExecFunction(name = "date_sub", argTypes = { "DATE", "INT" }, returnType 
= "DATE")
-    public static DateLiteral dateSub(DateLiteral date, IntegerLiteral day) 
throws AnalysisException {
+    @ExecFunction(name = "date_sub", argTypes = { "DATEV2", "INT" }, 
returnType = "DATEV2")
+    public static DateV2Literal dateSub(DateV2Literal date, IntegerLiteral 
day) throws AnalysisException {
         return dateAdd(date, new IntegerLiteral(-day.getValue()));
     }
 
@@ -607,9 +612,9 @@ public class ExecutableFunctions {
         return dateAdd(date, new IntegerLiteral(-day.getValue()));
     }
 
-    @ExecFunction(name = "date_sub", argTypes = { "DATEV2", "INT" }, 
returnType = "DATEV2")
-    public static DateV2Literal dateSub(DateV2Literal date, IntegerLiteral 
day) throws AnalysisException {
-        return dateAdd(date, new IntegerLiteral(-day.getValue()));
+    @ExecFunction(name = "date_add", argTypes = { "DATE", "INT" }, returnType 
= "DATE")
+    public static DateLiteral dateAdd(DateLiteral date, IntegerLiteral day) 
throws AnalysisException {
+        return daysAdd(date, day);
     }
 
     @ExecFunction(name = "date_add", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
@@ -617,8 +622,8 @@ public class ExecutableFunctions {
         return daysAdd(date, day);
     }
 
-    @ExecFunction(name = "date_add", argTypes = { "DATE", "INT" }, returnType 
= "DATE")
-    public static DateLiteral dateAdd(DateLiteral date, IntegerLiteral day) 
throws AnalysisException {
+    @ExecFunction(name = "date_add", argTypes = { "DATEV2", "INT" }, 
returnType = "DATEV2")
+    public static DateV2Literal dateAdd(DateV2Literal date, IntegerLiteral 
day) throws AnalysisException {
         return daysAdd(date, day);
     }
 
@@ -627,9 +632,9 @@ public class ExecutableFunctions {
         return daysAdd(date, day);
     }
 
-    @ExecFunction(name = "date_add", argTypes = { "DATEV2", "INT" }, 
returnType = "DATEV2")
-    public static DateV2Literal dateAdd(DateV2Literal date, IntegerLiteral 
day) throws AnalysisException {
-        return daysAdd(date, day);
+    @ExecFunction(name = "years_add", argTypes = { "DATE", "INT" }, returnType 
= "DATE")
+    public static DateLiteral yearsAdd(DateLiteral date, IntegerLiteral year) 
throws AnalysisException {
+        return date.plusYears(year.getValue());
     }
 
     @ExecFunction(name = "years_add", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
@@ -637,8 +642,8 @@ public class ExecutableFunctions {
         return date.plusYears(year.getValue());
     }
 
-    @ExecFunction(name = "years_add", argTypes = { "DATE", "INT" }, returnType 
= "DATE")
-    public static DateLiteral yearsAdd(DateLiteral date, IntegerLiteral year) 
throws AnalysisException {
+    @ExecFunction(name = "years_add", argTypes = { "DATEV2", "INT" }, 
returnType = "DATEV2")
+    public static DateV2Literal yearsAdd(DateV2Literal date, IntegerLiteral 
year) throws AnalysisException {
         return date.plusYears(year.getValue());
     }
 
@@ -647,9 +652,9 @@ public class ExecutableFunctions {
         return date.plusYears(year.getValue());
     }
 
-    @ExecFunction(name = "years_add", argTypes = { "DATEV2", "INT" }, 
returnType = "DATEV2")
-    public static DateV2Literal yearsAdd(DateV2Literal date, IntegerLiteral 
year) throws AnalysisException {
-        return date.plusYears(year.getValue());
+    @ExecFunction(name = "months_add", argTypes = { "DATE", "INT" }, 
returnType = "DATE")
+    public static DateLiteral monthsAdd(DateLiteral date, IntegerLiteral 
month) throws AnalysisException {
+        return date.plusMonths(month.getValue());
     }
 
     @ExecFunction(name = "months_add", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
@@ -657,8 +662,8 @@ public class ExecutableFunctions {
         return date.plusMonths(month.getValue());
     }
 
-    @ExecFunction(name = "months_add", argTypes = { "DATE", "INT" }, 
returnType = "DATE")
-    public static DateLiteral monthsAdd(DateLiteral date, IntegerLiteral 
month) throws AnalysisException {
+    @ExecFunction(name = "months_add", argTypes = { "DATEV2", "INT" }, 
returnType = "DATEV2")
+    public static DateV2Literal monthsAdd(DateV2Literal date, IntegerLiteral 
month) throws AnalysisException {
         return date.plusMonths(month.getValue());
     }
 
@@ -667,9 +672,9 @@ public class ExecutableFunctions {
         return date.plusMonths(month.getValue());
     }
 
-    @ExecFunction(name = "months_add", argTypes = { "DATEV2", "INT" }, 
returnType = "DATEV2")
-    public static DateV2Literal monthsAdd(DateV2Literal date, IntegerLiteral 
month) throws AnalysisException {
-        return date.plusMonths(month.getValue());
+    @ExecFunction(name = "days_add", argTypes = { "DATE", "INT" }, returnType 
= "DATE")
+    public static DateLiteral daysAdd(DateLiteral date, IntegerLiteral day) 
throws AnalysisException {
+        return date.plusDays(day.getValue());
     }
 
     @ExecFunction(name = "days_add", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
@@ -687,54 +692,123 @@ public class ExecutableFunctions {
         return date.plusDays(day.getValue());
     }
 
-    @ExecFunction(name = "days_add", argTypes = { "DATE", "INT" }, returnType 
= "DATE")
-    public static DateLiteral daysAdd(DateLiteral date, IntegerLiteral day) 
throws AnalysisException {
-        return date.plusDays(day.getValue());
-    }
-
     @ExecFunction(name = "hours_add", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
     public static DateTimeLiteral hoursAdd(DateTimeLiteral date, 
IntegerLiteral hour) throws AnalysisException {
         return date.plusHours(hour.getValue());
     }
 
+    @ExecFunction(name = "hours_add", argTypes = { "DATETIMEV2", "INT" }, 
returnType = "DATETIMEV2")
+    public static DateTimeV2Literal hoursAdd(DateTimeV2Literal date, 
IntegerLiteral hour) throws AnalysisException {
+        return date.plusHours(hour.getValue());
+    }
+
     @ExecFunction(name = "minutes_add", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
     public static DateTimeLiteral minutesAdd(DateTimeLiteral date, 
IntegerLiteral minute) throws AnalysisException {
         return date.plusMinutes(minute.getValue());
     }
 
+    @ExecFunction(name = "minutes_add", argTypes = { "DATETIMEV2", "INT" }, 
returnType = "DATETIMEV2")
+    public static DateTimeV2Literal minutesAdd(DateTimeV2Literal date, 
IntegerLiteral minute) throws AnalysisException {
+        return date.plusMinutes(minute.getValue());
+    }
+
     @ExecFunction(name = "seconds_add", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
     public static DateTimeLiteral secondsAdd(DateTimeLiteral date, 
IntegerLiteral second) throws AnalysisException {
         return date.plusSeconds(second.getValue());
     }
 
+    @ExecFunction(name = "seconds_add", argTypes = { "DATETIMEV2", "INT" }, 
returnType = "DATETIMEV2")
+    public static DateTimeV2Literal secondsAdd(DateTimeV2Literal date, 
IntegerLiteral second) throws AnalysisException {
+        return date.plusSeconds(second.getValue());
+    }
+
+    @ExecFunction(name = "years_sub", argTypes = { "DATE", "INT" }, returnType 
= "DATE")
+    public static DateLiteral yearsSub(DateLiteral date, IntegerLiteral year) 
throws AnalysisException {
+        return yearsAdd(date, new IntegerLiteral(-year.getValue()));
+    }
+
     @ExecFunction(name = "years_sub", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
     public static DateTimeLiteral yearsSub(DateTimeLiteral date, 
IntegerLiteral year) throws AnalysisException {
         return yearsAdd(date, new IntegerLiteral(-year.getValue()));
     }
 
+    @ExecFunction(name = "years_sub", argTypes = { "DATEV2", "INT" }, 
returnType = "DATEV2")
+    public static DateV2Literal yearsSub(DateV2Literal date, IntegerLiteral 
year) throws AnalysisException {
+        return yearsAdd(date, new IntegerLiteral(-year.getValue()));
+    }
+
+    @ExecFunction(name = "years_sub", argTypes = { "DATETIMEV2", "INT" }, 
returnType = "DATETIMEV2")
+    public static DateTimeV2Literal yearsSub(DateTimeV2Literal date, 
IntegerLiteral year) throws AnalysisException {
+        return yearsAdd(date, new IntegerLiteral(-year.getValue()));
+    }
+
+    @ExecFunction(name = "months_sub", argTypes = { "DATE", "INT" }, 
returnType = "DATE")
+    public static DateLiteral monthsSub(DateLiteral date, IntegerLiteral 
month) throws AnalysisException {
+        return monthsAdd(date, new IntegerLiteral(-month.getValue()));
+    }
+
     @ExecFunction(name = "months_sub", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
     public static DateTimeLiteral monthsSub(DateTimeLiteral date, 
IntegerLiteral month) throws AnalysisException {
         return monthsAdd(date, new IntegerLiteral(-month.getValue()));
     }
 
+    @ExecFunction(name = "months_sub", argTypes = { "DATEV2", "INT" }, 
returnType = "DATEV2")
+    public static DateV2Literal monthsSub(DateV2Literal date, IntegerLiteral 
month) throws AnalysisException {
+        return monthsAdd(date, new IntegerLiteral(-month.getValue()));
+    }
+
+    @ExecFunction(name = "months_sub", argTypes = { "DATETIMEV2", "INT" }, 
returnType = "DATETIMEV2")
+    public static DateTimeV2Literal monthsSub(DateTimeV2Literal date, 
IntegerLiteral month) throws AnalysisException {
+        return monthsAdd(date, new IntegerLiteral(-month.getValue()));
+    }
+
+    @ExecFunction(name = "days_sub", argTypes = { "DATE", "INT" }, returnType 
= "DATE")
+    public static DateLiteral daysSub(DateLiteral date, IntegerLiteral day) 
throws AnalysisException {
+        return daysAdd(date, new IntegerLiteral(-day.getValue()));
+    }
+
     @ExecFunction(name = "days_sub", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
     public static DateTimeLiteral daysSub(DateTimeLiteral date, IntegerLiteral 
day) throws AnalysisException {
         return daysAdd(date, new IntegerLiteral(-day.getValue()));
     }
 
+    @ExecFunction(name = "days_sub", argTypes = { "DATEV2", "INT" }, 
returnType = "DATEV2")
+    public static DateV2Literal daysSub(DateV2Literal date, IntegerLiteral 
day) throws AnalysisException {
+        return daysAdd(date, new IntegerLiteral(-day.getValue()));
+    }
+
+    @ExecFunction(name = "days_sub", argTypes = { "DATETIMEV2", "INT" }, 
returnType = "DATETIMEV2")
+    public static DateTimeV2Literal daysSub(DateTimeV2Literal date, 
IntegerLiteral day) throws AnalysisException {
+        return daysAdd(date, new IntegerLiteral(-day.getValue()));
+    }
+
     @ExecFunction(name = "hours_sub", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
     public static DateTimeLiteral hoursSub(DateTimeLiteral date, 
IntegerLiteral hour) throws AnalysisException {
         return hoursAdd(date, new IntegerLiteral(-hour.getValue()));
     }
 
+    @ExecFunction(name = "hours_sub", argTypes = { "DATETIMEV2", "INT" }, 
returnType = "DATETIMEV2")
+    public static DateTimeV2Literal hoursSub(DateTimeV2Literal date, 
IntegerLiteral hour) throws AnalysisException {
+        return hoursAdd(date, new IntegerLiteral(-hour.getValue()));
+    }
+
     @ExecFunction(name = "minutes_sub", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
     public static DateTimeLiteral minutesSub(DateTimeLiteral date, 
IntegerLiteral minute) throws AnalysisException {
         return minutesAdd(date, new IntegerLiteral(-minute.getValue()));
     }
 
+    @ExecFunction(name = "minutes_sub", argTypes = { "DATETIMEV2", "INT" }, 
returnType = "DATETIMEV2")
+    public static DateTimeV2Literal minutesSub(DateTimeV2Literal date, 
IntegerLiteral minute) throws AnalysisException {
+        return minutesAdd(date, new IntegerLiteral(-minute.getValue()));
+    }
+
     @ExecFunction(name = "seconds_sub", argTypes = { "DATETIME", "INT" }, 
returnType = "DATETIME")
     public static DateTimeLiteral secondsSub(DateTimeLiteral date, 
IntegerLiteral second) throws AnalysisException {
         return secondsAdd(date, new IntegerLiteral(-second.getValue()));
     }
 
+    @ExecFunction(name = "seconds_sub", argTypes = { "DATETIMEV2", "INT" }, 
returnType = "DATETIMEV2")
+    public static DateTimeV2Literal secondsSub(DateTimeV2Literal date, 
IntegerLiteral second) throws AnalysisException {
+        return secondsAdd(date, new IntegerLiteral(-second.getValue()));
+    }
 }


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

Reply via email to