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 e7d4dda3c84 branch-2.1: [Fix](function) Fix wrong FE fold constant implementation of function date_format #49032 (#49086) e7d4dda3c84 is described below commit e7d4dda3c8420bcc0ce751760e65f87c9425b3fd Author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> AuthorDate: Sun Mar 16 20:16:40 2025 +0800 branch-2.1: [Fix](function) Fix wrong FE fold constant implementation of function date_format #49032 (#49086) Cherry-picked from #49032 Co-authored-by: zclllyybb <zhaochan...@selectdb.com> --- .../functions/executable/DateTimeExtractAndTransform.java | 8 ++++---- .../src/main/java/org/apache/doris/nereids/util/DateUtils.java | 8 +++++--- .../fold_constant/fold_constant_date_arithmatic.groovy | 9 +++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) 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 c9082715318..bd1915c2d82 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 @@ -295,14 +295,14 @@ public class DateTimeExtractAndTransform { @ExecFunction(name = "date_format") public static Expression dateFormat(DateLiteral date, StringLikeLiteral format) { format = (StringLikeLiteral) SupportJavaDateFormatter.translateJavaFormatter(format); - return new VarcharLiteral(DateUtils.formatBuilder(format.getValue()).toFormatter().format( + return new VarcharLiteral(DateUtils.formatBuilder(format.getValue()).toFormatter(Locale.US).format( java.time.LocalDate.of(((int) date.getYear()), ((int) date.getMonth()), ((int) date.getDay())))); } @ExecFunction(name = "date_format") public static Expression dateFormat(DateTimeLiteral date, StringLikeLiteral format) { format = (StringLikeLiteral) SupportJavaDateFormatter.translateJavaFormatter(format); - return new VarcharLiteral(DateUtils.formatBuilder(format.getValue()).toFormatter().format( + return new VarcharLiteral(DateUtils.formatBuilder(format.getValue()).toFormatter(Locale.US).format( java.time.LocalDateTime.of(((int) date.getYear()), ((int) date.getMonth()), ((int) date.getDay()), ((int) date.getHour()), ((int) date.getMinute()), ((int) date.getSecond())))); } @@ -310,14 +310,14 @@ public class DateTimeExtractAndTransform { @ExecFunction(name = "date_format") public static Expression dateFormat(DateV2Literal date, StringLikeLiteral format) { format = (StringLikeLiteral) SupportJavaDateFormatter.translateJavaFormatter(format); - return new VarcharLiteral(DateUtils.formatBuilder(format.getValue()).toFormatter().format( + return new VarcharLiteral(DateUtils.formatBuilder(format.getValue()).toFormatter(Locale.US).format( java.time.LocalDate.of(((int) date.getYear()), ((int) date.getMonth()), ((int) date.getDay())))); } @ExecFunction(name = "date_format") public static Expression dateFormat(DateTimeV2Literal date, StringLikeLiteral format) { format = (StringLikeLiteral) SupportJavaDateFormatter.translateJavaFormatter(format); - return new VarcharLiteral(DateUtils.formatBuilder(format.getValue()).toFormatter().format( + return new VarcharLiteral(DateUtils.formatBuilder(format.getValue()).toFormatter(Locale.US).format( java.time.LocalDateTime.of(((int) date.getYear()), ((int) date.getMonth()), ((int) date.getDay()), ((int) date.getHour()), ((int) date.getMinute()), ((int) date.getSecond())))); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/DateUtils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/DateUtils.java index 354d78d0271..c0563de5d10 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/util/DateUtils.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/util/DateUtils.java @@ -68,7 +68,7 @@ public class DateUtils { break; case 'h': // %h Hour (01..12) case 'I': // %I Hour (01..12) - builder.appendValue(ChronoField.HOUR_OF_AMPM, 2); + builder.appendValue(ChronoField.CLOCK_HOUR_OF_AMPM, 2); break; case 'i': // %i Minutes, numeric (00..59) builder.appendValue(ChronoField.MINUTE_OF_HOUR, 2); @@ -80,7 +80,7 @@ public class DateUtils { builder.appendValue(ChronoField.HOUR_OF_DAY); break; case 'l': // %l Hour (1..12) - builder.appendValue(ChronoField.HOUR_OF_AMPM); + builder.appendValue(ChronoField.CLOCK_HOUR_OF_AMPM); break; case 'M': // %M Month name (January..December) builder.appendText(ChronoField.MONTH_OF_YEAR, TextStyle.FULL); @@ -92,8 +92,10 @@ public class DateUtils { builder.appendText(ChronoField.AMPM_OF_DAY); break; case 'r': // %r Time, 12-hour (hh:mm:ss followed by AM or PM) - builder.appendValue(ChronoField.HOUR_OF_AMPM, 2) + builder.appendValue(ChronoField.CLOCK_HOUR_OF_AMPM, 2) + .appendLiteral(':') .appendValue(ChronoField.MINUTE_OF_HOUR, 2) + .appendLiteral(':') .appendValue(ChronoField.SECOND_OF_MINUTE, 2) .appendLiteral(' ') .appendText(ChronoField.AMPM_OF_DAY, TextStyle.FULL) diff --git a/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_date_arithmatic.groovy b/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_date_arithmatic.groovy index 5e0ed2e5d25..e19a01b2a38 100644 --- a/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_date_arithmatic.groovy +++ b/regression-test/suites/nereids_p0/expression/fold_constant/fold_constant_date_arithmatic.groovy @@ -29,4 +29,13 @@ suite("fold_constant_date_arithmatic") { testFoldConst("select substr(current_date(), 1, 10);") testFoldConst("select substr(current_timestamp(), 1, 10);") testFoldConst("select substr(current_timestamp(3), 1, 10);") + + testFoldConst("SELECT date_format('2020-12-01 00:00:30.01', '%h');") + testFoldConst("SELECT date_format('2020-12-01 00:00:30.01', '%I');") + testFoldConst("SELECT date_format('2020-12-01 00:00:30.01', '%l');") + testFoldConst("SELECT date_format('2020-12-01 00:00:30.01', '%r');") + testFoldConst("SELECT date_format('2020-12-01 12:00:30.01', '%h');") + testFoldConst("SELECT date_format('2020-12-01 12:00:30.01', '%I');") + testFoldConst("SELECT date_format('2020-12-01 12:00:30.01', '%l');") + testFoldConst("SELECT date_format('2020-12-01 12:00:30.01', '%r');") } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org