This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch branch-1.1-lts in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-1.1-lts by this push: new 97e51a11e0 [Bug](date) Fix wrong result produced by date function (#12870) 97e51a11e0 is described below commit 97e51a11e068dc44e7390e9e66279d4858e188a0 Author: Gabriel <gabrielleeb...@gmail.com> AuthorDate: Fri Sep 23 08:50:36 2022 +0800 [Bug](date) Fix wrong result produced by date function (#12870) --- .../src/main/java/org/apache/doris/analysis/DateLiteral.java | 6 +++++- .../src/test/java/org/apache/doris/rewrite/FEFunctionsTest.java | 8 ++++---- 2 files changed, 9 insertions(+), 5 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 9de0ae375d..5531936bd0 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 @@ -387,7 +387,11 @@ public class DateLiteral extends LiteralExpr { @Override public long getLongValue() { - return (year * 10000 + month * 100 + day) * 1000000L + hour * 10000 + minute * 100 + second; + if (this.getType().isDate()) { + return year * 10000 + month * 100 + day; + } else { + return (year * 10000 + month * 100 + day) * 1000000L + hour * 10000 + minute * 100 + second; + } } @Override diff --git a/fe/fe-core/src/test/java/org/apache/doris/rewrite/FEFunctionsTest.java b/fe/fe-core/src/test/java/org/apache/doris/rewrite/FEFunctionsTest.java index af93c5ceda..66d7920171 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/rewrite/FEFunctionsTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/rewrite/FEFunctionsTest.java @@ -98,22 +98,22 @@ public class FEFunctionsTest { @Test public void dateAddTest() throws AnalysisException { DateLiteral actualResult = FEFunctions.dateAdd(new DateLiteral("2018-08-08", Type.DATE), new IntLiteral(1)); - DateLiteral expectedResult = new DateLiteral("2018-08-09 00:00:00", Type.DATETIME); + DateLiteral expectedResult = new DateLiteral("2018-08-09", Type.DATE); Assert.assertEquals(expectedResult, actualResult); actualResult = FEFunctions.dateAdd(new DateLiteral("2018-08-08", Type.DATE), new IntLiteral(-1)); - expectedResult = new DateLiteral("2018-08-07 00:00:00", Type.DATETIME); + expectedResult = new DateLiteral("2018-08-07", Type.DATE); Assert.assertEquals(expectedResult, actualResult); } @Test public void addDateTest() throws AnalysisException { DateLiteral actualResult = FEFunctions.addDate(new DateLiteral("2018-08-08", Type.DATE), new IntLiteral(1)); - DateLiteral expectedResult = new DateLiteral("2018-08-09 00:00:00", Type.DATETIME); + DateLiteral expectedResult = new DateLiteral("2018-08-09", Type.DATE); Assert.assertEquals(expectedResult, actualResult); actualResult = FEFunctions.addDate(new DateLiteral("2018-08-08", Type.DATE), new IntLiteral(-1)); - expectedResult = new DateLiteral("2018-08-07 00:00:00", Type.DATETIME); + expectedResult = new DateLiteral("2018-08-07", Type.DATE); Assert.assertEquals(expectedResult, actualResult); } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org