This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new 803d3a1545c Revert "[fix](date_function) fix str_to_date function
return wrong microsecond issue" (#47441)
803d3a1545c is described below
commit 803d3a1545c6f59b32cb983ed868f9eaec623bfe
Author: yiguolei <[email protected]>
AuthorDate: Sun Jan 26 12:53:11 2025 +0800
Revert "[fix](date_function) fix str_to_date function return wrong
microsecond issue" (#47441)
---
.../org/apache/doris/analysis/DateLiteral.java | 12 +--
.../apache/doris/analysis/FunctionCallExpr.java | 6 +-
.../executable/DateTimeExtractAndTransform.java | 4 +-
.../expressions/functions/scalar/StrToDate.java | 3 +-
.../array_functions/test_array_with_scale_type.out | Bin 7864 -> 7860 bytes
.../jdbc/test_oracle_jdbc_catalog.groovy | 2 +-
.../test_date_function_v2.groovy | 84 ---------------------
7 files changed, 6 insertions(+), 105 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 7685a24ab1b..67d99b1b06e 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
@@ -111,7 +111,6 @@ public class DateLiteral extends LiteralExpr {
private static Map<String, Integer> WEEK_DAY_NAME_DICT = Maps.newHashMap();
private static Set<Character> TIME_PART_SET = Sets.newHashSet();
private static final int[] DAYS_IN_MONTH = new int[] {0, 31, 28, 31, 30,
31, 30, 31, 31, 30, 31, 30, 31};
- private static String MICRO_SECOND_FORMATTER = "%f";
private static final WeekFields weekFields =
WeekFields.of(DayOfWeek.SUNDAY, 7);
static {
@@ -718,7 +717,7 @@ public class DateLiteral extends LiteralExpr {
int scale = ((ScalarType) type).getScalarScale();
long scaledMicroseconds = (long) (microsecond /
SCALE_FACTORS[scale]);
- if (scale > 0) {
+ if (scaledMicroseconds != 0) {
dateTimeChars[19] = '.';
fillPaddedValue(dateTimeChars, 20, (int) scaledMicroseconds,
scale);
return new String(dateTimeChars, 0, 20 + scale);
@@ -1063,10 +1062,6 @@ public class DateLiteral extends LiteralExpr {
return format.chars().anyMatch(c -> TIME_PART_SET.contains((char) c));
}
- public static boolean hasMicroSecondPart(String format) {
- return format.indexOf(MICRO_SECOND_FORMATTER) != -1;
- }
-
// Return the date stored in the dateliteral as pattern format.
// eg : "%Y-%m-%d" or "%Y-%m-%d %H:%i:%s"
public String dateFormat(String pattern) throws AnalysisException {
@@ -1609,9 +1604,6 @@ public class DateLiteral extends LiteralExpr {
case 'T':
partUsed |= timePart;
break;
- case 'f':
- partUsed |= fracPart;
- break;
default:
break;
}
@@ -1673,7 +1665,7 @@ public class DateLiteral extends LiteralExpr {
// Compute timestamp type
if ((partUsed & datePart) != 0) { // Ymd part only
- if (hasMicroSecondPart(format)) {
+ if ((partUsed & fracPart) != 0) {
this.type = Type.DATETIMEV2_WITH_MAX_SCALAR;
} else if ((partUsed & timePart) != 0) {
this.type = ScalarType.getDefaultDateType(Type.DATETIME);
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
index c87ef4d144f..8d71bdc3557 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
@@ -1993,11 +1993,7 @@ public class FunctionCallExpr extends Expr {
Expr child1Result = getChild(1).getResultValue(false);
if (child1Result instanceof StringLiteral) {
if (DateLiteral.hasTimePart(child1Result.getStringValue())) {
- if
(DateLiteral.hasMicroSecondPart(child1Result.getStringValue())) {
- this.type = Type.DATETIMEV2_WITH_MAX_SCALAR;
- } else {
- this.type = Type.DEFAULT_DATETIMEV2;
- }
+ this.type = Type.DATETIMEV2_WITH_MAX_SCALAR;
} else {
this.type = Type.DATEV2;
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java
index d0023ed2ff6..1f6f3afd7d4 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java
@@ -628,10 +628,8 @@ public class DateTimeExtractAndTransform {
if
(org.apache.doris.analysis.DateLiteral.hasTimePart(format.getStringValue())) {
DataType returnType =
DataType.fromCatalogType(ScalarType.getDefaultDateType(Type.DATETIME));
if (returnType instanceof DateTimeV2Type) {
- boolean hasMicroPart = org.apache.doris.analysis.DateLiteral
- .hasMicroSecondPart(format.getStringValue());
return
DateTimeV2Literal.fromJavaDateType(DateUtils.getTime(DateUtils.formatBuilder(format.getValue())
- .toFormatter(), str.getValue()), hasMicroPart ? 6 : 0);
+ .toFormatter(), str.getValue()));
} else {
return
DateTimeLiteral.fromJavaDateType(DateUtils.getTime(DateUtils.formatBuilder(format.getValue())
.toFormatter(), str.getValue()));
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/StrToDate.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/StrToDate.java
index c768a25ba38..ff014db6bca 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/StrToDate.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/StrToDate.java
@@ -88,8 +88,7 @@ public class StrToDate extends ScalarFunction
if (getArgument(1) instanceof StringLikeLiteral) {
if (DateLiteral.hasTimePart(((StringLikeLiteral)
getArgument(1)).getStringValue())) {
returnType =
DataType.fromCatalogType(ScalarType.getDefaultDateType(Type.DATETIME));
- if (returnType.isDateTimeV2Type()
- && DateLiteral.hasMicroSecondPart(((StringLikeLiteral)
getArgument(1)).getStringValue())) {
+ if (returnType.isDateTimeV2Type()) {
returnType =
DataType.fromCatalogType(Type.DATETIMEV2_WITH_MAX_SCALAR);
}
} else {
diff --git
a/regression-test/data/query_p0/sql_functions/array_functions/test_array_with_scale_type.out
b/regression-test/data/query_p0/sql_functions/array_functions/test_array_with_scale_type.out
index 9388c801878..446a96fa2ae 100644
Binary files
a/regression-test/data/query_p0/sql_functions/array_functions/test_array_with_scale_type.out
and
b/regression-test/data/query_p0/sql_functions/array_functions/test_array_with_scale_type.out
differ
diff --git
a/regression-test/suites/external_table_p0/jdbc/test_oracle_jdbc_catalog.groovy
b/regression-test/suites/external_table_p0/jdbc/test_oracle_jdbc_catalog.groovy
index cb2633e404c..d2b3669ab45 100644
---
a/regression-test/suites/external_table_p0/jdbc/test_oracle_jdbc_catalog.groovy
+++
b/regression-test/suites/external_table_p0/jdbc/test_oracle_jdbc_catalog.groovy
@@ -134,7 +134,7 @@ suite("test_oracle_jdbc_catalog",
"p0,external,oracle,external_docker,external_d
order_qt_date4 """ select * from TEST_DATE where (T1 > '2022-01-21
00:00:00' and T1 < '2022-01-22 00:00:00') or (T1 > '2022-01-20 00:00:00' and T1
< '2022-01-23 00:00:00'); """
order_qt_date5 """ select * from TEST_DATE where T1 < '2022-01-22
00:00:00' or T1 = '2022-01-21 05:23:01'; """
order_qt_date6 """ select * from TEST_DATE where (T1 < '2022-01-22
00:00:00' or T1 > '2022-01-20 00:00:00') and (T1 < '2022-01-23 00:00:00' or T1
> '2022-01-19 00:00:00'); """
- order_qt_date7 """select * from TEST_TIMESTAMP where T2 <
str_to_date('2020-12-21 12:34:56', '%Y-%m-%d %H:%i:%s.%f');"""
+ order_qt_date7 """select * from TEST_TIMESTAMP where T2 <
str_to_date('2020-12-21 12:34:56', '%Y-%m-%d %H:%i:%s');"""
// test nvl
explain {
diff --git
a/regression-test/suites/nereids_p0/sql_functions/datetime_functions/test_date_function_v2.groovy
b/regression-test/suites/nereids_p0/sql_functions/datetime_functions/test_date_function_v2.groovy
deleted file mode 100644
index 8b24c9d9c3f..00000000000
---
a/regression-test/suites/nereids_p0/sql_functions/datetime_functions/test_date_function_v2.groovy
+++ /dev/null
@@ -1,84 +0,0 @@
-// 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_date_function_v2") {
- sql """
- admin set frontend config ("enable_date_conversion"="true");
- """
- sql """SET enable_nereids_planner=true"""
-
- def tableName = "test_date_function_v2"
-
- sql """ DROP TABLE IF EXISTS ${tableName} """
- sql """
- CREATE TABLE IF NOT EXISTS ${tableName} (
- `id` INT,
- `name` varchar(32),
- `dt` varchar(32)
- ) ENGINE=OLAP
- UNIQUE KEY(`id`)
- DISTRIBUTED BY HASH(`id`) BUCKETS 1
- PROPERTIES (
- "replication_allocation" = "tag.location.default: 1"
- )
- """
- sql """ insert into ${tableName} values (3, 'Carl','2024-12-29 10:11:12')
"""
- def result1 = try_sql """
- select cast(str_to_date(dt, '%Y-%m-%d %H:%i:%s') as string) from
${tableName};
- """
- assertEquals(result1[0][0], "2024-12-29 10:11:12");
-
- def result2 = try_sql """
- select cast(str_to_date(dt, '%Y-%m-%d %H:%i:%s.%f') as string) from
${tableName};
- """
- assertEquals(result2[0][0], "2024-12-29 10:11:12.000000");
-
- def result3 = try_sql """
- select cast(str_to_date("2025-01-17 11:59:30", '%Y-%m-%d %H:%i:%s') as
string);
- """
- assertEquals(result3[0][0], "2025-01-17 11:59:30");
-
- def result4 = try_sql """
- select cast(str_to_date("2025-01-17 11:59:30", '%Y-%m-%d %H:%i:%s.%f')
as string);
- """
- assertEquals(result4[0][0], "2025-01-17 11:59:30.000000");
-
- // test legacy planner
- sql """SET enable_nereids_planner=false"""
- def result5 = try_sql """
- select cast(str_to_date(dt, '%Y-%m-%d %H:%i:%s') as string) from
${tableName};
- """
- assertEquals(result5[0][0], "2024-12-29 10:11:12");
-
- result5 = try_sql """
- select cast(str_to_date(dt, '%Y-%m-%d %H:%i:%s.%f') as string) from
${tableName};
- """
- assertEquals(result5[0][0], "2024-12-29 10:11:12.000000");
-
- result5 = try_sql """
- select cast(str_to_date('2025-01-17 11:59:30', '%Y-%m-%d %H:%i:%s') as
string);
- """
- assertEquals(result5[0][0], "2025-01-17 11:59:30");
-
- result5 = try_sql """
- select cast(str_to_date('2025-01-17 11:59:30', '%Y-%m-%d %H:%i:%s.%f')
as string);
- """
- assertEquals(result5[0][0], "2025-01-17 11:59:30.000000");
-
-
- sql """ drop table ${tableName} """
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]