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

jakevin 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 ee474044293 [feature](Nereids): date literal suppose Zone (#33534) 
(#33683)
ee474044293 is described below

commit ee47404429377a9100125a32998295826b194619
Author: jakevin <jakevin...@gmail.com>
AuthorDate: Tue Apr 16 09:27:48 2024 +0800

    [feature](Nereids): date literal suppose Zone (#33534) (#33683)
---
 .../trees/expressions/literal/DateLiteral.java     | 13 -------
 .../doris/nereids/util/DateTimeFormatterUtils.java |  1 -
 .../apache/doris/nereids/util/ExpressionUtils.java |  7 ----
 .../expressions/literal/DateTimeLiteralTest.java   | 41 ++++++++++++----------
 4 files changed, 22 insertions(+), 40 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 c6e19bb96cb..9693858fb7e 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
@@ -244,19 +244,6 @@ public class DateLiteral extends Literal {
 
         sb.append(s.substring(i));
 
-        // Zone Part
-        // while(i < s.length()) {
-        //
-        // }
-
-        // add missing :00 in Zone part
-        // int len = sb.length();
-        // int signIdx = sb.indexOf("+", 10); // from index:10, skip date part 
(it contains '-')
-        // signIdx = signIdx == -1 ? sb.indexOf("-", 10) : signIdx;
-        // if (signIdx != -1 && len - signIdx == 3) {
-        //     sb.append(":00");
-        // }
-
         return sb.toString();
     }
 
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/DateTimeFormatterUtils.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/DateTimeFormatterUtils.java
index 50d0f7169a5..6b52fb24a93 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/DateTimeFormatterUtils.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/DateTimeFormatterUtils.java
@@ -41,7 +41,6 @@ import java.time.temporal.ChronoField;
 public class DateTimeFormatterUtils {
     public static final DateTimeFormatter ZONE_FORMATTER = new 
DateTimeFormatterBuilder()
             .optionalStart()
-            // .appendZoneText(TextStyle.FULL)
             .appendZoneOrOffsetId()
             .optionalEnd()
             .toFormatter()
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java
index 46990827633..8bec208896a 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java
@@ -536,13 +536,6 @@ public class ExpressionUtils {
                 .collect(ImmutableSet.toImmutableSet());
     }
 
-    public static boolean checkTypeSkipCast(Expression expression, Class<? 
extends Expression> cls) {
-        while (expression instanceof Cast) {
-            expression = ((Cast) expression).child();
-        }
-        return cls.isInstance(expression);
-    }
-
     public static Expression getExpressionCoveredByCast(Expression expression) 
{
         while (expression instanceof Cast) {
             expression = ((Cast) expression).child();
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/literal/DateTimeLiteralTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/literal/DateTimeLiteralTest.java
index c5e0b5eee6b..93039c4ad7f 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/literal/DateTimeLiteralTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/literal/DateTimeLiteralTest.java
@@ -137,25 +137,7 @@ class DateTimeLiteralTest {
         new DateTimeV2Literal("2022-08-01 01:01:01Z");
         new DateTimeV2Literal("2022-08-01 01:01:01Europe/Berlin");
         new DateTimeV2Literal("2022-08-01 01:01:01Europe/London");
-    }
-
-    @Test
-    @Disabled("Test results can change over time")
-    void testZoneOrOffsetRight() {
-        java.util.function.BiConsumer<DateTimeV2Literal, Long> assertHour = 
(dateTimeV2Literal, expectHour) -> {
-            Assertions.assertEquals(dateTimeV2Literal.hour, expectHour);
-        };
-        DateTimeV2Literal dateTimeV2Literal;
-        dateTimeV2Literal = new DateTimeV2Literal("2022-08-01 
00:00:00Europe/London"); // +01:00
-        assertHour.accept(dateTimeV2Literal, 7L);
-        dateTimeV2Literal = new DateTimeV2Literal("2022-08-01 
00:00:00America/New_York"); // -04:00
-        assertHour.accept(dateTimeV2Literal, 12L);
-        dateTimeV2Literal = new DateTimeV2Literal("2022-08-01 
00:00:00Asia/Shanghai");
-        assertHour.accept(dateTimeV2Literal, 0L);
-        dateTimeV2Literal = new DateTimeV2Literal("2022-08-01 00:00:00+01:00");
-        assertHour.accept(dateTimeV2Literal, 7L);
-        dateTimeV2Literal = new DateTimeV2Literal("2022-08-01 00:00:00-01:00");
-        assertHour.accept(dateTimeV2Literal, 9L);
+        new DateTimeV2Literal("2022-08-01 00:00:00Asia/Shanghai");
     }
 
     @Test
@@ -238,6 +220,27 @@ class DateTimeLiteralTest {
         new DateTimeV2Literal("0001-01-01");
     }
 
+    @Test
+    void testDateTimeZone1() {
+        Consumer<DateTimeV2Literal> assertFunc = (datetime) -> {
+            Assertions.assertEquals(2022, datetime.year);
+            Assertions.assertEquals(1, datetime.month);
+            Assertions.assertEquals(2, datetime.day);
+            Assertions.assertEquals(12, datetime.hour);
+            Assertions.assertEquals(0, datetime.minute);
+            Assertions.assertEquals(0, datetime.second);
+        };
+        DateTimeV2Literal literal;
+        literal = new DateTimeV2Literal("2022-01-02 12:00:00UTC+08:00");
+        assertFunc.accept(literal);
+        literal = new DateTimeV2Literal("2022-01-02 04:00:00UTC");
+        assertFunc.accept(literal);
+        literal = new DateTimeV2Literal("2022-01-01 20:00:00UTC-08:00");
+        assertFunc.accept(literal);
+        literal = new DateTimeV2Literal("2022-01-02 04:00:00Z");
+        assertFunc.accept(literal);
+    }
+
     @Test
     void testIrregularDateTime() {
 


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

Reply via email to