Skip to content

Commit 6f2f340

Browse files
fix: remove comments, simplify branches, add null_string empty-input test
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d23a3db commit 6f2f340

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

datafusion/functions-nested/src/string.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -744,23 +744,20 @@ where
744744
list_builder.append(true);
745745
}
746746
(Some(string), Some(delimiter)) => {
747-
if string.is_empty() {
748-
// empty string returns empty array (PostgreSQL compatibility)
749-
list_builder.append(true);
750-
} else {
747+
if !string.is_empty() {
751748
string.split(delimiter).for_each(|s| {
752749
list_builder.values().append_value(s);
753750
});
754-
list_builder.append(true);
755751
}
752+
list_builder.append(true);
756753
}
757754
(Some(string), None) => {
758755
string.chars().map(|c| c.to_string()).for_each(|c| {
759756
list_builder.values().append_value(c.as_str());
760757
});
761758
list_builder.append(true);
762759
}
763-
_ => list_builder.append(false), // null value
760+
_ => list_builder.append(false),
764761
}
765762
},
766763
)
@@ -782,19 +779,16 @@ where
782779
list_builder.append(true);
783780
}
784781
(Some(string), Some(delimiter)) => {
785-
if string.is_empty() {
786-
// empty string returns empty array (PostgreSQL compatibility)
787-
list_builder.append(true);
788-
} else {
782+
if !string.is_empty() {
789783
string.split(delimiter).for_each(|s| {
790784
if Some(s) == null_value {
791785
list_builder.values().append_null();
792786
} else {
793787
list_builder.values().append_value(s);
794788
}
795789
});
796-
list_builder.append(true);
797790
}
791+
list_builder.append(true);
798792
}
799793
(Some(string), None) => {
800794
string.chars().map(|c| c.to_string()).for_each(|c| {

datafusion/sqllogictest/test_files/array.slt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8634,6 +8634,13 @@ SELECT string_to_array('', '')
86348634
----
86358635
[]
86368636

8637+
# empty string with null_string arg — without the fix "".split(",") yields [""],
8638+
# which is != the null_string "x", so the result would be [""] instead of []
8639+
query ?
8640+
SELECT string_to_array('', ',', 'x')
8641+
----
8642+
[]
8643+
86378644
query ?
86388645
SELECT string_to_array('abc', '')
86398646
----

0 commit comments

Comments
 (0)