[fix](func) fix truncate float type result error (#16468)

When the argument of truncate function is float type, it can match both truncate(DECIMALV3) and truncate(DOUBLE), if the match is truncate(DECIMALV3), the precision is lost when converting float to DECIMALV3(38, 0).

Here I modify it to match truncate(DOUBLE) for now, maybe we still need to solve the problem of losing precision when converting float to DECIMALV3.
This commit is contained in:
luozenglin
2023-02-08 08:57:43 +08:00
committed by GitHub
parent cf18de14b5
commit 289a4b2ea4
3 changed files with 9 additions and 1 deletions

View File

@ -980,10 +980,10 @@ visible_functions = [
[['ceil', 'dceil'], 'DECIMAL32', ['DECIMAL32', 'INT'], ''],
[['ceil', 'dceil'], 'DECIMAL64', ['DECIMAL64', 'INT'], ''],
[['ceil', 'dceil'], 'DECIMAL128', ['DECIMAL128', 'INT'], ''],
[['truncate'], 'DOUBLE', ['DOUBLE', 'INT'], ''],
[['truncate'], 'DECIMAL32', ['DECIMAL32', 'INT'], ''],
[['truncate'], 'DECIMAL64', ['DECIMAL64', 'INT'], ''],
[['truncate'], 'DECIMAL128', ['DECIMAL128', 'INT'], ''],
[['truncate'], 'DOUBLE', ['DOUBLE', 'INT'], ''],
[['ln', 'dlog1'], 'DOUBLE', ['DOUBLE'], 'ALWAYS_NULLABLE'],
[['log'], 'DOUBLE', ['DOUBLE', 'DOUBLE'], 'ALWAYS_NULLABLE'],

View File

@ -11,6 +11,11 @@
-- !select --
10.12
-- !truncate --
1.0 1989.0 1001.0 123.1 0.1 6.3
2.0 1986.0 1001.0 1243.5 20.2 789.2
3.0 1989.0 1002.0 24453.3 78945.0 3654.0
-- !select --
16.000 16.00000 16.00000

View File

@ -21,6 +21,9 @@ suite("test_round") {
qt_select "SELECT round_bankers(10.12345)"
qt_select "SELECT round_bankers(10.12345, 2)"
def tableTest = "test_query_db.test"
qt_truncate "select truncate(k1, 1), truncate(k2, 1), truncate(k3, 1), truncate(k5, 1), truncate(k8, 1), truncate(k9, 1) from ${tableTest} order by 1;"
def tableName = "test_round"
sql """DROP TABLE IF EXISTS `${tableName}`"""
sql """ CREATE TABLE `${tableName}` (