jackwener commented on code in PR #24224:
URL: https://github.com/apache/doris/pull/24224#discussion_r1323502833


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/literal/DateLiteral.java:
##########
@@ -115,27 +96,72 @@ public DateLiteral(DateLiteral other, DataType type) {
         this.day = other.day;
     }
 
-    protected void init(String s) throws AnalysisException {
+    // replace 'T' with ' '
+    private static String replaceDelimiterT(String s) {
+        // Matcher matcher = 
Pattern.compile("^(\\d{2,4}-\\d{1,2}-\\d{1,2})T").matcher(s);
+        // if (matcher.find()) {
+        //     return matcher.group(1) + " " + s.substring(matcher.end());
+        // }
+        // return s;
+        if (s.length() <= 10) {
+            return s;
+        }
+        if (s.charAt(10) == 'T') {
+            return s.substring(0, 10) + " " + s.substring(11);
+        } else if (s.charAt(8) == 'T') {
+            return s.substring(0, 8) + " " + s.substring(9);
+        } else {
+            return s;
+        }
+    }
+
+    protected static TemporalAccessor parse(String s) {
+        String originalString = s;
         try {
             TemporalAccessor dateTime;
+
+            // parse condition without '-' and ':'
             if (!s.contains("-") && !s.contains(":")) {
-                dateTime = 
DateTimeFormatterUtils.BASIC_DATE_TIME_FORMATTER.parse(s);
-            } else if (s.split("-")[0].length() == 2) {
-                dateTime = DATE_FORMATTER_TWO_DIGIT.parse(s);
-            } else if (s.length() == 19) {
-                dateTime = DATE_TIME_FORMATTER.parse(s);
+                // mysql reject "20200219 010101" "200219 010101", can't use ' 
' spilt basic date time.
+                if (!s.contains("T")) {
+                    if (s.length() == 6) {
+                        dateTime = 
DateTimeFormatterUtils.BASIC_TWO_DIGIT_DATE_FORMATTER.parse(s);
+                    } else {
+                        dateTime = 
DateTimeFormatterUtils.BASIC_FORMATTER_WITHOUT_T.parse(s);
+                    }
+                } else {
+                    dateTime = 
DateTimeFormatterUtils.BASIC_DATE_TIME_FORMATTER.parse(s);
+                }
+                return dateTime;
+            }
+
+            // replace first 'T' with ' '
+            s = replaceDelimiterT(s);
+            if (!s.contains(" ")) {
+                dateTime = DateTimeFormatterUtils.ZONE_DATE_FORMATTER.parse(s);
             } else {
-                dateTime = DATE_FORMATTER.parse(s);
+                dateTime = 
DateTimeFormatterUtils.ZONE_DATE_TIME_FORMATTER.parse(s);
+            }
+
+            // if Year is not present, throw exception
+            if (!dateTime.isSupported(ChronoField.YEAR)) {
+                throw new AnalysisException("datetime literal [" + 
originalString + "] is invalid");
             }
-            year = DateUtils.getOrDefault(dateTime, ChronoField.YEAR);
-            month = DateUtils.getOrDefault(dateTime, 
ChronoField.MONTH_OF_YEAR);
-            day = DateUtils.getOrDefault(dateTime, ChronoField.DAY_OF_MONTH);
+
+            return dateTime;
         } catch (Exception ex) {
-            throw new AnalysisException("date literal [" + s + "] is invalid");
+            throw new AnalysisException("datetime literal [" + originalString 
+ "] is invalid");

Review Comment:
   Will be done in next PR.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to