diff --git a/datafusion/sqllogictest/src/engines/conversion.rs b/datafusion/sqllogictest/src/engines/conversion.rs index 4447ea9f03bea..bb6b6c7815389 100644 --- a/datafusion/sqllogictest/src/engines/conversion.rs +++ b/datafusion/sqllogictest/src/engines/conversion.rs @@ -50,7 +50,11 @@ pub(crate) fn f16_to_str(value: f16) -> String { } else if value == f16::NEG_INFINITY { "-Infinity".to_string() } else { - big_decimal_to_str(BigDecimal::from_str(&value.to_string()).unwrap(), None) + big_decimal_to_str( + BigDecimal::from_str(&value.to_string()).unwrap(), + None, + true, + ) } } @@ -64,7 +68,11 @@ pub(crate) fn f32_to_str(value: f32) -> String { } else if value == f32::NEG_INFINITY { "-Infinity".to_string() } else { - big_decimal_to_str(BigDecimal::from_str(&value.to_string()).unwrap(), None) + big_decimal_to_str( + BigDecimal::from_str(&value.to_string()).unwrap(), + None, + true, + ) } } @@ -78,7 +86,11 @@ pub(crate) fn f64_to_str(value: f64) -> String { } else if value == f64::NEG_INFINITY { "-Infinity".to_string() } else { - big_decimal_to_str(BigDecimal::from_str(&value.to_string()).unwrap(), None) + big_decimal_to_str( + BigDecimal::from_str(&value.to_string()).unwrap(), + None, + true, + ) } } @@ -92,7 +104,11 @@ pub(crate) fn spark_f64_to_str(value: f64) -> String { } else if value == f64::NEG_INFINITY { "-Infinity".to_string() } else { - big_decimal_to_str(BigDecimal::from_str(&value.to_string()).unwrap(), Some(15)) + big_decimal_to_str( + BigDecimal::from_str(&value.to_string()).unwrap(), + Some(15), + true, + ) } } @@ -105,23 +121,35 @@ pub(crate) fn arrow_decimal_to_str( big_decimal_to_str( BigDecimal::from_str(&value).unwrap(), Some(i64::from(scale)), + false, ) } #[cfg(feature = "postgres")] pub(crate) fn decimal_to_str(value: BigDecimal) -> String { - big_decimal_to_str(value, None) + big_decimal_to_str(value, None, false) } /// Converts a `BigDecimal` to its plain string representation, optionally rounding to a specified number of decimal places. /// /// If `round_digits` is `None`, the value is rounded to 12 decimal places by default. +/// +/// If `normalize` is true, trailing 0s are trimmed. #[expect(clippy::needless_pass_by_value)] -pub(crate) fn big_decimal_to_str(value: BigDecimal, round_digits: Option) -> String { +pub(crate) fn big_decimal_to_str( + value: BigDecimal, + round_digits: Option, + normalize: bool, +) -> String { // Round the value to limit the number of decimal places - let value = value.round(round_digits.unwrap_or(12)).normalized(); + let value = value.round(round_digits.unwrap_or(12)); + // Format the value to a string - value.to_plain_string() + if normalize { + value.normalized().to_plain_string() + } else { + value.to_plain_string() + } } #[cfg(test)] @@ -137,7 +165,8 @@ mod tests { assert_eq!( big_decimal_to_str( BigDecimal::from_bigint(BigInt::from($integer), $scale), - $round_digits + $round_digits, + true ), $expected ); diff --git a/datafusion/sqllogictest/test_files/aggregate.slt b/datafusion/sqllogictest/test_files/aggregate.slt index 365505e2da9e2..3e1a8af0c2494 100644 --- a/datafusion/sqllogictest/test_files/aggregate.slt +++ b/datafusion/sqllogictest/test_files/aggregate.slt @@ -3586,7 +3586,7 @@ create table t (c1 decimal(10, 0)) as values (1), (2), (3), (4), (5), (6); query RT select avg(c1), arrow_typeof(avg(c1)) from t; ---- -3.5 Decimal128(14, 4) +3.5000 Decimal128(14, 4) statement ok drop table t; @@ -3598,7 +3598,7 @@ create table t (c1 decimal(10, 0)) as values (1), (NULL), (3), (4), (5); query RT select avg(c1), arrow_typeof(avg(c1)) from t; ---- -3.25 Decimal128(14, 4) +3.2500 Decimal128(14, 4) statement ok drop table t; @@ -5278,7 +5278,7 @@ INSERT INTO decimals VALUES (123.0001), (124.00); query RR SELECT MIN(value), MAX(value) FROM decimals; ---- -123 124 +123.00 124.00 statement ok DROP TABLE decimals; @@ -5347,7 +5347,7 @@ INSERT INTO decimals_error VALUES (123.00), (arrow_cast(124.001, 'Decimal128(10, query RR SELECT MIN(value), MAX(value) FROM decimals_error; ---- -123 124 +123.00 124.00 statement ok DROP TABLE decimals_error; @@ -6497,7 +6497,7 @@ NULL query RT select sum(c1), arrow_typeof(sum(c1)) from d_table; ---- -100 Decimal128(20, 3) +100.000 Decimal128(20, 3) # aggregate sum with decimal statement ok @@ -6506,7 +6506,7 @@ create table t (c decimal(35, 3)) as values (10), (null), (20); query RT select sum(c), arrow_typeof(sum(c)) from t; ---- -30 Decimal128(38, 3) +30.000 Decimal128(38, 3) statement ok drop table t; @@ -6585,13 +6585,13 @@ B -1000.045 Decimal128(20, 3) query RT select avg(c1), arrow_typeof(avg(c1)) from d_table ---- -5 Decimal128(14, 7) +5.0000000 Decimal128(14, 7) query TRT select c2, avg(c1), arrow_typeof(avg(c1)) from d_table GROUP BY c2 ORDER BY c2 ---- -A 110.0045 Decimal128(14, 7) -B -100.0045 Decimal128(14, 7) +A 110.0045000 Decimal128(14, 7) +B -100.0045000 Decimal128(14, 7) # aggregate_decimal_count_distinct query I @@ -6763,18 +6763,18 @@ INSERT INTO test_decimal_table VALUES (1, 10.10, 100.1, NULL), (1, 20.20, 200.2, query IIRRRRIIRR rowsort select c1, count(c2), avg(c2), sum(c2), min(c2), max(c2), count(c3), count(c4), sum(c4), avg(c4) from test_decimal_table group by c1 ---- -1 2 15.15 30.3 10.1 20.2 2 0 NULL NULL -2 2 15.15 30.3 10.1 20.2 2 0 NULL NULL -3 2 10.1 20.2 10.1 10.1 1 0 NULL NULL +1 2 15.150000 30.30 10.10 20.20 2 0 NULL NULL +2 2 15.150000 30.30 10.10 20.20 2 0 NULL NULL +3 2 10.100000 20.20 10.10 10.10 1 0 NULL NULL # aggregate_decimal_with_group_by_decimal query RIRRRRIR rowsort select c3, count(c2), avg(c2), sum(c2), min(c2), max(c2), count(c4), sum(c4) from test_decimal_table group by c3 ---- -100.1 2 10.1 20.2 10.1 10.1 0 NULL -200.2 1 20.2 20.2 20.2 20.2 0 NULL -700.1 2 15.15 30.3 10.1 20.2 0 NULL -NULL 1 10.1 10.1 10.1 10.1 0 NULL +100.1 2 10.100000 20.20 10.10 10.10 0 NULL +200.2 1 20.200000 20.20 20.20 20.20 0 NULL +700.1 2 15.150000 30.30 10.10 20.20 0 NULL +NULL 1 10.100000 10.10 10.10 10.10 0 NULL ## Multiple distinct aggregates and dictionaries statement ok @@ -8941,7 +8941,7 @@ create table t_decimal (c decimal(10, 4)) as values (100.00), (125.00), (175.00) query RT select avg(distinct c), arrow_typeof(avg(distinct c)) from t_decimal; ---- -180 Decimal128(14, 8) +180.00000000 Decimal128(14, 8) statement ok drop table t_decimal; @@ -8961,7 +8961,7 @@ create table t_decimal256 (c decimal(50, 2)) as values query RT select avg(distinct c), arrow_typeof(avg(distinct c)) from t_decimal256; ---- -180 Decimal256(54, 6) +180.000000 Decimal256(54, 6) statement ok drop table t_decimal256; @@ -9118,7 +9118,7 @@ select avg(d) from distinct_avg; ---- -3 Float64 37.4255 Float64 698.56005 Decimal128(14, 8) 15041.868333 Decimal256(54, 6) 4 56.52525 957.11074444 1272562.81625 +3 Float64 37.4255 Float64 698.56005000 Decimal128(14, 8) 15041.868333 Decimal256(54, 6) 4 56.52525 957.11074444 1272562.816250 query RRRR rowsort select @@ -9129,11 +9129,11 @@ select from distinct_avg group by b; ---- -1 4.09 4222.124 0 -3 NULL 2161.1901 90251.21 -5 1 100.25625 45125.105 -5 100.5 -49.5781 0.333333 -5 44.112 -132.12 NULL +1 4.09 4222.12400000 0.000000 +3 NULL 2161.19010000 90251.210000 +5 1 100.25625000 45125.105000 +5 100.5 -49.57810000 0.333333 +5 44.112 -132.12000000 NULL query RRRR select diff --git a/datafusion/sqllogictest/test_files/aggregate_skip_partial.slt b/datafusion/sqllogictest/test_files/aggregate_skip_partial.slt index 2ed4c9921f3a7..30c5ce454197d 100644 --- a/datafusion/sqllogictest/test_files/aggregate_skip_partial.slt +++ b/datafusion/sqllogictest/test_files/aggregate_skip_partial.slt @@ -742,9 +742,9 @@ FROM decimal_table CROSS JOIN t GROUP BY i ORDER BY i; ---- -1 66 -2 66 -3 33 +1 66.000 +2 66.000 +3 33.000 # Config reset statement ok diff --git a/datafusion/sqllogictest/test_files/array/array_min_max.slt b/datafusion/sqllogictest/test_files/array/array_min_max.slt index 2e9c1035b765d..108045ef4a008 100644 --- a/datafusion/sqllogictest/test_files/array/array_min_max.slt +++ b/datafusion/sqllogictest/test_files/array/array_min_max.slt @@ -310,7 +310,7 @@ from ( ) as dec_list ) t; ---- -100 300 Decimal128(20, 4) Decimal128(20, 4) +100.0000 300.0000 Decimal128(20, 4) Decimal128(20, 4) diff --git a/datafusion/sqllogictest/test_files/array/init_data.slt.part b/datafusion/sqllogictest/test_files/array/init_data.slt.part index bb8d76809f816..06d029303022b 100644 --- a/datafusion/sqllogictest/test_files/array/init_data.slt.part +++ b/datafusion/sqllogictest/test_files/array/init_data.slt.part @@ -688,4 +688,3 @@ AS arrow_cast(column4, 'FixedSizeList(3, Float64)') AS column4 FROM arrays_distance_table ; - diff --git a/datafusion/sqllogictest/test_files/array_add.slt b/datafusion/sqllogictest/test_files/array_add.slt index e13f6acd269cb..acef9984fdbcc 100644 --- a/datafusion/sqllogictest/test_files/array_add.slt +++ b/datafusion/sqllogictest/test_files/array_add.slt @@ -234,4 +234,4 @@ select array_add(array_add(a, b), c) from (values ---- [111.0, 222.0] NULL -[111.0, NULL] \ No newline at end of file +[111.0, NULL] diff --git a/datafusion/sqllogictest/test_files/array_product.slt b/datafusion/sqllogictest/test_files/array_product.slt index ba60360d1c1a9..a904282358dff 100644 --- a/datafusion/sqllogictest/test_files/array_product.slt +++ b/datafusion/sqllogictest/test_files/array_product.slt @@ -142,4 +142,4 @@ select list_product(column1) from (values ) as t(column1); ---- 6 -NULL \ No newline at end of file +NULL diff --git a/datafusion/sqllogictest/test_files/array_subtract.slt b/datafusion/sqllogictest/test_files/array_subtract.slt index 4a680c93aae95..28edd6ba9b0ed 100644 --- a/datafusion/sqllogictest/test_files/array_subtract.slt +++ b/datafusion/sqllogictest/test_files/array_subtract.slt @@ -234,4 +234,4 @@ select array_subtract(array_subtract(a, b), c) from (values ---- [89.0, 178.0] NULL -[89.0, NULL] \ No newline at end of file +[89.0, NULL] diff --git a/datafusion/sqllogictest/test_files/arrow_typeof.slt b/datafusion/sqllogictest/test_files/arrow_typeof.slt index 17fcb7fa36ed7..02f1911898f3a 100644 --- a/datafusion/sqllogictest/test_files/arrow_typeof.slt +++ b/datafusion/sqllogictest/test_files/arrow_typeof.slt @@ -204,7 +204,7 @@ SELECT col_d256 FROM foo; ---- -100 100 +100.00 100.00 statement ok drop table foo diff --git a/datafusion/sqllogictest/test_files/binary.slt b/datafusion/sqllogictest/test_files/binary.slt index 94c1365cb9514..0905dca4efe15 100644 --- a/datafusion/sqllogictest/test_files/binary.slt +++ b/datafusion/sqllogictest/test_files/binary.slt @@ -363,4 +363,4 @@ hellohello query T SELECT 'hello' || arrow_cast(arrow_cast('hello', 'Binary'), 'BinaryView'); ---- -hellohello \ No newline at end of file +hellohello diff --git a/datafusion/sqllogictest/test_files/coalesce.slt b/datafusion/sqllogictest/test_files/coalesce.slt index 79a29f7bf8ec0..c6170e0611852 100644 --- a/datafusion/sqllogictest/test_files/coalesce.slt +++ b/datafusion/sqllogictest/test_files/coalesce.slt @@ -167,14 +167,14 @@ select coalesce(arrow_cast(2, 'Decimal128(7, 2)'), 0), arrow_typeof(coalesce(arrow_cast(2, 'Decimal128(7, 2)'), 0)) ---- -2 Decimal128(22, 2) +2.00 Decimal128(22, 2) query RT select coalesce(arrow_cast(2, 'Decimal256(7, 2)'), 0), arrow_typeof(coalesce(arrow_cast(2, 'Decimal256(7, 2)'), 0)); ---- -2 Decimal256(22, 2) +2.00 Decimal256(22, 2) # coalesce string query TT diff --git a/datafusion/sqllogictest/test_files/decimal.slt b/datafusion/sqllogictest/test_files/decimal.slt index 4335ec06685f2..a1f38cf4f987b 100644 --- a/datafusion/sqllogictest/test_files/decimal.slt +++ b/datafusion/sqllogictest/test_files/decimal.slt @@ -19,14 +19,14 @@ query TR select arrow_typeof(cast(1.23 as decimal(10,4))), cast(1.23 as decimal(10,4)); ---- -Decimal128(10, 4) 1.23 +Decimal128(10, 4) 1.2300 query TR select arrow_typeof(cast(cast(1.23 as decimal(10,3)) as decimal(10,4))), cast(cast(1.23 as decimal(10,3)) as decimal(10,4)); ---- -Decimal128(10, 4) 1.23 +Decimal128(10, 4) 1.2300 query TR @@ -57,55 +57,55 @@ Decimal128(10, 6) Decimal128(12, 7) query R rowsort SELECT c1 from decimal_simple; ---- -0.00001 -0.00002 -0.00002 -0.00003 -0.00003 -0.00003 -0.00004 -0.00004 -0.00004 -0.00004 -0.00005 -0.00005 -0.00005 -0.00005 -0.00005 +0.000010 +0.000020 +0.000020 +0.000030 +0.000030 +0.000030 +0.000040 +0.000040 +0.000040 +0.000040 +0.000050 +0.000050 +0.000050 +0.000050 +0.000050 query R rowsort select c1 from decimal_simple where c1 > 0.000030; ---- -0.00004 -0.00004 -0.00004 -0.00004 -0.00005 -0.00005 -0.00005 -0.00005 -0.00005 +0.000040 +0.000040 +0.000040 +0.000040 +0.000050 +0.000050 +0.000050 +0.000050 +0.000050 query RRIBR rowsort select * from decimal_simple where c1 > c5; ---- -0.00002 0.000000000002 3 false 0.000019 -0.00003 0.000000000003 5 true 0.000011 -0.00005 0.000000000005 8 false 0.000033 +0.000020 0.000000000002 3 false 0.0000190 +0.000030 0.000000000003 5 true 0.0000110 +0.000050 0.000000000005 8 false 0.0000330 query TR select arrow_typeof(min(c1)), min(c1) from decimal_simple where c4=false; ---- -Decimal128(10, 6) 0.00002 +Decimal128(10, 6) 0.000020 query TR select arrow_typeof(max(c1)), max(c1) from decimal_simple where c4=false; ---- -Decimal128(10, 6) 0.00005 +Decimal128(10, 6) 0.000050 # inferred precision is 10+10 @@ -113,7 +113,7 @@ Decimal128(10, 6) 0.00005 query TR select arrow_typeof(sum(c1)), sum(c1) from decimal_simple; ---- -Decimal128(20, 6) 0.00055 +Decimal128(20, 6) 0.000550 # inferred precision is original precision + 4 @@ -127,14 +127,14 @@ Decimal128(14, 10) 0.0000366666 query TR select arrow_typeof(median(c1)), median(c1) from decimal_simple; ---- -Decimal128(10, 6) 0.00004 +Decimal128(10, 6) 0.000040 query RRIBR rowsort select * from decimal_simple where c1=CAST(0.00002 as Decimal(10,8)); ---- -0.00002 0.000000000002 2 true 0.000025 -0.00002 0.000000000002 3 false 0.000019 +0.000020 0.000000000002 2 true 0.0000250 +0.000020 0.000000000002 3 false 0.0000190 query RI rowsort @@ -158,51 +158,51 @@ select c2,c3 from decimal_simple where c1!=0.00002; query RRIBR select * from decimal_simple where 0.00002 > c1; ---- -0.00001 0.000000000001 1 true 0.000014 +0.000010 0.000000000001 1 true 0.0000140 query RRIBR rowsort select * from decimal_simple where c1 <= 0.00002; ---- -0.00001 0.000000000001 1 true 0.000014 -0.00002 0.000000000002 2 true 0.000025 -0.00002 0.000000000002 3 false 0.000019 +0.000010 0.000000000001 1 true 0.0000140 +0.000020 0.000000000002 2 true 0.0000250 +0.000020 0.000000000002 3 false 0.0000190 query RRIBR rowsort select * from decimal_simple where c1 > 0.00002; ---- -0.00003 0.000000000003 4 true 0.000032 -0.00003 0.000000000003 5 false 0.000035 -0.00003 0.000000000003 5 true 0.000011 -0.00004 0.000000000004 12 false 0.00004 -0.00004 0.000000000004 14 true 0.00004 -0.00004 0.000000000004 5 true 0.000044 -0.00004 0.000000000004 8 false 0.000044 -0.00005 0.000000000005 1 false 0.0001 -0.00005 0.000000000005 100 true 0.000068 -0.00005 0.000000000005 4 true 0.000078 -0.00005 0.000000000005 8 false 0.000033 -0.00005 0.000000000005 9 true 0.000052 +0.000030 0.000000000003 4 true 0.0000320 +0.000030 0.000000000003 5 false 0.0000350 +0.000030 0.000000000003 5 true 0.0000110 +0.000040 0.000000000004 12 false 0.0000400 +0.000040 0.000000000004 14 true 0.0000400 +0.000040 0.000000000004 5 true 0.0000440 +0.000040 0.000000000004 8 false 0.0000440 +0.000050 0.000000000005 1 false 0.0001000 +0.000050 0.000000000005 100 true 0.0000680 +0.000050 0.000000000005 4 true 0.0000780 +0.000050 0.000000000005 8 false 0.0000330 +0.000050 0.000000000005 9 true 0.0000520 query RRIBR rowsort select * from decimal_simple where c1 >= 0.00002; ---- -0.00002 0.000000000002 2 true 0.000025 -0.00002 0.000000000002 3 false 0.000019 -0.00003 0.000000000003 4 true 0.000032 -0.00003 0.000000000003 5 false 0.000035 -0.00003 0.000000000003 5 true 0.000011 -0.00004 0.000000000004 12 false 0.00004 -0.00004 0.000000000004 14 true 0.00004 -0.00004 0.000000000004 5 true 0.000044 -0.00004 0.000000000004 8 false 0.000044 -0.00005 0.000000000005 1 false 0.0001 -0.00005 0.000000000005 100 true 0.000068 -0.00005 0.000000000005 4 true 0.000078 -0.00005 0.000000000005 8 false 0.000033 -0.00005 0.000000000005 9 true 0.000052 +0.000020 0.000000000002 2 true 0.0000250 +0.000020 0.000000000002 3 false 0.0000190 +0.000030 0.000000000003 4 true 0.0000320 +0.000030 0.000000000003 5 false 0.0000350 +0.000030 0.000000000003 5 true 0.0000110 +0.000040 0.000000000004 12 false 0.0000400 +0.000040 0.000000000004 14 true 0.0000400 +0.000040 0.000000000004 5 true 0.0000440 +0.000040 0.000000000004 8 false 0.0000440 +0.000050 0.000000000005 1 false 0.0001000 +0.000050 0.000000000005 100 true 0.0000680 +0.000050 0.000000000005 4 true 0.0000780 +0.000050 0.000000000005 8 false 0.0000330 +0.000050 0.000000000005 9 true 0.0000520 query T @@ -214,21 +214,21 @@ Decimal128(27, 6) query R rowsort select c1+1 from decimal_simple; ---- -1.00001 -1.00002 -1.00002 -1.00003 -1.00003 -1.00003 -1.00004 -1.00004 -1.00004 -1.00004 -1.00005 -1.00005 -1.00005 -1.00005 -1.00005 +1.000010 +1.000020 +1.000020 +1.000030 +1.000030 +1.000030 +1.000040 +1.000040 +1.000040 +1.000040 +1.000050 +1.000050 +1.000050 +1.000050 +1.000050 # array decimal(10,6) + array decimal(12,7) => decimal(13,7) @@ -241,21 +241,21 @@ Decimal128(13, 7) query R rowsort select c1+c5 from decimal_simple; ---- -0.000024 -0.000039 -0.000041 -0.000045 -0.000062 -0.000065 -0.00008 -0.00008 -0.000083 -0.000084 -0.000084 -0.000102 -0.000118 -0.000128 -0.00015 +0.0000240 +0.0000390 +0.0000410 +0.0000450 +0.0000620 +0.0000650 +0.0000800 +0.0000800 +0.0000830 +0.0000840 +0.0000840 +0.0001020 +0.0001180 +0.0001280 +0.0001500 query T @@ -267,21 +267,21 @@ Decimal128(27, 6) query R rowsort select c1-1 from decimal_simple; ---- --0.99995 --0.99995 --0.99995 --0.99995 --0.99995 --0.99996 --0.99996 --0.99996 --0.99996 --0.99997 --0.99997 --0.99997 --0.99998 --0.99998 --0.99999 +-0.999950 +-0.999950 +-0.999950 +-0.999950 +-0.999950 +-0.999960 +-0.999960 +-0.999960 +-0.999960 +-0.999970 +-0.999970 +-0.999970 +-0.999980 +-0.999980 +-0.999990 query T @@ -293,21 +293,21 @@ Decimal128(13, 7) query R rowsort select c1-c5 from decimal_simple; ---- --0.000002 --0.000002 --0.000004 --0.000004 --0.000004 --0.000005 --0.000005 --0.000018 --0.000028 --0.00005 -0 -0 -0.000001 -0.000017 -0.000019 +-0.0000020 +-0.0000020 +-0.0000040 +-0.0000040 +-0.0000040 +-0.0000050 +-0.0000050 +-0.0000180 +-0.0000280 +-0.0000500 +0.0000000 +0.0000000 +0.0000010 +0.0000170 +0.0000190 query T @@ -319,21 +319,21 @@ Decimal128(31, 6) query R rowsort select c1*20 from decimal_simple; ---- -0.0002 -0.0004 -0.0004 -0.0006 -0.0006 -0.0006 -0.0008 -0.0008 -0.0008 -0.0008 -0.001 -0.001 -0.001 -0.001 -0.001 +0.000200 +0.000400 +0.000400 +0.000600 +0.000600 +0.000600 +0.000800 +0.000800 +0.000800 +0.000800 +0.001000 +0.001000 +0.001000 +0.001000 +0.001000 query T @@ -345,21 +345,21 @@ Decimal128(23, 13) query R rowsort select c1*c5 from decimal_simple; ---- -0.00000000014 -0.00000000033 -0.00000000038 -0.0000000005 -0.00000000096 -0.00000000105 -0.0000000016 -0.0000000016 -0.00000000165 -0.00000000176 -0.00000000176 -0.0000000026 -0.0000000034 -0.0000000039 -0.000000005 +0.0000000001400 +0.0000000003300 +0.0000000003800 +0.0000000005000 +0.0000000009600 +0.0000000010500 +0.0000000016000 +0.0000000016000 +0.0000000016500 +0.0000000017600 +0.0000000017600 +0.0000000026000 +0.0000000034000 +0.0000000039000 +0.0000000050000 query T @@ -371,21 +371,21 @@ Decimal128(19, 10) query R rowsort select c1/cast(0.00001 as decimal(5,5)) from decimal_simple; ---- -1 -2 -2 -3 -3 -3 -4 -4 -4 -4 -5 -5 -5 -5 -5 +1.0000000000 +2.0000000000 +2.0000000000 +3.0000000000 +3.0000000000 +3.0000000000 +4.0000000000 +4.0000000000 +4.0000000000 +4.0000000000 +5.0000000000 +5.0000000000 +5.0000000000 +5.0000000000 +5.0000000000 query T @@ -397,18 +397,18 @@ Decimal128(21, 10) query R rowsort select c1/c5 from decimal_simple; ---- -0.5 -0.641025641 +0.5000000000 +0.6410256410 0.7142857142 0.7352941176 -0.8 +0.8000000000 0.8571428571 -0.909090909 -0.909090909 -0.9375 +0.9090909090 +0.9090909090 +0.9375000000 0.9615384615 -1 -1 +1.0000000000 +1.0000000000 1.0526315789 1.5151515151 2.7272727272 @@ -423,21 +423,21 @@ Decimal128(7, 7) query R rowsort select c5%cast(0.00001 as decimal(5,5)) from decimal_simple; ---- -0 -0 -0 -0.000001 -0.000002 -0.000002 -0.000003 -0.000004 -0.000004 -0.000004 -0.000005 -0.000005 -0.000008 -0.000008 -0.000009 +0.0000000 +0.0000000 +0.0000000 +0.0000010 +0.0000020 +0.0000020 +0.0000030 +0.0000040 +0.0000040 +0.0000040 +0.0000050 +0.0000050 +0.0000080 +0.0000080 +0.0000090 query T @@ -449,21 +449,21 @@ Decimal128(11, 7) query R rowsort select c1%c5 from decimal_simple; ---- -0 -0 -0.000001 -0.000008 -0.00001 -0.000017 -0.00002 -0.00003 -0.00003 -0.00004 -0.00004 -0.00005 -0.00005 -0.00005 -0.00005 +0.0000000 +0.0000000 +0.0000010 +0.0000080 +0.0000100 +0.0000170 +0.0000200 +0.0000300 +0.0000300 +0.0000400 +0.0000400 +0.0000500 +0.0000500 +0.0000500 +0.0000500 query T @@ -475,104 +475,104 @@ Decimal128(10, 6) query R rowsort SELECT abs(c1) from decimal_simple; ---- -0.00001 -0.00002 -0.00002 -0.00003 -0.00003 -0.00003 -0.00004 -0.00004 -0.00004 -0.00004 -0.00005 -0.00005 -0.00005 -0.00005 -0.00005 +0.000010 +0.000020 +0.000020 +0.000030 +0.000030 +0.000030 +0.000040 +0.000040 +0.000040 +0.000040 +0.000050 +0.000050 +0.000050 +0.000050 +0.000050 query RRIBR select * from decimal_simple where c1 >= 0.00004 order by c1; ---- -0.00004 0.000000000004 5 true 0.000044 -0.00004 0.000000000004 12 false 0.00004 -0.00004 0.000000000004 14 true 0.00004 -0.00004 0.000000000004 8 false 0.000044 -0.00005 0.000000000005 9 true 0.000052 -0.00005 0.000000000005 4 true 0.000078 -0.00005 0.000000000005 8 false 0.000033 -0.00005 0.000000000005 100 true 0.000068 -0.00005 0.000000000005 1 false 0.0001 +0.000040 0.000000000004 5 true 0.0000440 +0.000040 0.000000000004 12 false 0.0000400 +0.000040 0.000000000004 14 true 0.0000400 +0.000040 0.000000000004 8 false 0.0000440 +0.000050 0.000000000005 9 true 0.0000520 +0.000050 0.000000000005 4 true 0.0000780 +0.000050 0.000000000005 8 false 0.0000330 +0.000050 0.000000000005 100 true 0.0000680 +0.000050 0.000000000005 1 false 0.0001000 query RRIBR select * from decimal_simple where c1 >= 0.00004 order by c1, c3 limit 10; ---- -0.00004 0.000000000004 5 true 0.000044 -0.00004 0.000000000004 8 false 0.000044 -0.00004 0.000000000004 12 false 0.00004 -0.00004 0.000000000004 14 true 0.00004 -0.00005 0.000000000005 1 false 0.0001 -0.00005 0.000000000005 4 true 0.000078 -0.00005 0.000000000005 8 false 0.000033 -0.00005 0.000000000005 9 true 0.000052 -0.00005 0.000000000005 100 true 0.000068 +0.000040 0.000000000004 5 true 0.0000440 +0.000040 0.000000000004 8 false 0.0000440 +0.000040 0.000000000004 12 false 0.0000400 +0.000040 0.000000000004 14 true 0.0000400 +0.000050 0.000000000005 1 false 0.0001000 +0.000050 0.000000000005 4 true 0.0000780 +0.000050 0.000000000005 8 false 0.0000330 +0.000050 0.000000000005 9 true 0.0000520 +0.000050 0.000000000005 100 true 0.0000680 query RRIBR select * from decimal_simple where c1 >= 0.00004 order by c1, c3 limit 5; ---- -0.00004 0.000000000004 5 true 0.000044 -0.00004 0.000000000004 8 false 0.000044 -0.00004 0.000000000004 12 false 0.00004 -0.00004 0.000000000004 14 true 0.00004 -0.00005 0.000000000005 1 false 0.0001 +0.000040 0.000000000004 5 true 0.0000440 +0.000040 0.000000000004 8 false 0.0000440 +0.000040 0.000000000004 12 false 0.0000400 +0.000040 0.000000000004 14 true 0.0000400 +0.000050 0.000000000005 1 false 0.0001000 query RRIBR select * from decimal_simple where c1 >= 0.00004 order by c1 desc; ---- -0.00005 0.000000000005 9 true 0.000052 -0.00005 0.000000000005 4 true 0.000078 -0.00005 0.000000000005 8 false 0.000033 -0.00005 0.000000000005 100 true 0.000068 -0.00005 0.000000000005 1 false 0.0001 -0.00004 0.000000000004 5 true 0.000044 -0.00004 0.000000000004 12 false 0.00004 -0.00004 0.000000000004 14 true 0.00004 -0.00004 0.000000000004 8 false 0.000044 +0.000050 0.000000000005 9 true 0.0000520 +0.000050 0.000000000005 4 true 0.0000780 +0.000050 0.000000000005 8 false 0.0000330 +0.000050 0.000000000005 100 true 0.0000680 +0.000050 0.000000000005 1 false 0.0001000 +0.000040 0.000000000004 5 true 0.0000440 +0.000040 0.000000000004 12 false 0.0000400 +0.000040 0.000000000004 14 true 0.0000400 +0.000040 0.000000000004 8 false 0.0000440 query RRIBR select * from decimal_simple where c1 < 0.00003 order by c1 desc,c4; ---- -0.00002 0.000000000002 3 false 0.000019 -0.00002 0.000000000002 2 true 0.000025 -0.00001 0.000000000001 1 true 0.000014 +0.000020 0.000000000002 3 false 0.0000190 +0.000020 0.000000000002 2 true 0.0000250 +0.000010 0.000000000001 1 true 0.0000140 query IR select count(*),c1 from decimal_simple group by c1 order by c1; ---- -1 0.00001 -2 0.00002 -3 0.00003 -4 0.00004 -5 0.00005 +1 0.000010 +2 0.000020 +3 0.000030 +4 0.000040 +5 0.000050 query IRB select count(*),c1,c4 from decimal_simple group by c1,c4 order by c1,c4; ---- -1 0.00001 true -1 0.00002 false -1 0.00002 true -1 0.00003 false -2 0.00003 true -2 0.00004 false -2 0.00004 true -2 0.00005 false -3 0.00005 true +1 0.000010 true +1 0.000020 false +1 0.000020 true +1 0.000030 false +2 0.000030 true +2 0.000040 false +2 0.000040 true +2 0.000050 false +3 0.000050 true query TR @@ -612,12 +612,12 @@ insert into foo VALUES (1, 5); query R select a / b from foo; ---- -0.2 +0.200000000000000000000000 query R select AVG(column1) from values (arrow_cast(123, 'Decimal256(5,2)')); ---- -123 +123.000000 statement ok CREATE EXTERNAL TABLE decimal256_simple ( @@ -639,41 +639,41 @@ Decimal256(50, 6) Decimal256(52, 7) query R rowsort SELECT c1 from decimal256_simple; ---- -0.00001 -0.00002 -0.00002 -0.00003 -0.00003 -0.00003 -0.00004 -0.00004 -0.00004 -0.00004 -0.00005 -0.00005 -0.00005 -0.00005 -0.00005 +0.000010 +0.000020 +0.000020 +0.000030 +0.000030 +0.000030 +0.000040 +0.000040 +0.000040 +0.000040 +0.000050 +0.000050 +0.000050 +0.000050 +0.000050 query R rowsort select c1 from decimal256_simple where c1 > 0.000030; ---- -0.00004 -0.00004 -0.00004 -0.00004 -0.00005 -0.00005 -0.00005 -0.00005 -0.00005 +0.000040 +0.000040 +0.000040 +0.000040 +0.000050 +0.000050 +0.000050 +0.000050 +0.000050 query RRIBR rowsort select * from decimal256_simple where c1 > c5; ---- -0.00002 0.000000000002 3 false 0.000019 -0.00003 0.000000000003 5 true 0.000011 -0.00005 0.000000000005 8 false 0.000033 +0.000020 0.000000000002 3 false 0.0000190 +0.000030 0.000000000003 5 true 0.0000110 +0.000050 0.000000000005 8 false 0.0000330 query TR select arrow_typeof(avg(c1)), avg(c1) from decimal256_simple; @@ -683,31 +683,31 @@ Decimal256(54, 10) 0.0000366666 query TR select arrow_typeof(min(c1)), min(c1) from decimal256_simple where c4=false; ---- -Decimal256(50, 6) 0.00002 +Decimal256(50, 6) 0.000020 query TR select arrow_typeof(max(c1)), max(c1) from decimal256_simple where c4=false; ---- -Decimal256(50, 6) 0.00005 +Decimal256(50, 6) 0.000050 query TR select arrow_typeof(sum(c1)), sum(c1) from decimal256_simple; ---- -Decimal256(60, 6) 0.00055 +Decimal256(60, 6) 0.000550 query TR select arrow_typeof(median(c1)), median(c1) from decimal256_simple; ---- -Decimal256(50, 6) 0.00004 +Decimal256(50, 6) 0.000040 query IR select count(*),c1 from decimal256_simple group by c1 order by c1; ---- -1 0.00001 -2 0.00002 -3 0.00003 -4 0.00004 -5 0.00005 +1 0.000010 +2 0.000020 +3 0.000030 +4 0.000040 +5 0.000050 query I select count(DISTINCT cast(c1 AS DECIMAL(42, 4))) from decimal256_simple; @@ -735,7 +735,7 @@ SELECT cast(cast('0' as decimal(3,0)) as decimal(2,0)), cast(cast('5.20' as decimal(4,2)) as decimal(3,2)) ---- -0 5.2 +0 5.20 query RR SELECT @@ -763,7 +763,7 @@ SELECT arrow_cast(1.23,'Decimal128(3,2)') / arrow_cast(123, 'UInt64') as divison_uint, arrow_cast(1.23,'Decimal128(3,2)') / arrow_cast(123, 'Int64') as divison_int ---- -0.01 0.01 +0.010000 0.010000 query TR with tt as ( @@ -1198,20 +1198,20 @@ NULL Float64 query RR rowsort SELECT distinct c1*100000, power(c1*100000, 2) from decimal_simple; ---- -1 1 -2 4 -3 9 -4 16 -5 25 +1.000000 1 +2.000000 4 +3.000000 9 +4.000000 16 +5.000000 25 query RR rowsort SELECT distinct c1*100000, power(c1*100000, 2.0) from decimal_simple; ---- -1 1 -2 4 -3 9 -4 16 -5 25 +1.000000 1 +2.000000 4 +3.000000 9 +4.000000 16 +5.000000 25 # Set parse_float_as_decimal to false to test float parsing statement ok @@ -1305,7 +1305,7 @@ from ( from generate_series(1, 21476) ) t; ---- -99999 Decimal32(9, 4) +99999.0000 Decimal32(9, 4) # 92235 * 99999999999999 ~= 9.22e18 > i64::MAX query RT @@ -1315,7 +1315,7 @@ from ( from generate_series(1, 92235) ) t; ---- -99999999999999 Decimal64(18, 4) +99999999999999.0000 Decimal64(18, 4) # 21476 * (10^34 - 1) ~= 2.15e38 > i128::MAX query RT @@ -1325,7 +1325,7 @@ from ( from generate_series(1, 21476) ) t; ---- -9999999999999999999999999999999999 Decimal128(38, 4) +9999999999999999999999999999999999.0000 Decimal128(38, 4) # Regression: `avg(DISTINCT ...)` must widen its intermediate sum the same way. # The second distinct aggregate keeps `single_distinct_to_group_by` from @@ -1339,4 +1339,10 @@ from ( from generate_series(1, 65536) t(v) ) t; ---- -32768.5 Decimal32(9, 4) 32768.5 +32768.5000 Decimal32(9, 4) 32768.5 + +# Make sure to display full scale +query R +select arrow_cast('1.2300', 'Decimal32(9, 4)'); +---- +1.2300 diff --git a/datafusion/sqllogictest/test_files/errors.slt b/datafusion/sqllogictest/test_files/errors.slt index ab934279c32ec..9b69d4b83d7b1 100644 --- a/datafusion/sqllogictest/test_files/errors.slt +++ b/datafusion/sqllogictest/test_files/errors.slt @@ -157,7 +157,7 @@ query error DataFusion error: Error during planning: Substring without for/from select 1 group by substr(''); # Error in filter should be reported -query error Divide by zero +query error DataFusion error: Arrow error: Divide by zero error SELECT c2 from aggregate_test_100 where CASE WHEN true THEN 1 / 0 ELSE 0 END = 1; diff --git a/datafusion/sqllogictest/test_files/group_by.slt b/datafusion/sqllogictest/test_files/group_by.slt index de493d6e4a2b1..e165fe7b6779c 100644 --- a/datafusion/sqllogictest/test_files/group_by.slt +++ b/datafusion/sqllogictest/test_files/group_by.slt @@ -5592,7 +5592,7 @@ select a, b, count(*) from t group by a, b order by a, b; ---- 1 123.45 2 1 NULL 1 -2 678.9 3 +2 678.90 3 2 1011.12 2 3 1314.15 2 NULL 123.45 2 diff --git a/datafusion/sqllogictest/test_files/input_file_name.slt b/datafusion/sqllogictest/test_files/input_file_name.slt index 8fb72d4a9d14b..5e844259a91c8 100644 --- a/datafusion/sqllogictest/test_files/input_file_name.slt +++ b/datafusion/sqllogictest/test_files/input_file_name.slt @@ -125,4 +125,4 @@ physical_plan 05)--------DataSourceExec: file_groups={2 groups: [[WORKSPACE_ROOT/datafusion/sqllogictest/test_files/scratch/input_file_name/parquet/first.parquet], [WORKSPACE_ROOT/datafusion/sqllogictest/test_files/scratch/input_file_name/parquet/second.parquet]]}, projection=[input_file_name() as __datafusion_extracted_1, column1], file_type=parquet, predicate=input_file_name() LIKE %first.parquet statement ok -DROP TABLE pq_table; \ No newline at end of file +DROP TABLE pq_table; diff --git a/datafusion/sqllogictest/test_files/insert.slt b/datafusion/sqllogictest/test_files/insert.slt index c807f73d60fe0..ddb954bcfebc6 100644 --- a/datafusion/sqllogictest/test_files/insert.slt +++ b/datafusion/sqllogictest/test_files/insert.slt @@ -463,7 +463,7 @@ drop table unsigned_bigint_test # Config reset -# The SLT runner sets `target_partitions` to 4 instead of using the default, so +# The SLT runner sets `target_partitions` to 4 instead of using the default, so # reset it explicitly. statement ok set datafusion.execution.target_partitions = 4; diff --git a/datafusion/sqllogictest/test_files/joins.slt b/datafusion/sqllogictest/test_files/joins.slt index 3b8f66def3c34..d4d1648ca3452 100644 --- a/datafusion/sqllogictest/test_files/joins.slt +++ b/datafusion/sqllogictest/test_files/joins.slt @@ -2718,7 +2718,7 @@ query DDRTDDRT rowsort select * from hashjoin_datatype_table_t1 t1 join hashjoin_datatype_table_t2 t2 on t1.c1 = t2.c1 ---- 1970-01-02 1970-01-02T00:00:00 1.23 abc 1970-01-02 1970-01-02T00:00:00 -123.12 abc -1970-01-04 NULL -123.12 jkl 1970-01-04 NULL 789 qwe +1970-01-04 NULL -123.12 jkl 1970-01-04 NULL 789.00 qwe # explain hash_join_with_date64 @@ -2737,9 +2737,9 @@ query DDRTDDRT rowsort select * from hashjoin_datatype_table_t1 t1 left join hashjoin_datatype_table_t2 t2 on t1.c2 = t2.c2 ---- 1970-01-02 1970-01-02T00:00:00 1.23 abc 1970-01-02 1970-01-02T00:00:00 -123.12 abc -1970-01-03 1970-01-03T00:00:00 456 def NULL NULL NULL NULL +1970-01-03 1970-01-03T00:00:00 456.00 def NULL NULL NULL NULL 1970-01-04 NULL -123.12 jkl NULL NULL NULL NULL -NULL 1970-01-04T00:00:00 789 ghi NULL 1970-01-04T00:00:00 0 qwerty +NULL 1970-01-04T00:00:00 789.00 ghi NULL 1970-01-04T00:00:00 0.00 qwerty # explain hash_join_with_decimal @@ -2758,9 +2758,9 @@ query DDRTDDRT rowsort select * from hashjoin_datatype_table_t1 t1 right join hashjoin_datatype_table_t1 t2 on t1.c3 = t2.c3 ---- 1970-01-02 1970-01-02T00:00:00 1.23 abc 1970-01-02 1970-01-02T00:00:00 1.23 abc -1970-01-03 1970-01-03T00:00:00 456 def 1970-01-03 1970-01-03T00:00:00 456 def +1970-01-03 1970-01-03T00:00:00 456.00 def 1970-01-03 1970-01-03T00:00:00 456.00 def 1970-01-04 NULL -123.12 jkl 1970-01-04 NULL -123.12 jkl -NULL 1970-01-04T00:00:00 789 ghi NULL 1970-01-04T00:00:00 789 ghi +NULL 1970-01-04T00:00:00 789.00 ghi NULL 1970-01-04T00:00:00 789.00 ghi # explain hash_join_with_dictionary query TT @@ -2825,7 +2825,7 @@ query DDRTDDRT rowsort select * from hashjoin_datatype_table_t1 t1 join hashjoin_datatype_table_t2 t2 on t1.c1 = t2.c1 ---- 1970-01-02 1970-01-02T00:00:00 1.23 abc 1970-01-02 1970-01-02T00:00:00 -123.12 abc -1970-01-04 NULL -123.12 jkl 1970-01-04 NULL 789 qwe +1970-01-04 NULL -123.12 jkl 1970-01-04 NULL 789.00 qwe # explain sort_merge_join_on_decimal right join on data type (Decimal) query TT @@ -2854,9 +2854,9 @@ query DDRTDDRT rowsort select * from hashjoin_datatype_table_t1 t1 right join hashjoin_datatype_table_t2 t2 on t1.c3 = t2.c3 ---- 1970-01-04 NULL -123.12 jkl 1970-01-02 1970-01-02T00:00:00 -123.12 abc -NULL 1970-01-04T00:00:00 789 ghi 1970-01-04 NULL 789 qwe -NULL NULL NULL NULL NULL 1970-01-04T00:00:00 0 qwerty -NULL NULL NULL NULL NULL NULL 100000 abcdefg +NULL 1970-01-04T00:00:00 789.00 ghi 1970-01-04 NULL 789.00 qwe +NULL NULL NULL NULL NULL 1970-01-04T00:00:00 0.00 qwerty +NULL NULL NULL NULL NULL NULL 100000.00 abcdefg #### # Config teardown diff --git a/datafusion/sqllogictest/test_files/math.slt b/datafusion/sqllogictest/test_files/math.slt index 668809632e476..aa1aad2277683 100644 --- a/datafusion/sqllogictest/test_files/math.slt +++ b/datafusion/sqllogictest/test_files/math.slt @@ -730,9 +730,9 @@ NULL query R SELECT c1*0 FROM test_nullable_decimal WHERE c1 IS NOT NULL; ---- -0 -0 -0 +0.00 +0.00 +0.00 query error DataFusion error: Arrow error: Divide by zero error SELECT c1/0 FROM test_nullable_decimal WHERE c1 IS NOT NULL; @@ -755,7 +755,7 @@ Decimal128(10, 2) Decimal128(38, 10) Decimal256(40, 2) Decimal256(76, 10) query RRRR rowsort SELECT abs(c1), abs(c2), abs(c3), abs(c4) FROM test_nullable_decimal ---- -0 0 0 0 +0.00 0.0000000000 0.00 0.0000000000 99999999.99 9999999999999999999999999999.9999999999 99999999999999999999999999999999999999.99 999999999999999999999999999999999999999999999999999999999999999999.9999999999 99999999.99 9999999999999999999999999999.9999999999 99999999999999999999999999999999999999.99 999999999999999999999999999999999999999999999999999999999999999999.9999999999 NULL NULL NULL NULL @@ -883,7 +883,7 @@ select gcd(15.3::decimal(38, 1), 2.9::decimal(38, 1)), arrow_typeof(gcd(15.3::de query RT select gcd(15::decimal(30, 2), 3::decimal(38, 5)), arrow_typeof(gcd(15::decimal(30, 2), 3::decimal(38, 5))); ---- -3 Decimal128(38, 5) +3.00000 Decimal128(38, 5) ## lcm @@ -945,7 +945,7 @@ select lcm(2, 3::decimal(38, 0)), arrow_typeof(lcm(2, 3::decimal(38, 0))); query RT select lcm(2::decimal(30, 2), 3::decimal(38, 5)), arrow_typeof(lcm(2::decimal(30, 2), 3::decimal(38, 5))); ---- -6 Decimal128(38, 5) +6.00000 Decimal128(38, 5) ## pow/power diff --git a/datafusion/sqllogictest/test_files/optimizer_group_by_constant.slt b/datafusion/sqllogictest/test_files/optimizer_group_by_constant.slt index da1e7de22bb7a..21be3683c1c86 100644 --- a/datafusion/sqllogictest/test_files/optimizer_group_by_constant.slt +++ b/datafusion/sqllogictest/test_files/optimizer_group_by_constant.slt @@ -119,7 +119,7 @@ logical_plan # Config reset -# The SLT runner sets `target_partitions` to 4 instead of using the default, so +# The SLT runner sets `target_partitions` to 4 instead of using the default, so # reset it explicitly. statement ok set datafusion.execution.target_partitions = 4; diff --git a/datafusion/sqllogictest/test_files/options.slt b/datafusion/sqllogictest/test_files/options.slt index 00d7664779a66..380252fcb3cac 100644 --- a/datafusion/sqllogictest/test_files/options.slt +++ b/datafusion/sqllogictest/test_files/options.slt @@ -86,7 +86,7 @@ drop table a query RR select 10000000000000000000.01, -10000000000000000000.01 ---- -10000000000000000000 -10000000000000000000 +10000000000000000000 -10000000000000000000 query TT select arrow_typeof(10000000000000000000.01), arrow_typeof(-10000000000000000000.01) @@ -139,7 +139,7 @@ Int64 Int64 Decimal128(19, 0) Int64 UInt64 UInt64 Decimal128(20, 0) query RRRR select .0 as c1, 0. as c2, 0000. as c3, 00000.00 as c4 ---- -0 0 0 0 +0.0 0 0 0.00 query TTTT select arrow_typeof(.0) as c1, arrow_typeof(0.) as c2, arrow_typeof(0000.) as c3, arrow_typeof(00000.00) as c4 @@ -209,13 +209,13 @@ query RT select 123456789.0123456789012345678901234567890, arrow_typeof(123456789.0123456789012345678901234567890) ---- -123456789.012345678901234567890123456789 Decimal256(40, 31) +123456789.0123456789012345678901234567890 Decimal256(40, 31) query RT select -123456789.0123456789012345678901234567890, arrow_typeof(-123456789.0123456789012345678901234567890) ---- --123456789.012345678901234567890123456789 Decimal256(40, 31) +-123456789.0123456789012345678901234567890 Decimal256(40, 31) # max precision and scale of Decimal256 query RTRT @@ -277,7 +277,7 @@ query RTRT select 1e40 + 1e40, arrow_typeof(1e40 + 1e40), 1e-40 + -1e-40, arrow_typeof(1e-40 + -1e-40) ---- -20000000000000000000000000000000000000000 Decimal128(2, -40) 0 Decimal256(41, 40) +20000000000000000000000000000000000000000 Decimal128(2, -40) 0.0000000000000000000000000000000000000000 Decimal256(41, 40) # Restore option to default value statement ok diff --git a/datafusion/sqllogictest/test_files/pg_compat/pg_compat_types.slt b/datafusion/sqllogictest/test_files/pg_compat/pg_compat_types.slt index 7e315a448b48e..8339fb4fab24a 100644 --- a/datafusion/sqllogictest/test_files/pg_compat/pg_compat_types.slt +++ b/datafusion/sqllogictest/test_files/pg_compat/pg_compat_types.slt @@ -99,7 +99,7 @@ select 1.0::DOUBLE, 1.023::DOUBLE, 'NaN'::DOUBLE,'+Inf'::DOUBLE,'-Inf'::DOUBLE query RRR select 1.0::DECIMAL(5,3) as one, 2.023::DECIMAL(5,3) as two, 3.023::DECIMAL(5,2) as three ---- -1 2.023 3.02 +1.000 2.023 3.02 query D select '2018-01-01'::DATE diff --git a/datafusion/sqllogictest/test_files/predicates.slt b/datafusion/sqllogictest/test_files/predicates.slt index b4482a3af1beb..9e28d1fb08044 100644 --- a/datafusion/sqllogictest/test_files/predicates.slt +++ b/datafusion/sqllogictest/test_files/predicates.slt @@ -874,7 +874,7 @@ OR ) GROUP BY p_partkey; ---- -63700 13309.6 0.1 1 +63700 13309.60 0.100000 1 query TT diff --git a/datafusion/sqllogictest/test_files/qualify.slt b/datafusion/sqllogictest/test_files/qualify.slt index b70f078327a42..ca4775ef121f1 100644 --- a/datafusion/sqllogictest/test_files/qualify.slt +++ b/datafusion/sqllogictest/test_files/qualify.slt @@ -92,9 +92,9 @@ FROM users QUALIFY prev_salary IS NOT NULL AND salary > prev_salary ORDER BY dept, id; ---- -2 Bob 60000 50000 -8 Henry 62000 52000 -7 Grace 75000 65000 +2 Bob 60000.00 50000.00 +8 Henry 62000.00 52000.00 +7 Grace 75000.00 65000.00 # QUALIFY with LEAD function query ITRR @@ -103,9 +103,9 @@ FROM users QUALIFY next_salary IS NOT NULL AND salary < next_salary ORDER BY dept, id; ---- -1 Alice 50000 60000 -6 Frank 52000 62000 -5 Eve 65000 75000 +1 Alice 50000.00 60000.00 +6 Frank 52000.00 62000.00 +5 Eve 65000.00 75000.00 # QUALIFY with NTILE query ITI @@ -164,8 +164,8 @@ FROM users QUALIFY rn = 1 AND salary > 60000 ORDER BY dept, id; ---- -8 Henry 62000 1 -7 Grace 75000 1 +8 Henry 62000.00 1 +7 Grace 75000.00 1 # QUALIFY with string functions query ITI @@ -200,9 +200,9 @@ GROUP BY dept, salary HAVING SUM(salary) > 20000 QUALIFY r > 60000 ---- -Marketing 70000 -Marketing 70000 -Marketing 70000 +Marketing 70000.000000 +Marketing 70000.000000 +Marketing 70000.000000 # QUALIFY with aggregate function reference from projection query TR @@ -212,7 +212,7 @@ GROUP BY dept QUALIFY RANK() OVER (ORDER BY dept DESC) = 1 AND s > 1000 ORDER BY dept; ---- -Marketing 210000 +Marketing 210000.00 # QUALIFY with aggregate function query T @@ -232,7 +232,7 @@ GROUP BY dept QUALIFY RANK() OVER (ORDER BY SUM(salary) DESC) = 1 ORDER BY dept; ---- -Engineering 279000 +Engineering 279000.00 # QUALIFY with aggregate function reference from projection within window function query TR @@ -242,7 +242,7 @@ GROUP BY dept QUALIFY RANK() OVER (ORDER BY s DESC) = 1 ORDER BY dept; ---- -Engineering 279000 +Engineering 279000.00 # Error: QUALIFY without window functions query error diff --git a/datafusion/sqllogictest/test_files/repartition.slt b/datafusion/sqllogictest/test_files/repartition.slt index cf913caefc525..7cec3b5844112 100644 --- a/datafusion/sqllogictest/test_files/repartition.slt +++ b/datafusion/sqllogictest/test_files/repartition.slt @@ -140,7 +140,7 @@ FROM t1 WHERE ((false > (v1 = v1)) IS DISTINCT FROM true); # Config reset -# The SLT runner sets `target_partitions` to 4 instead of using the default, so +# The SLT runner sets `target_partitions` to 4 instead of using the default, so # reset it explicitly. statement ok set datafusion.execution.target_partitions = 4; diff --git a/datafusion/sqllogictest/test_files/run_end_encoded.slt b/datafusion/sqllogictest/test_files/run_end_encoded.slt index b5909bc7c430d..8660dd485d071 100644 --- a/datafusion/sqllogictest/test_files/run_end_encoded.slt +++ b/datafusion/sqllogictest/test_files/run_end_encoded.slt @@ -63,10 +63,10 @@ SELECT arrow_cast(arrow_cast(temperature, 'Decimal128(10, 2)'), 'RunEndEncoded("run_ends": non-null Int32, "values": Decimal128(10, 2))') + 1 AS t_dec_plus_one FROM sensor_readings; ---- -21 21 -23 23 -24 24 -25 25 +21 21.00 +23 23.00 +24 24.00 +25 25.00 # Regex / LIKE match against an REE column whose values are themselves Dictionary-encoded query BB rowsort diff --git a/datafusion/sqllogictest/test_files/scalar.slt b/datafusion/sqllogictest/test_files/scalar.slt index 7666b680e16a8..1880b250e7b0b 100644 --- a/datafusion/sqllogictest/test_files/scalar.slt +++ b/datafusion/sqllogictest/test_files/scalar.slt @@ -344,7 +344,7 @@ select ceil(arrow_cast(123.00,'Decimal128(10,2)')), ceil(arrow_cast(-123.00,'Decimal128(10,2)')); ---- -2 -1 123 -123 +2.00 -1.00 123.00 -123.00 # ceil overflow with limited precision query error Decimal overflow while applying ceil @@ -539,7 +539,7 @@ select floor(arrow_cast(123.00,'Decimal128(10,2)')), floor(arrow_cast(-123.00,'Decimal128(10,2)')); ---- -1 -2 123 -123 +1.00 -2.00 123.00 -123.00 # floor overflow with limited precision query error Decimal overflow while applying floor @@ -1083,7 +1083,7 @@ query TR select arrow_typeof(round(val, dp)), round(val, dp) from (values (cast('999.9' as decimal(4,1)), 0)) as t(val, dp); ---- -Decimal128(5, 1) 1000 +Decimal128(5, 1) 1000.0 # round decimal at max precision now works (scale reduction handles overflow) query TR @@ -1104,7 +1104,7 @@ select arrow_typeof(round(cast(500 as decimal(10,-2)), -3)), round(cast(400 as decimal(10,-2)), -3), round(cast(-500 as decimal(10,-2)), -3); ---- -Decimal128(10, -3) 1000 0 -1000 +Decimal128(10, -3) 1000 0000 -1000 # round decimal with negative scale and carry-over query TR @@ -1337,7 +1337,7 @@ from small_floats; query RT select trunc(arrow_cast(3.1415, 'Decimal128(10,4)')), arrow_typeof(trunc(arrow_cast(3.1415, 'Decimal128(10,4)'))); ---- -3 Decimal128(10, 4) +3.0000 Decimal128(10, 4) # trunc with precision - decimals query RRRRR rowsort @@ -1348,21 +1348,21 @@ select trunc(arrow_cast(1.2837284, 'Decimal256(35,7)'), 2), trunc(arrow_cast(1.1, 'Decimal128(10,1)'), 0); ---- -4.267 1.12 -1.1231 1.28 1 +4.267 1.120000 -1.1231 1.2800000 1.0 # trunc with negative precision should truncate digits left of decimal - decimal types query RT select trunc(arrow_cast(12345.678, 'Decimal128(10,3)'), -3), arrow_typeof(trunc(arrow_cast(12345.678, 'Decimal128(10,3)'), -3)); ---- -12000 Decimal128(10, 3) +12000.000 Decimal128(10, 3) # trunc: coercion with a decimal argument and a non-int64 precision argument query RT select trunc(arrow_cast(1.2345678, 'Decimal128(20,14)'), arrow_cast(2, 'Int32')), arrow_typeof(trunc(arrow_cast(1.2345678, 'Decimal128(20,14)'), arrow_cast(2, 'Int32'))); ---- -1.23 Decimal128(20, 14) +1.23000000000000 Decimal128(20, 14) # trunc with columns and precision - decimal128 query RRR rowsort @@ -1372,10 +1372,10 @@ select trunc(arrow_cast(c, 'Decimal128(10,4)'), 0) as c0 from small_floats; ---- --1 NULL NULL -0 0 -1 -0 0 0 -0 0 1 +-1.0000 NULL NULL +0.0000 0.0000 -1.0000 +0.0000 0.0000 0.0000 +0.0000 0.0000 1.0000 # trunc issue #22512 query R diff --git a/datafusion/sqllogictest/test_files/spark/aggregate/try_sum.slt b/datafusion/sqllogictest/test_files/spark/aggregate/try_sum.slt index 0f440a97dd1cc..c9b5dabee6110 100644 --- a/datafusion/sqllogictest/test_files/spark/aggregate/try_sum.slt +++ b/datafusion/sqllogictest/test_files/spark/aggregate/try_sum.slt @@ -55,12 +55,12 @@ Infinity query R SELECT try_sum(x) AS sum_x FROM VALUES (DECIMAL(10,2) '1.23'), (DECIMAL(10,2) '4.77') AS tab(x); ---- -6 +6.00 query R SELECT try_sum(x) AS sum_x FROM VALUES (DECIMAL(10,2) '1.00'), (NULL), (DECIMAL(10,2) '2.50') AS tab(x); ---- -3.5 +3.50 query R SELECT try_sum(x) AS sum_x FROM VALUES (DECIMAL(5,0) '90000'), (DECIMAL(5,0) '20000') AS tab(x); @@ -131,10 +131,10 @@ SELECT try_sum(col) AS sum_x FROM VALUES (CAST(-0.0 AS DOUBLE)), (CAST(0.0 AS DO query R SELECT try_sum(col) AS sum_x FROM VALUES (CAST(-5.5 AS DECIMAL(10,2))), (CAST(5.5 AS DECIMAL(10,2))) AS tab(col); ---- -0 +0.00 # Compare double 0.0 vs decimal 0.00 query RR SELECT 0.0 AS double_zero, CAST(0.0 AS DECIMAL(10,2)) AS decimal_zero; ---- -0 0 +0 0.00 diff --git a/datafusion/sqllogictest/test_files/spark/math/abs.slt b/datafusion/sqllogictest/test_files/spark/math/abs.slt index 94092caab9854..5da474052520c 100644 --- a/datafusion/sqllogictest/test_files/spark/math/abs.slt +++ b/datafusion/sqllogictest/test_files/spark/math/abs.slt @@ -73,23 +73,23 @@ SELECT abs(-1.0::DOUBLE), abs(0.::DOUBLE), abs(-0.::DOUBLE), abs(-0::DOUBLE), ab query RRR SELECT abs(('-99999999.99')::DECIMAL(10, 2)), abs(0::DECIMAL(10, 2)), abs(NULL::DECIMAL(10, 2)); ---- -99999999.99 0 NULL +99999999.99 0.00 NULL query RRR SELECT abs(('-9999999999999999999999999999.9999999999')::DECIMAL(38, 10)), abs(0::DECIMAL(38, 10)), abs(NULL::DECIMAL(38, 10)); ---- -9999999999999999999999999999.9999999999 0 NULL +9999999999999999999999999999.9999999999 0.0000000000 NULL ## Scalar input: decimal256 query RRR SELECT abs(('-99999999999999999999999999999999999999.99')::DECIMAL(40, 2)), abs(0::DECIMAL(40, 2)), abs(NULL::DECIMAL(40, 2)); ---- -99999999999999999999999999999999999999.99 0 NULL +99999999999999999999999999999999999999.99 0.00 NULL query RRR SELECT abs(('-999999999999999999999999999999999999999999999999999999999999999999.9999999999')::DECIMAL(76, 10)), abs(0::DECIMAL(76, 10)), abs(NULL::DECIMAL(76, 10)); ---- -999999999999999999999999999999999999999999999999999999999999999999.9999999999 0 NULL +999999999999999999999999999999999999999999999999999999999999999999.9999999999 0.0000000000 NULL # Array input @@ -181,14 +181,14 @@ query R SELECT abs(a) FROM (VALUES (('-99999999.99')::DECIMAL(10, 2)), (0::DECIMAL(10, 2)), (NULL::DECIMAL(10, 2))) AS t(a); ---- 99999999.99 -0 +0.00 NULL query R SELECT abs(a) FROM (VALUES (('-9999999999999999999999999999.9999999999')::DECIMAL(38, 10)), (0::DECIMAL(38, 10)), (NULL::DECIMAL(38, 10))) AS t(a); ---- 9999999999999999999999999999.9999999999 -0 +0.0000000000 NULL ## Array input: decimal256 @@ -196,14 +196,14 @@ query R SELECT abs(a) FROM (VALUES (('-99999999999999999999999999999999999999.99')::DECIMAL(40, 2)), (0::DECIMAL(40, 2)), (NULL::DECIMAL(40, 2))) AS t(a); ---- 99999999999999999999999999999999999999.99 -0 +0.00 NULL query R SELECT abs(a) FROM (VALUES (('-999999999999999999999999999999999999999999999999999999999999999999.9999999999')::DECIMAL(76, 10)), (0::DECIMAL(76, 10)), (NULL::DECIMAL(76, 10))) AS t(a); ---- 999999999999999999999999999999999999999999999999999999999999999999.9999999999 -0 +0.0000000000 NULL ## Original Query: SELECT abs(INTERVAL -'1-1' YEAR TO MONTH); diff --git a/datafusion/sqllogictest/test_files/spark/math/mod.slt b/datafusion/sqllogictest/test_files/spark/math/mod.slt index 8229bb065152d..e5bea25cc1876 100644 --- a/datafusion/sqllogictest/test_files/spark/math/mod.slt +++ b/datafusion/sqllogictest/test_files/spark/math/mod.slt @@ -142,7 +142,7 @@ SELECT MOD(2.5::decimal(3,1), 1.2::decimal(2,1)) as mod_decimal_1; query R SELECT MOD(10.0::decimal(3,1), 3.0::decimal(2,1)) as mod_decimal_2; ---- -1 +1.0 # Division by zero returns NULL in legacy mode (ANSI off) query I diff --git a/datafusion/sqllogictest/test_files/spark/math/pmod.slt b/datafusion/sqllogictest/test_files/spark/math/pmod.slt index aa4a197ba470f..100f62909ac7f 100644 --- a/datafusion/sqllogictest/test_files/spark/math/pmod.slt +++ b/datafusion/sqllogictest/test_files/spark/math/pmod.slt @@ -221,7 +221,7 @@ SELECT CAST(pmod(15.8::float4, 4.2::float4) AS DECIMAL(3,1)) as pmod_float32_3; query R SELECT CAST(pmod(-15.8::float4, 4.2::float4) AS DECIMAL(3,1)) as pmod_float32_4; ---- -1 +1.0 # PMOD tests with special float values query R @@ -273,12 +273,12 @@ SELECT pmod(-2.5::decimal(3,1), 1.2::decimal(2,1)) as pmod_decimal_2; query R SELECT pmod(10.0::decimal(3,1), 3.0::decimal(2,1)) as pmod_decimal_3; ---- -1 +1.0 query R SELECT pmod(-10.0::decimal(3,1), 3.0::decimal(2,1)) as pmod_decimal_4; ---- -2 +2.0 # PMOD tests with different integer types query I diff --git a/datafusion/sqllogictest/test_files/spark/math/round.slt b/datafusion/sqllogictest/test_files/spark/math/round.slt index 7fee15079d1d0..309fbc1b52c5d 100644 --- a/datafusion/sqllogictest/test_files/spark/math/round.slt +++ b/datafusion/sqllogictest/test_files/spark/math/round.slt @@ -308,24 +308,24 @@ SELECT round(arrow_cast(42, 'UInt32'), 2::int); query R SELECT round(arrow_cast(2.5, 'Decimal32(9, 1)'), 0::int); ---- -3 +3.0 query R SELECT round(arrow_cast(-2.5, 'Decimal32(9, 1)'), 0::int); ---- --3 +-3.0 # round(decimal32, 2) query R SELECT round(arrow_cast(2.345, 'Decimal32(9, 3)'), 2::int); ---- -2.35 +2.350 # round(decimal32) default scale = 0 query R SELECT round(arrow_cast(3.5, 'Decimal32(9, 1)')); ---- -4 +4.0 # --- Decimal64 --- @@ -333,24 +333,24 @@ SELECT round(arrow_cast(3.5, 'Decimal32(9, 1)')); query R SELECT round(arrow_cast(2.5, 'Decimal64(18, 1)'), 0::int); ---- -3 +3.0 query R SELECT round(arrow_cast(-2.5, 'Decimal64(18, 1)'), 0::int); ---- --3 +-3.0 # round(decimal64, 2) query R SELECT round(arrow_cast(2.345, 'Decimal64(18, 3)'), 2::int); ---- -2.35 +2.350 # round(decimal64) default scale = 0 query R SELECT round(arrow_cast(3.5, 'Decimal64(18, 1)')); ---- -4 +4.0 # --- Decimal128 --- @@ -358,34 +358,34 @@ SELECT round(arrow_cast(3.5, 'Decimal64(18, 1)')); query R SELECT round(2.5::decimal(2,1), 0::int); ---- -3 +3.0 query R SELECT round(3.5::decimal(2,1), 0::int); ---- -4 +4.0 query R SELECT round(-2.5::decimal(2,1), 0::int); ---- --3 +-3.0 # round(decimal) default scale = 0 query R SELECT round(2.5::decimal(2,1)); ---- -3 +3.0 # round(decimal, 2) — keep 2 decimal places query R SELECT round(2.345::decimal(10,3), 2::int); ---- -2.35 +2.350 query R SELECT round(2.355::decimal(10,3), 2::int); ---- -2.36 +2.360 # round(decimal, scale larger than input scale) — no change query R @@ -397,19 +397,19 @@ SELECT round(2.5::decimal(2,1), 5::int); query R SELECT round(123.456::decimal(10,3), 1::int); ---- -123.5 +123.500 # round(decimal, negative scale) — round to tens query R SELECT round(125.0::decimal(10,1), -1::int); ---- -130 +130.0 # round(decimal, extreme negative scale) — should return 0, not error query R SELECT round(2.5::decimal(10,1), -400::int); ---- -0 +0.0 # --- Decimal256 --- @@ -417,24 +417,24 @@ SELECT round(2.5::decimal(10,1), -400::int); query R SELECT round(arrow_cast(2.5, 'Decimal256(38, 1)'), 0::int); ---- -3 +3.0 query R SELECT round(arrow_cast(-2.5, 'Decimal256(38, 1)'), 0::int); ---- --3 +-3.0 # round(decimal256, 2) query R SELECT round(arrow_cast(2.345, 'Decimal256(38, 3)'), 2::int); ---- -2.35 +2.350 # round(decimal256) default scale = 0 query R SELECT round(arrow_cast(3.5, 'Decimal256(38, 1)')); ---- -4 +4.0 # ------------------------------------------------------------------- # NULL handling @@ -481,10 +481,10 @@ CREATE TABLE test_round (id int, int_val int, float_val double, dec_val decimal( query IIRR rowsort SELECT id, round(int_val, -1::int), round(float_val), round(dec_val, 2::int) FROM test_round; ---- -1 30 3 2.35 -2 40 4 3.56 -3 -30 -3 -2.35 -4 120 1 1.01 +1 30 3 2.350 +2 40 4 3.560 +3 -30 -3 -2.350 +4 120 1 1.010 5 NULL NULL NULL statement ok @@ -566,7 +566,7 @@ SELECT round(2.5::double); query R SELECT round(2.5::decimal(2,1), 0::int); ---- -3 +3.0 # ANSI mode: integer overflow should error query error DataFusion error: Execution error: Int64 overflow on round diff --git a/datafusion/sqllogictest/test_files/struct.slt b/datafusion/sqllogictest/test_files/struct.slt index a0e47a8691f34..941bab7c2d866 100644 --- a/datafusion/sqllogictest/test_files/struct.slt +++ b/datafusion/sqllogictest/test_files/struct.slt @@ -1732,4 +1732,3 @@ drop view leaf_view; statement ok drop table leaf_base; - diff --git a/datafusion/sqllogictest/test_files/subquery.slt b/datafusion/sqllogictest/test_files/subquery.slt index 325cff62d3986..cd5a262b56519 100644 --- a/datafusion/sqllogictest/test_files/subquery.slt +++ b/datafusion/sqllogictest/test_files/subquery.slt @@ -2572,8 +2572,8 @@ from ( group by cntrycode order by cntrycode; ---- -18 1 30 -29 1 40 +18 1 30.00 +29 1 40.00 # `count(*)` over the same query must agree with the row count above. query I diff --git a/datafusion/sqllogictest/test_files/window.slt b/datafusion/sqllogictest/test_files/window.slt index cbbd9b74dfc00..72fbdbf5e9486 100644 --- a/datafusion/sqllogictest/test_files/window.slt +++ b/datafusion/sqllogictest/test_files/window.slt @@ -6600,9 +6600,9 @@ FROM ( ) ORDER BY a; ---- -1.5 1.5 2.5 -2.5 1.5 3.5 -3.5 2.5 3.5 +1.50 1.50 2.50 +2.50 1.50 3.50 +3.50 2.50 3.50 ############################################################################ # ROWS frame regression guard: huge offsets already saturate via @@ -6808,8 +6808,8 @@ FROM (VALUES(1,CAST(1.5 AS DECIMAL(10,2))), (4,CAST(NULL AS DECIMAL(10,2)))) t(i,v) ORDER BY i; ---- -1 2 -2 2.5 +1 2.000000 +2 2.500000 3 NULL 4 NULL