Skip to content

Apache DataFusion SQL Query Engine

test: improve `gcd` sqllogictest coverage (#23972)

Yongting You802d8d2dc11c
diff --git a/datafusion/sqllogictest/test_files/math.slt b/datafusion/sqllogictest/test_files/math.slt
index 55320c0261..999709dfe7 100644
--- a/datafusion/sqllogictest/test_files/math.slt
+++ b/datafusion/sqllogictest/test_files/math.slt
@@ -1333,6 +1333,61 @@ SELECT gcd(arrow_cast(column1, 'Decimal128(38,0)'), arrow_cast(column2, 'Decimal
5
15
+# gcd with the remaining decimal array widths
+query R
+SELECT gcd(arrow_cast(column1, 'Decimal32(7,0)'), arrow_cast(column2, 'Decimal32(7,0)')) FROM (VALUES (15, 10), (15, 25), (15, 0));
+----
+5
+5
+15
+
+query R
+SELECT gcd(arrow_cast(column1, 'Decimal64(16,0)'), arrow_cast(column2, 'Decimal64(16,0)')) FROM (VALUES (15, 10), (15, 25), (15, 0));
+----
+5
+5
+15
+
+query R
+SELECT gcd(arrow_cast(column1, 'Decimal256(40,0)'), arrow_cast(column2, 'Decimal256(40,0)')) FROM (VALUES (15, 10), (15, 25), (15, 0));
+----
+5
+5
+15
+
+# gcd array with zero, minimum, and null scalars
+query I
+SELECT gcd(column1, 0) FROM (VALUES (1), (2), (0), (NULL));
+----
+1
+2
+0
+NULL
+
+query I
+SELECT gcd(column1, -9223372036854775808) FROM (VALUES (1), (2), (NULL));
+----
+1
+2
+NULL
+
+query I
+SELECT gcd(column1, NULL) FROM (VALUES (1), (2), (NULL));
+----
+NULL
+NULL
+NULL
+
+# invalid argument count and type
+query error gcd function requires 2 arguments, got 0
+SELECT gcd();
+
+query error gcd function requires 2 arguments, got 3
+SELECT gcd(1, 2, 3);
+
+query error Unsupported argument types Utf8 and Utf8 for function gcd
+SELECT gcd('x', 'y');
+
# gcd array and scalar with nulls in the array
query I