Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 54d18fb

Browse files
authored
fix round crash (vesoft-inc#5773)
1 parent 4c6a0a7 commit 54d18fb

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/common/function/FunctionManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ FunctionManager::FunctionManager() {
584584
case Value::Type::FLOAT: {
585585
if (args.size() >= 2) {
586586
if (args[1].get().type() == Value::Type::INT) {
587-
auto val = args[0].get().getFloat();
587+
auto val = args[0].get().isInt() ? args[0].get().getInt() : args[0].get().getFloat();
588588
auto decimal = args[1].get().getInt();
589589
auto factor = pow(10.0, decimal);
590590

tests/tck/features/expression/FunctionCall.feature

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Feature: Function Call Expression
1010
When executing query:
1111
"""
1212
YIELD sign(38) AS a, sign(-2) AS b, sign(0.421) AS c,
13-
sign(-1.0) AS d, sign(0) AS e, sign(abs(-3)) AS f
13+
sign(-1.0) AS d, sign(0) AS e, sign(abs(-3)) AS f
1414
"""
1515
Then the result should be, in any order:
1616
| a | b | c | d | e | f |
@@ -185,6 +185,36 @@ Feature: Function Call Expression
185185
| result |
186186
| 0.0 |
187187

188+
Scenario: round int
189+
When executing query:
190+
"""
191+
YIELD round(12345, 2) as result
192+
"""
193+
Then the result should be, in any order:
194+
| result |
195+
| 12345.0 |
196+
When executing query:
197+
"""
198+
YIELD round(12345, 0) as result
199+
"""
200+
Then the result should be, in any order:
201+
| result |
202+
| 12345.0 |
203+
When executing query:
204+
"""
205+
YIELD round(12345, -2) as result
206+
"""
207+
Then the result should be, in any order:
208+
| result |
209+
| 12300.0 |
210+
When executing query:
211+
"""
212+
YIELD round(12345, -5) as result
213+
"""
214+
Then the result should be, in any order:
215+
| result |
216+
| 0.0 |
217+
188218
Scenario: error check
189219
When executing query:
190220
"""

0 commit comments

Comments
 (0)