Skip to content

Commit

Permalink
[test](decimal) add some cases about overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mrhhsg committed Dec 9, 2023
1 parent 42aa174 commit ffc3e17
Show file tree
Hide file tree
Showing 6 changed files with 561 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !select_all --
\N \N \N \N
1.10000 1.20000 1.56000 1.23400
1.10000 1.40000 1.50000 1.60000
1.20000 1.20000 1.34400 1.32432
1.20000 1.20000 1.66000 1.53465
1.30000 1.20000 1.45600 1.34544
2.10000 1.20000 1.30000 1.23400
2.10000 1.20000 1.30000 1.23420
2.20000 1.40000 1.21000 1.12300

-- !select_calc1 --
\N \N \N \N \N \N
1.10000 1.10000 2.20000 0.00000 1.2100000000 1.000000000
1.10000 1.10000 2.20000 0.00000 1.2100000000 1.000000000
1.20000 1.20000 2.40000 0.00000 1.4400000000 1.000000000
1.20000 1.20000 2.40000 0.00000 1.4400000000 1.000000000
1.30000 1.30000 2.60000 0.00000 1.6900000000 1.000000000
2.10000 2.10000 4.20000 0.00000 4.4100000000 1.000000000
2.10000 2.10000 4.20000 0.00000 4.4100000000 1.000000000
2.20000 2.20000 4.40000 0.00000 4.8400000000 1.000000000

-- !select_calc2 --
\N \N \N \N \N \N \N \N \N \N
1.10000 1.20000 2.30000 -0.10000 1.3200000000 0.916666666 2.30000 0.10000 1.3200000000 1.090909090
1.10000 1.40000 2.50000 -0.30000 1.5400000000 0.785714285 2.50000 0.30000 1.5400000000 1.272727272
1.20000 1.20000 2.40000 0.00000 1.4400000000 1.000000000 2.40000 0.00000 1.4400000000 1.000000000
1.20000 1.20000 2.40000 0.00000 1.4400000000 1.000000000 2.40000 0.00000 1.4400000000 1.000000000
1.30000 1.20000 2.50000 0.10000 1.5600000000 1.083333333 2.50000 -0.10000 1.5600000000 0.923076923
2.10000 1.20000 3.30000 0.90000 2.5200000000 1.750000000 3.30000 -0.90000 2.5200000000 0.571428571
2.10000 1.20000 3.30000 0.90000 2.5200000000 1.750000000 3.30000 -0.90000 2.5200000000 0.571428571
2.20000 1.40000 3.60000 0.80000 3.0800000000 1.571428571 3.60000 -0.80000 3.0800000000 0.636363636

-- !select_calc3 --
\N \N \N \N \N \N \N \N \N \N
1.10000 1.50000 2.60000 -0.40000 1.6500000000 0.733333333 2.60000 0.40000 1.6500000000 1.363636363
1.10000 1.56000 2.66000 -0.46000 1.7160000000 0.705128205 2.66000 0.46000 1.7160000000 1.418181818
1.20000 1.34400 2.54400 -0.14400 1.6128000000 0.892857142 2.54400 0.14400 1.6128000000 1.120000000
1.20000 1.66000 2.86000 -0.46000 1.9920000000 0.722891566 2.86000 0.46000 1.9920000000 1.383333333
1.30000 1.45600 2.75600 -0.15600 1.8928000000 0.892857142 2.75600 0.15600 1.8928000000 1.120000000
2.10000 1.30000 3.40000 0.80000 2.7300000000 1.615384615 3.40000 -0.80000 2.7300000000 0.619047619
2.10000 1.30000 3.40000 0.80000 2.7300000000 1.615384615 3.40000 -0.80000 2.7300000000 0.619047619
2.20000 1.21000 3.41000 0.99000 2.6620000000 1.818181818 3.41000 -0.99000 2.6620000000 0.550000000

-- !select_calc4 --
\N \N \N \N \N \N \N \N \N \N
1.10000 1.23400 2.33400 -0.13400 1.3574000000 0.891410048 2.33400 0.13400 1.3574000000 1.121818181
1.10000 1.60000 2.70000 -0.50000 1.7600000000 0.687500000 2.70000 0.50000 1.7600000000 1.454545454
1.20000 1.32432 2.52432 -0.12432 1.5891840000 0.906125407 2.52432 0.12432 1.5891840000 1.103600000
1.20000 1.53465 2.73465 -0.33465 1.8415800000 0.781937249 2.73465 0.33465 1.8415800000 1.278875000
1.30000 1.34544 2.64544 -0.04544 1.7490720000 0.966226661 2.64544 0.04544 1.7490720000 1.034953846
2.10000 1.23400 3.33400 0.86600 2.5914000000 1.701782820 3.33400 -0.86600 2.5914000000 0.587619047
2.10000 1.23420 3.33420 0.86580 2.5918200000 1.701507049 3.33420 -0.86580 2.5918200000 0.587714285
2.20000 1.12300 3.32300 1.07700 2.4706000000 1.959038290 3.32300 -1.07700 2.4706000000 0.510454545

-- !select_calc5 --
\N \N \N \N \N
1.20000 2.40000 0.00000 1.4400000000 1.000000000
1.20000 2.40000 0.00000 1.4400000000 1.000000000
1.20000 2.40000 0.00000 1.4400000000 1.000000000
1.20000 2.40000 0.00000 1.4400000000 1.000000000
1.20000 2.40000 0.00000 1.4400000000 1.000000000
1.20000 2.40000 0.00000 1.4400000000 1.000000000
1.40000 2.80000 0.00000 1.9600000000 1.000000000
1.40000 2.80000 0.00000 1.9600000000 1.000000000

-- !select_calc6 --
\N \N \N \N \N \N \N \N \N \N
1.20000 1.30000 2.50000 -0.10000 1.5600000000 0.972289742 2.50000 0.10000 1.5600000000 1.083333333
1.20000 1.30000 2.50000 -0.10000 1.5600000000 0.972447325 2.50000 0.10000 1.5600000000 1.083333333
1.20000 1.34400 2.54400 -0.14400 1.6128000000 0.906125407 2.54400 0.14400 1.6128000000 1.120000000
1.20000 1.45600 2.65600 -0.25600 1.7472000000 0.891901534 2.65600 0.25600 1.7472000000 1.213333333
1.20000 1.56000 2.76000 -0.36000 1.8720000000 0.972447325 2.76000 0.36000 1.8720000000 1.300000000
1.20000 1.66000 2.86000 -0.46000 1.9920000000 0.781937249 2.86000 0.46000 1.9920000000 1.383333333
1.40000 1.21000 2.61000 0.19000 1.6940000000 1.246660730 2.61000 -0.19000 1.6940000000 0.864285714
1.40000 1.50000 2.90000 -0.10000 2.1000000000 0.875000000 2.90000 0.10000 2.1000000000 1.071428571

-- !select_calc7 --
\N \N \N \N \N \N \N \N \N \N
1.20000 1.23400 2.43400 -0.03400 1.4808000000 0.972447325 2.43400 0.03400 1.4808000000 1.028333333
1.20000 1.23400 2.43400 -0.03400 1.4808000000 0.972447325 2.43400 0.03400 1.4808000000 1.028333333
1.20000 1.23420 2.43420 -0.03420 1.4810400000 0.972289742 2.43420 0.03420 1.4810400000 1.028500000
1.20000 1.32432 2.52432 -0.12432 1.5891840000 0.906125407 2.52432 0.12432 1.5891840000 1.103600000
1.20000 1.34544 2.54544 -0.14544 1.6145280000 0.891901534 2.54544 0.14544 1.6145280000 1.121200000
1.20000 1.53465 2.73465 -0.33465 1.8415800000 0.781937249 2.73465 0.33465 1.8415800000 1.278875000
1.40000 1.12300 2.52300 0.27700 1.5722000000 1.246660730 2.52300 -0.27700 1.5722000000 0.802142857
1.40000 1.60000 3.00000 -0.20000 2.2400000000 0.875000000 3.00000 0.20000 2.2400000000 1.142857142

-- !select_calc8 --
\N \N \N \N \N
1.21000 2.42000 0.00000 1.4641000000 1.000000000
1.30000 2.60000 0.00000 1.6900000000 1.000000000
1.30000 2.60000 0.00000 1.6900000000 1.000000000
1.34400 2.68800 0.00000 1.8063360000 1.000000000
1.45600 2.91200 0.00000 2.1199360000 1.000000000
1.50000 3.00000 0.00000 2.2500000000 1.000000000
1.56000 3.12000 0.00000 2.4336000000 1.000000000
1.66000 3.32000 0.00000 2.7556000000 1.000000000

-- !select_calc9 --
\N \N \N \N \N \N \N \N \N \N
1.21000 1.12300 2.33300 0.08700 1.3588300000 1.077471059 2.33300 -0.08700 1.3588300000 0.928099173
1.30000 1.23400 2.53400 0.06600 1.6042000000 1.053484602 2.53400 -0.06600 1.6042000000 0.949230769
1.30000 1.23420 2.53420 0.06580 1.6044600000 1.053313887 2.53420 -0.06580 1.6044600000 0.949384615
1.34400 1.32432 2.66832 0.01968 1.7798860800 1.014860456 2.66832 -0.01968 1.7798860800 0.985357142
1.45600 1.34544 2.80144 0.11056 1.9589606400 1.082173861 2.80144 -0.11056 1.9589606400 0.924065934
1.50000 1.60000 3.10000 -0.10000 2.4000000000 0.937500000 3.10000 0.10000 2.4000000000 1.066666666
1.56000 1.23400 2.79400 0.32600 1.9250400000 1.264181523 2.79400 -0.32600 1.9250400000 0.791025641
1.66000 1.53465 3.19465 0.12535 2.5475190000 1.081679861 3.19465 -0.12535 2.5475190000 0.924487951

-- !select_calc10 --
\N \N \N \N \N
1.12300 2.24600 0.00000 1.2611290000 1.000000000
1.23400 2.46800 0.00000 1.5227560000 1.000000000
1.23400 2.46800 0.00000 1.5227560000 1.000000000
1.23420 2.46840 0.00000 1.5232496400 1.000000000
1.32432 2.64864 0.00000 1.7538234624 1.000000000
1.34544 2.69088 0.00000 1.8102087936 1.000000000
1.53465 3.06930 0.00000 2.3551506225 1.000000000
1.60000 3.20000 0.00000 2.5600000000 1.000000000

-- !calc_overflow --
\N \N \N \N
1.21000 1.12300 1209.9999879000 1.122999887700
1.30000 1.23400 1299.9999870000 1.233999876600
1.30000 1.23420 1299.9999870000 1.234199876580
1.34400 1.32432 1343.9999865600 1.324319867568
1.45600 1.34544 1455.9999854400 1.345439865456
1.50000 1.60000 1499.9999850000 1.599999840000
1.56000 1.23400 1559.9999844000 1.233999876600
1.66000 1.53465 1659.9999834000 1.534649846535

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql1 --
9223372036854775807.999999999

-- !decimalv2_calc_overflow --
123456789000.123456 12345678.12345678 1524157779151043787.117829481
999999999999.999999 99999999.99999999 7766279631452231820.000000001

-- !union1 --
9.900000000
9999999.999999999
99999999999999999.999999999

-- !union2 --
9.900000000
9999999.999999999
99999999999999999.999999999

-- !intersect1 --
9.900000000

-- !intersect2 --
9.900000000

-- !except1 --
99999999999999999.999999999

-- !except2 --
9999999.999999999

Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,25 @@
1.1 1.111120000000000000000000000000000000 2.21
123456789012345678901234567890123456.7 1.234567890123456789012345678901234567 123456789012345678901234567890123457.93

-- !union1 --
9.9
10.0
999999999999999999.9

-- !union2 --
9.9
10.0
999999999999999999.9

-- !intersect1 --
9.9

-- !intersect2 --
9.9

-- !except1 --
10.0

-- !except2 --
999999999999999999.9

Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

suite("test_decimalv2_calc_with_conversion", "nonConcurrent") {

sql """
admin set frontend config("enable_decimal_conversion" = "true");
"""
sql "set check_overflow_for_decimal=false;"

def table1 = "test_decimalv2_calc_tbl"

sql "drop table if exists ${table1}"

sql """
CREATE TABLE IF NOT EXISTS `${table1}` (
`decimal_key1` decimalv2(8, 5) NULL COMMENT "",
`decimal_key2` decimalv2(16, 5) NULL COMMENT "",
`decimal_value1` decimalv2(8, 5) NULL COMMENT "",
`decimal_value2` decimalv2(16, 5) NULL COMMENT "",
) ENGINE=OLAP
DUPLICATE KEY(`decimal_key1`, `decimal_key2`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`decimal_key1`, `decimal_key2`) BUCKETS 4
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"in_memory" = "false",
"storage_format" = "V2"
)
"""

sql """insert into ${table1} values
(1.1, 1.4, 1.5, 1.6),
(1.1, 1.2, 1.56, 1.234),
(1.2, 1.2, 1.66, 1.534654),
(1.2, 1.2, 1.344, 1.32432),
(1.3, 1.2, 1.456, 1.345435),
(2.1, 1.2, 1.3, 1.234),
(2.1, 1.2, 1.3, 1.2342),
(2.2, 1.4, 1.21, 1.123),
(NULL, NULL, NULL, NULL)
"""
qt_select_all "select * from ${table1} order by 1, 2, 3, 4"

qt_select_calc1 """
select
decimal_key1, decimal_key1
, decimal_key1 + decimal_key1 v1
, decimal_key1 - decimal_key1 v2
, decimal_key1 * decimal_key1 v3
, decimal_key1 / decimal_key1 v4
from ${table1} order by 1, 2, 3, 4, 5;
"""

qt_select_calc2 """
select
decimal_key1
, decimal_key2
, decimal_key1 + decimal_key2 v1
, decimal_key1 - decimal_key2 v2
, decimal_key1 * decimal_key2 v3
, decimal_key1 / decimal_key2 v4
, decimal_key2 + decimal_key1 v5
, decimal_key2 - decimal_key1 v6
, decimal_key2 * decimal_key1 v7
, decimal_key2 / decimal_key1 v8
from ${table1} order by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
"""

qt_select_calc3 """
select
decimal_key1
, decimal_value1
, decimal_key1 + decimal_value1 v1
, decimal_key1 - decimal_value1 v2
, decimal_key1 * decimal_value1 v3
, decimal_key1 / decimal_value1 v4
, decimal_value1 + decimal_key1 v5
, decimal_value1 - decimal_key1 v6
, decimal_value1 * decimal_key1 v7
, decimal_value1 / decimal_key1 v8
from ${table1} order by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
"""

qt_select_calc4 """
select
decimal_key1
, decimal_value2
, decimal_key1 + decimal_value2 v1
, decimal_key1 - decimal_value2 v2
, decimal_key1 * decimal_value2 v3
, decimal_key1 / decimal_value2 v4
, decimal_value2 + decimal_key1 v5
, decimal_value2 - decimal_key1 v6
, decimal_value2 * decimal_key1 v7
, decimal_value2 / decimal_key1 v8
from ${table1} order by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
"""

qt_select_calc5 """
select
decimal_key2
, decimal_key2 + decimal_key2 v1
, decimal_key2 - decimal_key2 v2
, decimal_key2 * decimal_key2 v3
, decimal_key2 / decimal_key2 v4
from ${table1} order by 1, 2, 3, 4, 5;
"""

qt_select_calc6 """
select
decimal_key2
, decimal_value1
, decimal_key2 + decimal_value1 v1
, decimal_key2 - decimal_value1 v2
, decimal_key2 * decimal_value1 v3
, decimal_key2 / decimal_value2 v4
, decimal_value1 + decimal_key2 v5
, decimal_value1 - decimal_key2 v6
, decimal_value1 * decimal_key2 v7
, decimal_value1 / decimal_key2 v8
from ${table1} order by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
"""

qt_select_calc7 """
select
decimal_key2
, decimal_value2
, decimal_key2 + decimal_value2 v1
, decimal_key2 - decimal_value2 v2
, decimal_key2 * decimal_value2 v3
, decimal_key2 / decimal_value2 v4
, decimal_value2 + decimal_key2 v5
, decimal_value2 - decimal_key2 v6
, decimal_value2 * decimal_key2 v7
, decimal_value2 / decimal_key2 v8
from ${table1} order by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
"""

qt_select_calc8 """
select
decimal_value1
, decimal_value1 + decimal_value1 v1
, decimal_value1 - decimal_value1 v2
, decimal_value1 * decimal_value1 v3
, decimal_value1 / decimal_value1 v4
from ${table1} order by 1, 2, 3, 4, 5;
"""

qt_select_calc9 """
select
decimal_value1
, decimal_value2
, decimal_value1 + decimal_value2 v1
, decimal_value1 - decimal_value2 v2
, decimal_value1 * decimal_value2 v3
, decimal_value1 / decimal_value2 v4
, decimal_value2 + decimal_value1 v5
, decimal_value2 - decimal_value1 v6
, decimal_value2 * decimal_value1 v7
, decimal_value2 / decimal_value1 v8
from ${table1} order by 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
"""

qt_select_calc10 """
select
decimal_value2
, decimal_value2 + decimal_value2 v1
, decimal_value2 - decimal_value2 v2
, decimal_value2 * decimal_value2 v3
, decimal_value2 / decimal_value2 v4
from ${table1} order by 1, 2, 3, 4, 5;
"""

qt_calc_overflow """
select
decimal_value1
, decimal_value2
, decimal_value1 * 999.99999 v1
, decimal_value2 * 0.9999999 v1
from ${table1} order by 1, 2, 3, 4;
"""
}
Loading

0 comments on commit ffc3e17

Please sign in to comment.