This is an automated email from the ASF dual-hosted git repository.
dataroaring pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-1.2-lts by this push:
new c3386b1abe [branch-1.2](datetime) Fix inserting datetimev2 with
timezone (#23453)
c3386b1abe is described below
commit c3386b1abeab308d3b564b6a5ab55323d35fc8ae
Author: zclllyybb <[email protected]>
AuthorDate: Fri Aug 25 12:59:30 2023 +0800
[branch-1.2](datetime) Fix inserting datetimev2 with timezone (#23453)
---
be/src/vec/runtime/vdatetime_value.cpp | 3 ++
.../org/apache/doris/analysis/DateLiteral.java | 11 +++++
.../datatype_p0/datetimev2/test_with_suffix.csv | 4 ++
.../datatype_p0/datetimev2/test_with_suffix.out | 11 +++++
.../datatype_p0/datetimev2/test_with_suffix.groovy | 49 ++++++++++++++++++++++
5 files changed, 78 insertions(+)
diff --git a/be/src/vec/runtime/vdatetime_value.cpp
b/be/src/vec/runtime/vdatetime_value.cpp
index a9e98b2ef8..dedac5f457 100644
--- a/be/src/vec/runtime/vdatetime_value.cpp
+++ b/be/src/vec/runtime/vdatetime_value.cpp
@@ -1836,6 +1836,9 @@ bool DateV2Value<T>::from_date_str(const char* date_str,
int len, int scale) {
while (ptr < end && isspace(*ptr)) {
ptr++;
}
+ while (ptr < end && isalpha(*(end - 1))) {
+ end--;
+ }
if (ptr == end || !isdigit(*ptr)) {
return false;
}
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 e9d08ace60..6e07904869 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
@@ -358,6 +358,9 @@ public class DateLiteral extends LiteralExpr {
Preconditions.checkArgument(type.isDateType());
TemporalAccessor dateTime = null;
boolean parsed = false;
+
+ s = skipTrailingNonDigit(s);
+
if (!s.contains("-")) {
// handle format like 20210106, but should not handle 2021-1-6
for (DateTimeFormatter formatter : formatterList) {
@@ -1707,4 +1710,12 @@ public class DateLiteral extends LiteralExpr {
second = 0;
microsecond = 0;
}
+
+ private static String skipTrailingNonDigit(String str) {
+ int split = str.length() - 1;
+ for (; split > 0 && !Character.isDigit(str.charAt(split)) &&
str.charAt(split) != '.'; split--) {
+ ;
+ }
+ return str.substring(0, split + 1);
+ }
}
diff --git a/regression-test/data/datatype_p0/datetimev2/test_with_suffix.csv
b/regression-test/data/datatype_p0/datetimev2/test_with_suffix.csv
new file mode 100644
index 0000000000..8c690fec90
--- /dev/null
+++ b/regression-test/data/datatype_p0/datetimev2/test_with_suffix.csv
@@ -0,0 +1,4 @@
+2020-05-12 12:12:12.123,2020-05-12 12:12:12.123
+2020-06-12 12:12:12.123Z,2020-06-12 12:12:12.123Z
+2020-07-12 12:12:12.UTC,2020-07-12 12:12:12.UTC"
+2020-08-12 12:12:12.123456XYZ,2020-08-12 12:12:12.123456XYZ
\ No newline at end of file
diff --git a/regression-test/data/datatype_p0/datetimev2/test_with_suffix.out
b/regression-test/data/datatype_p0/datetimev2/test_with_suffix.out
new file mode 100644
index 0000000000..0d9024e088
--- /dev/null
+++ b/regression-test/data/datatype_p0/datetimev2/test_with_suffix.out
@@ -0,0 +1,11 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !all --
+2020-01-12T12:12:12.123 2020-01-12T12:12:12.123
+2020-02-12T12:12:12.123 2020-02-12T12:12:12.123
+2020-03-12T12:12:12 2020-03-12T12:12:12
+2020-04-12T12:12:12.123 2020-04-12T12:12:12.123456
+2020-05-12T12:12:12.123 2020-05-12T12:12:12.123
+2020-06-12T12:12:12.123 2020-06-12T12:12:12.123
+2020-07-12T12:12:12 2020-07-12T12:12:12
+2020-08-12T12:12:12.123 2020-08-12T12:12:12.123456
+
diff --git
a/regression-test/suites/datatype_p0/datetimev2/test_with_suffix.groovy
b/regression-test/suites/datatype_p0/datetimev2/test_with_suffix.groovy
new file mode 100644
index 0000000000..a76d0d0913
--- /dev/null
+++ b/regression-test/suites/datatype_p0/datetimev2/test_with_suffix.groovy
@@ -0,0 +1,49 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_with_suffix") {
+ def tableName = "datetime"
+
+ sql "drop table if exists ${tableName}"
+ sql """
+ CREATE TABLE IF NOT EXISTS ${tableName} (
+ `k1` datetimev2(3) NULL,
+ `k2` datetimev2(6) NULL
+ ) ENGINE=OLAP
+ DUPLICATE KEY(`k1`)
+ DISTRIBUTED BY HASH(`k1`) BUCKETS 3
+ PROPERTIES (
+ "replication_num" = "1"
+ )
+ """
+
+ sql """ insert into ${tableName} values
+ ("2020-01-12 12:12:12.123", "2020-01-12 12:12:12.123"),
+ ("2020-02-12 12:12:12.123Z", "2020-02-12 12:12:12.123Z"),
+ ("2020-03-12 12:12:12.UTC", "2020-03-12 12:12:12.UTC"),
+ ("2020-04-12 12:12:12.123456XYZ", "2020-04-12 12:12:12.123456XYZ") """
+
+ streamLoad {
+ table "${tableName}"
+ set 'column_separator', ','
+ file "test_with_suffix.csv"
+ time 10000
+ }
+ sql "sync"
+
+ qt_all "select * from ${tableName} order by k1"
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]