neilconway commented on code in PR #23973:
URL: https://github.com/apache/datafusion/pull/23973#discussion_r3675305854
##########
datafusion/sqllogictest/test_files/math.slt:
##########
@@ -88,6 +88,92 @@ SELECT round(125.2345, -3), round(125.2345, -2),
round(125.2345, -1), round(125.
----
0 100 130 125 125 125.2 125.23 125.235
+# Round signed and unsigned integer scalar widths
+query IIIIIIII
+SELECT
+ round(arrow_cast('115', 'Int8'), -1),
+ round(arrow_cast('-115', 'Int16'), -1),
+ round(arrow_cast('115', 'Int32'), -1),
+ round(arrow_cast('-115', 'Int64'), -1),
+ round(arrow_cast('115', 'UInt8'), -1),
+ round(arrow_cast('115', 'UInt16'), -1),
+ round(arrow_cast('115', 'UInt32'), -1),
+ round(arrow_cast('115', 'UInt64'), -1);
+----
+120 -120 120 -120 120 120 120 120
+
+# Round signed and unsigned integer arrays, including null and oversized scales
+query IIIIIIII
+SELECT
+ round(arrow_cast(column1, 'Int8'), column2),
+ round(arrow_cast(column1, 'Int16'), column2),
+ round(arrow_cast(column1, 'Int32'), column2),
+ round(arrow_cast(column1, 'Int64'), column2),
+ round(arrow_cast(column1, 'UInt8'), column2),
+ round(arrow_cast(column1, 'UInt16'), column2),
+ round(arrow_cast(column1, 'UInt32'), column2),
+ round(arrow_cast(column1, 'UInt64'), column2)
+FROM (VALUES ('115', -1), ('0', -1), (NULL, -20)) AS t(column1, column2);
+----
+120 120 120 120 120 120 120 120
+0 0 0 0 0 0 0 0
+NULL NULL NULL NULL NULL NULL NULL NULL
+
+# Round all decimal widths as scalars
+query RRRR
+SELECT
+ round(arrow_cast('125.55', 'Decimal32(7,2)'), 1),
+ round(arrow_cast('-125.55', 'Decimal64(16,2)'), 1),
+ round(arrow_cast('125.55', 'Decimal128(30,2)'), 1),
+ round(arrow_cast('-125.55', 'Decimal256(40,2)'), 1);
+----
+125.6 -125.6 125.6 -125.6
+
+# Round all decimal widths as arrays with per-row decimal places
+query RRRR
+SELECT
+ round(arrow_cast(column1, 'Decimal32(7,2)'), column2),
+ round(arrow_cast(column1, 'Decimal64(16,2)'), column2),
+ round(arrow_cast(column1, 'Decimal128(30,2)'), column2),
+ round(arrow_cast(column1, 'Decimal256(40,2)'), column2)
+FROM (VALUES ('125.55', 1), ('-125.55', 0), ('125.55', -1), (NULL, 1)) AS
t(column1, column2);
+----
+125.6 125.6 125.6 125.6
+-126 -126 -126 -126
+130 130 130 130
+NULL NULL NULL NULL
+
+# Float arrays with scalar and per-row decimal places
+query RRRR
+SELECT
+ round(arrow_cast(column1, 'Float32'), 1),
+ round(arrow_cast(column1, 'Float64'), 1),
+ round(arrow_cast(column1, 'Float32'), column2),
+ round(arrow_cast(column1, 'Float64'), column2)
+FROM (VALUES ('125.55', 1), ('-125.55', 0), (NULL, -1)) AS t(column1, column2);
+----
+125.6 125.6 125.6 125.6
+-125.6 -125.6 -126 -126
+NULL NULL NULL NULL
+
+# Null decimal places, invalid argument count/type, and out-of-range scale
+query R
+SELECT round(1.25, NULL);
+----
+NULL
+
+query error DataFusion error:
+SELECT round();
+
+query error DataFusion error:
+SELECT round(1, 2, 3);
+
+query error DataFusion error:
+SELECT round('x');
Review Comment:
Can we make the error matches more precise?
##########
datafusion/sqllogictest/test_files/math.slt:
##########
@@ -88,6 +88,92 @@ SELECT round(125.2345, -3), round(125.2345, -2),
round(125.2345, -1), round(125.
----
0 100 130 125 125 125.2 125.23 125.235
+# Round signed and unsigned integer scalar widths
+query IIIIIIII
+SELECT
+ round(arrow_cast('115', 'Int8'), -1),
+ round(arrow_cast('-115', 'Int16'), -1),
+ round(arrow_cast('115', 'Int32'), -1),
+ round(arrow_cast('-115', 'Int64'), -1),
+ round(arrow_cast('115', 'UInt8'), -1),
+ round(arrow_cast('115', 'UInt16'), -1),
+ round(arrow_cast('115', 'UInt32'), -1),
+ round(arrow_cast('115', 'UInt64'), -1);
+----
+120 -120 120 -120 120 120 120 120
+
+# Round signed and unsigned integer arrays, including null and oversized scales
Review Comment:
I think we'd benefit from another test row that checks oversized scales but
does not have a NULL in `column1` (since NULLs take a different code path).
e.g., `('115', -20)`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]