From 4cc1f8e52d691f8be6eaf4887dbff07877f59a3b Mon Sep 17 00:00:00 2001 From: HarrisChu <1726587+HarrisChu@users.noreply.github.com> Date: Mon, 27 Nov 2023 17:59:29 +0800 Subject: [PATCH] fix round crash --- src/common/function/FunctionManager.cpp | 2 +- .../features/expression/FunctionCall.feature | 32 ++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/common/function/FunctionManager.cpp b/src/common/function/FunctionManager.cpp index 0d9e6cd93ee..cc2393a775d 100644 --- a/src/common/function/FunctionManager.cpp +++ b/src/common/function/FunctionManager.cpp @@ -584,7 +584,7 @@ FunctionManager::FunctionManager() { case Value::Type::FLOAT: { if (args.size() >= 2) { if (args[1].get().type() == Value::Type::INT) { - auto val = args[0].get().getFloat(); + auto val = args[0].get().isInt() ? args[0].get().getInt() : args[0].get().getFloat(); auto decimal = args[1].get().getInt(); auto factor = pow(10.0, decimal); diff --git a/tests/tck/features/expression/FunctionCall.feature b/tests/tck/features/expression/FunctionCall.feature index dc569e50294..541f5b1443b 100644 --- a/tests/tck/features/expression/FunctionCall.feature +++ b/tests/tck/features/expression/FunctionCall.feature @@ -10,7 +10,7 @@ Feature: Function Call Expression When executing query: """ YIELD sign(38) AS a, sign(-2) AS b, sign(0.421) AS c, - sign(-1.0) AS d, sign(0) AS e, sign(abs(-3)) AS f + sign(-1.0) AS d, sign(0) AS e, sign(abs(-3)) AS f """ Then the result should be, in any order: | a | b | c | d | e | f | @@ -185,6 +185,36 @@ Feature: Function Call Expression | result | | 0.0 | + Scenario: round int + When executing query: + """ + YIELD round(12345, 2) as result + """ + Then the result should be, in any order: + | result | + | 12345.0 | + When executing query: + """ + YIELD round(12345, 0) as result + """ + Then the result should be, in any order: + | result | + | 12345.0 | + When executing query: + """ + YIELD round(12345, -2) as result + """ + Then the result should be, in any order: + | result | + | 12300.0 | + When executing query: + """ + YIELD round(12345, -5) as result + """ + Then the result should be, in any order: + | result | + | 0.0 | + Scenario: error check When executing query: """