This is an automated email from the ASF dual-hosted git repository.

morrysnow 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 138be9e1ad [Fix](planner) normalize the behavior of from_unixtime() 
according to 2.0.0 (#21731)
138be9e1ad is described below

commit 138be9e1adc3d2601c514933984238937699a413
Author: mch_ucchi <41606806+sohardforan...@users.noreply.github.com>
AuthorDate: Thu Jul 13 14:41:31 2023 +0800

    [Fix](planner) normalize the behavior of from_unixtime() according to 2.0.0 
(#21731)
    
    if from_unixtime() receive an integer out of int range, the function 
returns null.
    cherry pick from master branch #21723
---
 .../src/main/java/org/apache/doris/rewrite/FEFunctions.java       | 8 ++++----
 .../src/test/java/org/apache/doris/rewrite/FEFunctionsTest.java   | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunctions.java 
b/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunctions.java
index 9c2023e77f..81cff97b1b 100755
--- a/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunctions.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/rewrite/FEFunctions.java
@@ -239,8 +239,8 @@ public class FEFunctions {
     @FEFunction(name = "from_unixtime", argTypes = { "INT" }, returnType = 
"VARCHAR")
     public static StringLiteral fromUnixTime(LiteralExpr unixTime) throws 
AnalysisException {
         // if unixTime < 0, we should return null, throw a exception and let 
BE process
-        if (unixTime.getLongValue() < 0) {
-            throw new AnalysisException("unixtime should larger than zero");
+        if (unixTime.getLongValue() < 0 || unixTime.getLongValue() >= 
Integer.MAX_VALUE) {
+            throw new AnalysisException("unix timestamp out of range");
         }
         DateLiteral dl = new DateLiteral(unixTime.getLongValue() * 1000, 
TimeUtils.getTimeZone(),
                 ScalarType.getDefaultDateType(Type.DATETIME));
@@ -250,8 +250,8 @@ public class FEFunctions {
     @FEFunction(name = "from_unixtime", argTypes = { "INT", "VARCHAR" }, 
returnType = "VARCHAR")
     public static StringLiteral fromUnixTime(LiteralExpr unixTime, 
StringLiteral fmtLiteral) throws AnalysisException {
         // if unixTime < 0, we should return null, throw a exception and let 
BE process
-        if (unixTime.getLongValue() < 0) {
-            throw new AnalysisException("unixtime should larger than zero");
+        if (unixTime.getLongValue() < 0 || unixTime.getLongValue() >= 
Integer.MAX_VALUE) {
+            throw new AnalysisException("unix timestamp out of range");
         }
         DateLiteral dl = new DateLiteral(unixTime.getLongValue() * 1000, 
TimeUtils.getTimeZone(),
                 ScalarType.getDefaultDateType(Type.DATETIME));
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 210a8635bc..f7cd440d8f 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
@@ -250,7 +250,7 @@ public class FEFunctionsTest {
     @Test
     public void fromUnixTimeTestException() throws AnalysisException {
         expectedEx.expect(AnalysisException.class);
-        expectedEx.expectMessage("unixtime should larger than zero");
+        expectedEx.expectMessage("unix timestamp out of range");
         FEFunctions.fromUnixTime(new IntLiteral(-100));
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to