You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2022/07/26 01:00:47 UTC

[doris] branch master updated: [fix](fe-ut) Ignore invalid datetimev2 partition value in UT (#11178)

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

morningman 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 1788e2fe6c [fix](fe-ut) Ignore invalid datetimev2 partition value in UT (#11178)
1788e2fe6c is described below

commit 1788e2fe6c800e248aa2670c0d376983b739dec2
Author: Gabriel <ga...@gmail.com>
AuthorDate: Tue Jul 26 09:00:38 2022 +0800

    [fix](fe-ut) Ignore invalid datetimev2 partition value in UT (#11178)
---
 .../org/apache/doris/analysis/DateLiteral.java     | 24 +++++++++++++++-------
 .../apache/doris/planner/ConstantExpressTest.java  |  2 +-
 2 files changed, 18 insertions(+), 8 deletions(-)

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 72c566067a..52b2029e04 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
@@ -68,10 +68,8 @@ public class DateLiteral extends LiteralExpr {
     private static final DateLiteral MAX_DATETIMEV2
             = new DateLiteral(9999, 12, 31, 23, 59, 59, 999999L);
     private static final int DATEKEY_LENGTH = 8;
+    private static final int DATETIMEKEY_LENGTH = 14;
     private static final int MAX_MICROSECOND = 999999;
-    private static final int DATETIME_TO_MINUTE_STRING_LENGTH = 16;
-    private static final int DATETIME_TO_HOUR_STRING_LENGTH = 13;
-    private static final int DATETIME_TO_SECOND_STRING_LENGTH = 19;
 
     private static DateTimeFormatter DATE_TIME_FORMATTER = null;
     private static DateTimeFormatter DATE_TIME_FORMATTER_TO_MICRO_SECOND = null;
@@ -82,6 +80,8 @@ public class DateLiteral extends LiteralExpr {
      *  and data in the form of 'yyyymmdd' is generally called the datekey type.
      */
     private static DateTimeFormatter DATEKEY_FORMATTER = null;
+    // 'yyyymmddHHMMss'
+    private static DateTimeFormatter DATETIMEKEY_FORMATTER = null;
 
     private static Map<String, Integer> MONTH_NAME_DICT = Maps.newHashMap();
     private static Map<String, Integer> MONTH_ABBR_NAME_DICT = Maps.newHashMap();
@@ -96,6 +96,7 @@ public class DateLiteral extends LiteralExpr {
             DATE_TIME_FORMATTER = formatBuilder("%Y-%m-%d %H:%i:%s").toFormatter();
             DATE_FORMATTER = formatBuilder("%Y-%m-%d").toFormatter();
             DATEKEY_FORMATTER = formatBuilder("%Y%m%d").toFormatter();
+            DATETIMEKEY_FORMATTER = formatBuilder("%Y%m%d%H%i%s").toFormatter();
             DATE_TIME_FORMATTER_TO_MICRO_SECOND = new DateTimeFormatterBuilder()
                     .appendPattern("uuuu-MM-dd HH:mm:ss")
                     .appendFraction(ChronoField.NANO_OF_SECOND, 0, 6, true)
@@ -324,6 +325,9 @@ public class DateLiteral extends LiteralExpr {
             if (s.length() == DATEKEY_LENGTH && !s.contains("-")) {
                 // handle format like 20210106, but should not handle 2021-1-6
                 dateTime = DATEKEY_FORMATTER.parse(s);
+            } else if (s.length() == DATETIMEKEY_LENGTH && !s.contains("-")) {
+                // handle format like 20210106, but should not handle 2021-1-6
+                dateTime = DATETIMEKEY_FORMATTER.parse(s);
             } else {
                 String[] datePart = s.contains(" ") ? s.split(" ")[0].split("-") : s.split("-");
                 DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
@@ -493,8 +497,12 @@ public class DateLiteral extends LiteralExpr {
         if (type.isDate() || type.isDateV2()) {
             return String.format("%04d-%02d-%02d", year, month, day);
         } else if (type.isDatetimeV2()) {
-            return String.format("%04d-%02d-%02d %02d:%02d:%02d.%06d",
-                    year, month, day, hour, minute, second, microsecond);
+            String tmp = String.format("%04d-%02d-%02d %02d:%02d:%02d",
+                    year, month, day, hour, minute, second);
+            if (microsecond == 0) {
+                return tmp;
+            }
+            return tmp + String.format(".%06d", microsecond);
         } else {
             return String.format("%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second);
         }
@@ -606,9 +614,10 @@ public class DateLiteral extends LiteralExpr {
         } else if (this.type.equals(Type.DATE)) {
             out.writeShort(DateLiteralType.DATE.value());
             out.writeLong(makePackedDatetime());
-        } else if (this.type.equals(Type.DATETIMEV2)) {
+        } else if (this.type.getPrimitiveType() == PrimitiveType.DATETIMEV2) {
             out.writeShort(DateLiteralType.DATETIMEV2.value());
             out.writeLong(makePackedDatetimeV2());
+            out.writeInt(((ScalarType) this.type).getScalarScale());
         } else if (this.type.equals(Type.DATEV2)) {
             out.writeShort(DateLiteralType.DATEV2.value());
             out.writeLong(makePackedDatetimeV2());
@@ -664,7 +673,8 @@ public class DateLiteral extends LiteralExpr {
             this.type = Type.DATE;
         } else if (dateLiteralType == DateLiteralType.DATETIMEV2.value()) {
             fromPackedDatetime(in.readLong());
-            this.type = Type.DATETIMEV2;
+            int scale = in.readInt();
+            this.type = ScalarType.createDatetimeV2Type(scale);
         } else if (dateLiteralType == DateLiteralType.DATEV2.value()) {
             fromPackedDatetime(in.readLong());
             this.type = Type.DATEV2;
diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/ConstantExpressTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/ConstantExpressTest.java
index cc753fe58c..d73a106ae6 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/planner/ConstantExpressTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/planner/ConstantExpressTest.java
@@ -140,7 +140,7 @@ public class ConstantExpressTest {
 
         testConstantExpressResult(
                 "select cast ('2020-01-20 00:00:00' as datetime(0));",
-                "'2020-01-20 00:00:00.000000'");
+                "'2020-01-20 00:00:00'");
     }
 
     @Test


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