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 4f5db35990 [fix](date) fix the value may be changed during the parsing 
of date and datetime types (#11573)
4f5db35990 is described below

commit 4f5db359908c3452850f9bf91a4eb80fe55df1d7
Author: luozenglin <[email protected]>
AuthorDate: Mon Aug 8 08:58:30 2022 +0800

    [fix](date) fix the value may be changed during the parsing of date and 
datetime types (#11573)
    
    * [fix](date) fix the value may be changed during the parsing of date and 
datetime types
---
 .../main/java/org/apache/doris/analysis/DateLiteral.java    |  5 ++++-
 .../java/org/apache/doris/analysis/DateLiteralTest.java     | 13 +++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java
index b1160a9118..789eca23b9 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java
@@ -48,6 +48,7 @@ import java.time.ZonedDateTime;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeFormatterBuilder;
 import java.time.format.DateTimeParseException;
+import java.time.format.ResolverStyle;
 import java.time.format.TextStyle;
 import java.time.temporal.ChronoField;
 import java.time.temporal.TemporalAccessor;
@@ -415,7 +416,9 @@ public class DateLiteral extends LiteralExpr {
                         builder.appendLiteral(":");
                     }
                 }
-                DateTimeFormatter formatter = builder.toFormatter();
+                // The default resolver style is 'SMART', which parses 
"2022-06-31" as "2022-06-30"
+                // and does not throw an exception. 'STRICT' is used here.
+                DateTimeFormatter formatter = 
builder.toFormatter().withResolverStyle(ResolverStyle.STRICT);
                 dateTime = formatter.parse(s);
                 parsed = true;
             }
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/analysis/DateLiteralTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/analysis/DateLiteralTest.java
index 43271660e7..b0318b0e21 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/analysis/DateLiteralTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/DateLiteralTest.java
@@ -241,11 +241,24 @@ public class DateLiteralTest {
             Assert.assertEquals(2023, literal.getYear());
             Assert.assertEquals(6, literal.getMonth());
             Assert.assertEquals(1, literal.getDay());
+
+            literal = new DateLiteral("2020-02-29", Type.DATEV2);
+            Assert.assertEquals(2020, literal.getYear());
+            Assert.assertEquals(2, literal.getMonth());
+            Assert.assertEquals(29, literal.getDay());
         } catch (AnalysisException e) {
             e.printStackTrace();
             hasException = true;
         }
         Assert.assertFalse(hasException);
+
+        try {
+            new DateLiteral("2022-02-29", Type.DATEV2);
+        } catch (AnalysisException e) {
+            e.printStackTrace();
+            hasException = true;
+        }
+        Assert.assertTrue(hasException);
     }
 
     @Test


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

Reply via email to