Skip to content

Conversation

Jefffrey
Copy link
Contributor

Which issue does this PR close?

Part of #8249

Rationale for this change

Was checking through array functions and found array_to_string doesn't handle FixedSizeList arrays. Fix so it does.

What changes are included in this PR?

  • Fix signature of array_to_string to allow coercion from FixedSizeList to List
  • Use more specific type signature API as well
  • Also fix to allow FixedSizeList as one of the child elements of the input list

Are these changes tested?

Added SLT cases

Are there any user-facing changes?

No

@Jefffrey Jefffrey mentioned this pull request Sep 19, 2025
19 tasks
@github-actions github-actions bot added sqllogictest SQL Logic Tests (.slt) common Related to common crate labels Sep 19, 2025
Comment on lines -187 to +209
fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
Ok(match arg_types[0] {
List(_) | LargeList(_) | FixedSizeList(_, _) => Utf8,
_ => {
return plan_err!("The array_to_string function can only accept List/LargeList/FixedSizeList.");
}
})
fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
Ok(Utf8)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to guard here since type signature should enforce for us now

Comment on lines -287 to +306
Ok(match arg_types[0] {
Utf8 | Utf8View | LargeUtf8 => {
List(Arc::new(Field::new_list_field(arg_types[0].clone(), true)))
}
_ => {
return plan_err!(
"The string_to_array function can only accept Utf8, Utf8View or LargeUtf8."
);
}
})
Ok(List(Arc::new(Field::new_list_field(
arg_types[0].clone(),
true,
))))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for string to array, but is similar to above in that type signature already ensures the arguments are string

Comment on lines +383 to +396
FixedSizeList(..) => {
let list_array = as_fixed_size_list_array(&arr)?;
for i in 0..list_array.len() {
compute_array_to_string(
arg,
list_array.value(i),
delimiter.clone(),
null_string.clone(),
with_null_string,
)?;
}

Ok(arg)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is handling for when an element of the input list is a FixedSizeList itself

Comment on lines -474 to -494
_ => {
let mut arg = String::from("");
let mut res: Vec<Option<String>> = Vec::new();
// delimiter length is 1
assert_eq!(delimiters.len(), 1);
let delimiter = delimiters[0].unwrap();
let s = compute_array_to_string(
&mut arg,
Arc::clone(arr),
delimiter.to_string(),
null_string,
with_null_string,
)?
.clone();

if !s.is_empty() {
let s = s.strip_suffix(delimiter).unwrap().to_string();
res.push(Some(s));
} else {
res.push(Some(s));
}
StringArray::from(res)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this arm as the array (which is the first argument) must be a List type (List, Fixed or Large) by this point so this arm didn't make sense; even before my changes I don't think this arm was ever reachable as the return_type() function guarded arg[0] to be a list type 🤔

Comment on lines +4713 to +4716
query T
select array_to_string(arrow_cast([arrow_cast([NULL, 'a'], 'FixedSizeList(2, Utf8)'), NULL], 'FixedSizeList(2, FixedSizeList(2, Utf8))'), ',', '-');
----
-,a,-,-
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is interesting; it's formatting [[NULL, 'a'], NULL] to become this; note three - implying three nulls. I'm not sure if this is desired or if it should instead be -,a,- since the second element of the parent array is null (current code considers it to be two nulls, I guess because it represents a FixedSizeList(2)) 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look into this as a follow-on issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raised #17692

@Jefffrey Jefffrey marked this pull request as ready for review September 19, 2025 11:10
Copy link
Contributor

@comphead comphead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Jefffrey this PR lgtm

@Jefffrey Jefffrey added this pull request to the merge queue Sep 21, 2025
Merged via the queue into apache:main with commit d55fb6d Sep 21, 2025
28 checks passed
@Jefffrey Jefffrey deleted the array_to_string_fsl branch September 21, 2025 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
common Related to common crate sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants