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

dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new 8dbde04163a branch-3.0: [fix](nereids) fix parse date time exception 
#50810 (#50889)
8dbde04163a is described below

commit 8dbde04163af91616ee53dbbd44cfd165955187f
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed May 14 21:08:55 2025 +0800

    branch-3.0: [fix](nereids) fix parse date time exception #50810 (#50889)
    
    Cherry-picked from #50810
    
    Co-authored-by: yujun <yu...@selectdb.com>
---
 .../doris/nereids/parser/LogicalPlanBuilder.java   | 32 ++++++++++++++++++----
 .../nereids_syntax_p0/test_cast_datetime.groovy    | 14 ++++++++++
 2 files changed, 41 insertions(+), 5 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
index d29eb2b2433..e247386ae71 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
@@ -472,6 +472,10 @@ import org.apache.doris.nereids.types.ArrayType;
 import org.apache.doris.nereids.types.BigIntType;
 import org.apache.doris.nereids.types.BooleanType;
 import org.apache.doris.nereids.types.DataType;
+import org.apache.doris.nereids.types.DateTimeType;
+import org.apache.doris.nereids.types.DateTimeV2Type;
+import org.apache.doris.nereids.types.DateType;
+import org.apache.doris.nereids.types.DateV2Type;
 import org.apache.doris.nereids.types.LargeIntType;
 import org.apache.doris.nereids.types.MapType;
 import org.apache.doris.nereids.types.StructField;
@@ -2380,19 +2384,37 @@ public class LogicalPlanBuilder extends 
DorisParserBaseVisitor<Object> {
     }
 
     @Override
-    public Literal visitTypeConstructor(TypeConstructorContext ctx) {
+    public Expression visitTypeConstructor(TypeConstructorContext ctx) {
         String value = ctx.STRING_LITERAL().getText();
         value = value.substring(1, value.length() - 1);
         String type = ctx.type.getText().toUpperCase();
         switch (type) {
             case "DATE":
-                return Config.enable_date_conversion ? new 
DateV2Literal(value) : new DateLiteral(value);
+                try {
+                    return Config.enable_date_conversion ? new 
DateV2Literal(value) : new DateLiteral(value);
+                } catch (Exception e) {
+                    return new Cast(new StringLiteral(value),
+                            Config.enable_date_conversion ? 
DateV2Type.INSTANCE : DateType.INSTANCE);
+                }
             case "TIMESTAMP":
-                return Config.enable_date_conversion ? new 
DateTimeV2Literal(value) : new DateTimeLiteral(value);
+                try {
+                    return Config.enable_date_conversion ? new 
DateTimeV2Literal(value) : new DateTimeLiteral(value);
+                } catch (Exception e) {
+                    return new Cast(new StringLiteral(value),
+                            Config.enable_date_conversion ? DateTimeV2Type.MAX 
: DateTimeType.INSTANCE);
+                }
             case "DATEV2":
-                return new DateV2Literal(value);
+                try {
+                    return new DateV2Literal(value);
+                } catch (Exception e) {
+                    return new Cast(new StringLiteral(value), 
DateV2Type.INSTANCE);
+                }
             case "DATEV1":
-                return new DateLiteral(value);
+                try {
+                    return new DateLiteral(value);
+                } catch (Exception e) {
+                    return new Cast(new StringLiteral(value), 
DateType.INSTANCE);
+                }
             default:
                 throw new ParseException("Unsupported data type : " + type, 
ctx);
         }
diff --git a/regression-test/suites/nereids_syntax_p0/test_cast_datetime.groovy 
b/regression-test/suites/nereids_syntax_p0/test_cast_datetime.groovy
index 32eb0da90eb..c56a4272e54 100644
--- a/regression-test/suites/nereids_syntax_p0/test_cast_datetime.groovy
+++ b/regression-test/suites/nereids_syntax_p0/test_cast_datetime.groovy
@@ -53,6 +53,10 @@ suite("test_cast_datetime") {
     qt_3 "select a, '' = mydate, '' = mydatev2, '' = mydatetime, '' = 
mydatetimev2 from casttbl"
 
     def wrong_date_strs = [
+        "date '2020-01'",
+        "datev1 '2020-01'",
+        "datev2 '2020-01'",
+        "timestamp '2020-01'",
         "'' > date '2019-06-01'",
         "'' > date_sub('2019-06-01', -10)",
         "'' > cast('2019-06-01 00:00:00' as datetime)",
@@ -572,5 +576,15 @@ suite("test_cast_datetime") {
             sql "select date_add('2023-11-05 01:30:00 America/New_York', 
INTERVAL 1 DAY)"
             result([[LocalDateTime.parse('2023-11-06T01:30:00')]])
         }
+
+        test {
+            sql "select date '2025年1月20日'"
+            result([[Date.valueOf('2025-01-20')]])
+        }
+
+        test {
+            sql "select timestamp '2025年1月20日10时20分5秒'"
+            result([[LocalDateTime.parse('2025-01-20T10:20:05')]])
+        }
     }
 }


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

Reply via email to