Skip to content

Apache DataFusion SQL Query Engine

test: improve `rpad` sqllogictest coverage (#23968)

Yongting You0bcbe40024f9
diff --git a/datafusion/sqllogictest/test_files/string/string_literal.slt b/datafusion/sqllogictest/test_files/string/string_literal.slt
index c175f52a35..6962a6d337 100644
--- a/datafusion/sqllogictest/test_files/string/string_literal.slt
+++ b/datafusion/sqllogictest/test_files/string/string_literal.slt
@@ -664,6 +664,64 @@ SELECT rpad('x', 5, 'e' || chr(769)) = 'x' || 'e' || chr(769) || 'e' || chr(769)
----
true 5
+# rpad with string, length, and fill arrays in every string width
+query BBB
+SELECT
+ rpad(arrow_cast(column1, 'Utf8'), column2, arrow_cast(column3, 'Utf8')) IS NOT DISTINCT FROM column4,
+ rpad(arrow_cast(column1, 'LargeUtf8'), column2, arrow_cast(column3, 'LargeUtf8')) IS NOT DISTINCT FROM column4,
+ rpad(arrow_cast(column1, 'Utf8View'), column2, arrow_cast(column3, 'Utf8View')) IS NOT DISTINCT FROM column4
+FROM (VALUES
+ ('hi', 5, 'xy', 'hixyx'),
+ ('abcdef', 3, 'z', 'abc'),
+ ('é', 4, '好', 'é好好好'),
+ ('hi', 5, '', 'hi'),
+ (NULL, 5, 'x', NULL),
+ ('hi', NULL, 'x', NULL),
+ ('hi', 5, NULL, NULL)
+) AS t(column1, column2, column3, column4);
+----
+true true true
+true true true
+true true true
+true true true
+true true true
+true true true
+true true true
+
+# rpad array path with the default fill
+query BBB
+SELECT
+ rpad(arrow_cast(column1, 'Utf8'), column2) IS NOT DISTINCT FROM column3,
+ rpad(arrow_cast(column1, 'LargeUtf8'), column2) IS NOT DISTINCT FROM column3,
+ rpad(arrow_cast(column1, 'Utf8View'), column2) IS NOT DISTINCT FROM column3
+FROM (VALUES ('hi', 5, 'hi '), ('abcdef', 3, 'abc'), (NULL, 5, NULL)) AS t(column1, column2, column3);
+----
+true true true
+true true true
+true true true
+
+# a large scalar target length skips the scalar fast path
+query I
+SELECT character_length(rpad('x', 16385, 'a'));
+----
+16385
+
+# invalid argument count/type and excessive target length
+query error 'rpad' does not support zero arguments
+SELECT rpad();
+
+query error Failed to coerce arguments to satisfy a call to 'rpad' function: coercion from Utf8 to the signature
+SELECT rpad('x');
+
+query error Failed to coerce arguments to satisfy a call to 'rpad' function: coercion from Utf8, Int64, Utf8, Utf8 to the signature
+SELECT rpad('x', 2, 'y', 'z');
+
+query error Failed to coerce arguments to satisfy a call to 'rpad' function: coercion from Utf8, Utf8 to the signature
+SELECT rpad('x', 'bad');
+
+query error rpad requested length 2147483648 too large
+SELECT rpad('x', 2147483648, 'y');
+
query I
SELECT char_length('')
----