Skip to content

Commit 12ac114

Browse files
committed
edge null and test
1 parent 1319bfa commit 12ac114

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

datafusion/spark/src/function/string/concat_ws.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ fn collect_parts_from_list<O: OffsetSizeTrait>(
291291
/// Extract non-null string elements from an array.
292292
fn collect_string_elements(values: &ArrayRef, parts: &mut Vec<String>) -> Result<()> {
293293
match values.data_type() {
294+
DataType::Null => {}
294295
DataType::Utf8 => {
295296
let str_arr = as_generic_string_array::<i32>(values)?;
296297
for i in 0..str_arr.len() {

datafusion/sqllogictest/test_files/spark/string/concat_ws.slt

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,73 @@ SELECT concat_ws(',', 'a', 'b') AS result FROM VALUES (1), (2), (3) AS t(x);
137137
a,b
138138
a,b
139139
a,b
140+
141+
## ── Additional edge cases ───────────────────────────────────
142+
143+
## Empty separator — values concatenated with nothing between
144+
query T
145+
SELECT concat_ws('', 'a', 'b', 'c');
146+
----
147+
abc
148+
149+
## Empty-string values are NOT skipped (only NULLs are)
150+
query T
151+
SELECT concat_ws(',', '', 'a', '', 'b');
152+
----
153+
,a,,b
154+
155+
## Multi-character separator
156+
query T
157+
SELECT concat_ws(' - ', 'a', 'b', 'c');
158+
----
159+
a - b - c
160+
161+
## Utf8View separator
162+
query TT
163+
SELECT concat_ws(arrow_cast(',', 'Utf8View'), 'a', 'b'), arrow_typeof(concat_ws(arrow_cast(',', 'Utf8View'), 'a', 'b'));
164+
----
165+
a,b Utf8
166+
167+
## LargeUtf8 separator
168+
query TT
169+
SELECT concat_ws(arrow_cast(',', 'LargeUtf8'), 'a', 'b'), arrow_typeof(concat_ws(arrow_cast(',', 'LargeUtf8'), 'a', 'b'));
170+
----
171+
a,b Utf8
172+
173+
## Empty array → empty string
174+
query T
175+
SELECT concat_ws(',', array());
176+
----
177+
(empty)
178+
179+
## Scalar + array + array mix
180+
query T
181+
SELECT concat_ws(',', array('a', 'b'), 'c', array('d', 'e'));
182+
----
183+
a,b,c,d,e
184+
185+
## All-NULL row mixed with non-NULL rows
186+
query T
187+
SELECT concat_ws(',', a, b, c) AS result FROM VALUES
188+
('a', 'b', 'c'),
189+
(CAST(NULL AS STRING), 'b', 'c'),
190+
('a', CAST(NULL AS STRING), CAST(NULL AS STRING)),
191+
(CAST(NULL AS STRING), CAST(NULL AS STRING), CAST(NULL AS STRING))
192+
AS t(a, b, c);
193+
----
194+
a,b,c
195+
b,c
196+
a
197+
(empty)
198+
199+
## Separator from column (per-row separator), with NULL rows
200+
query T
201+
SELECT concat_ws(sep, a, b) AS result FROM VALUES
202+
(',', 'a', 'b'),
203+
(CAST(NULL AS STRING), 'a', 'b'),
204+
('|', 'x', 'y')
205+
AS t(sep, a, b);
206+
----
207+
a,b
208+
NULL
209+
x|y

0 commit comments

Comments
 (0)