This is an automated email from the ASF dual-hosted git repository.
zclll 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 4fc6bdb569e [fix](function) fix convert_tz function fe time_zone range
problem (#56228)
4fc6bdb569e is described below
commit 4fc6bdb569ef616c353453f9b7dc60a9d9a7a069
Author: dwdwqfwe <[email protected]>
AuthorDate: Tue Sep 23 15:16:05 2025 +0800
[fix](function) fix convert_tz function fe time_zone range problem (#56228)
fe result is not the same as convert_tz when time zone over the range
BE:
mysql> select CONVERT_TZ('2019-08-01 13:21:03', '+08:00', '+18:00');
ERROR 1105 (HY000): errCode = 2, detailMessage =
(10.16.10.3)[INVALID_ARGUMENT][E33] Operation convert_tz invalid
timezone: +18:00
FE:
mysql> select CONVERT_TZ('2019-08-01 13:21:03', '+08:00', '+18:00');
+-------------------------------------------------------+
| CONVERT_TZ('2019-08-01 13:21:03', '+08:00', '+18:00') |
+-------------------------------------------------------+
| 2019-08-01 23:21:03 |
+-------------------------------------------------------+
---
.../executable/DateTimeExtractAndTransform.java | 28 +++++++++++++++++++++-
.../suites/correctness/test_timev2_fold.groovy | 8 +++++++
2 files changed, 35 insertions(+), 1 deletion(-)
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 b8b9fed5028..bcf3ac6f7d1 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
@@ -749,10 +749,14 @@ public class DateTimeExtractAndTransform {
}
/**
- * convert_tz
+ * date transformation function: convert_tz
*/
@ExecFunction(name = "convert_tz")
public static Expression convertTz(DateTimeV2Literal datetime,
StringLikeLiteral fromTz, StringLikeLiteral toTz) {
+ // Validate timezone offset ranges before parsing
+ validateTimezoneOffset(fromTz.getStringValue());
+ validateTimezoneOffset(toTz.getStringValue());
+
DateTimeFormatter zoneFormatter = new DateTimeFormatterBuilder()
.parseCaseInsensitive()
.appendZoneOrOffsetId()
@@ -766,6 +770,28 @@ public class DateTimeExtractAndTransform {
return
DateTimeV2Literal.fromJavaDateType(resultDateTime.toLocalDateTime(),
datetime.getDataType().getScale());
}
+ private static void validateTimezoneOffset(String timezone) {
+ // Pattern to match offset format like +HH:MM or -HH:MM
+ if (timezone.matches("^[+-]\\d{2}:\\d{2}$")) {
+ boolean positive = timezone.charAt(0) == '+';
+ int hour = Integer.parseInt(timezone.substring(1, 3));
+ int minute = Integer.parseInt(timezone.substring(4, 6));
+
+ if (!positive && hour > 12) {
+ throw new AnalysisException("Invalid timezone offset: " +
timezone
+ + ". Timezone offsets must be between -12:00 and
+14:00");
+ } else if (positive && hour > 14) {
+ throw new AnalysisException("Invalid timezone offset: " +
timezone
+ + ". Timezone offsets must be between -12:00 and
+14:00");
+ }
+
+ if (minute != 0 && minute != 15 && minute != 30 && minute != 45) {
+ throw new AnalysisException("Invalid timezone offset: " +
timezone
+ + ". Minute part should be 00, 15, 30, or 45");
+ }
+ }
+ }
+
@ExecFunction(name = "weekday")
public static Expression weekDay(DateLiteral date) {
return new TinyIntLiteral((byte)
((date.toJavaDateType().getDayOfWeek().getValue() + 6) % 7));
diff --git a/regression-test/suites/correctness/test_timev2_fold.groovy
b/regression-test/suites/correctness/test_timev2_fold.groovy
index ac7994922c0..72329fd005b 100644
--- a/regression-test/suites/correctness/test_timev2_fold.groovy
+++ b/regression-test/suites/correctness/test_timev2_fold.groovy
@@ -30,6 +30,14 @@ suite("test_timev2_fold") {
qt_select13 """
select CONVERT_TZ('9999-12-31 23:59:59.999999', 'Pacific/Galapagos',
'Pacific/GalapaGoS');
"""
+ test {
+ sql "select convert_tz('2020-05-01 12:00:00', '+08:00', '+15:00');"
+ exception "Operation convert_tz invalid timezone: +15:00"
+ }
+ test {
+ sql "select convert_tz('2020-05-01 12:00:00', '-13:00', '+12:00');"
+ exception "Operation convert_tz invalid timezone: -13:00"
+ }
// FE + BE
sql """ set enable_fold_constant_by_be=true """
qt_select20 """
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]