MCPcopy Create free account
hub / github.com/apache/datafusion / compute_array_to_string

Function compute_array_to_string

datafusion/functions-nested/src/string.rs:590–746  ·  view source on GitHub ↗
(
    w: &mut impl Write,
    arr: &ArrayRef,
    delimiter: &str,
    null_string: Option<&str>,
    first: &mut bool,
)

Source from the content-addressed store, hash-verified

588}
589
590fn compute_array_to_string(
591 w: &mut impl Write,
592 arr: &ArrayRef,
593 delimiter: &str,
594 null_string: Option<&str>,
595 first: &mut bool,
596) -> Result<()> {
597 // Handle lists by recursing on each list element.
598 macro_rules! handle_list {
599 ($list_array:expr) => {
600 for i in 0..$list_array.len() {
601 if !$list_array.is_null(i) {
602 compute_array_to_string(
603 w,
604 &$list_array.value(i),
605 delimiter,
606 null_string,
607 first,
608 )?;
609 } else if let Some(ns) = null_string {
610 if *first {
611 *first = false;
612 } else {
613 w.write_str(delimiter)?;
614 }
615 w.write_str(ns)?;
616 }
617 }
618 };
619 }
620
621 match arr.data_type() {
622 List(..) => {
623 let list_array = as_list_array(arr)?;
624 handle_list!(list_array);
625 Ok(())
626 }
627 FixedSizeList(..) => {
628 let list_array = as_fixed_size_list_array(arr)?;
629 handle_list!(list_array);
630 Ok(())
631 }
632 LargeList(..) => {
633 let list_array = as_large_list_array(arr)?;
634 handle_list!(list_array);
635 Ok(())
636 }
637 Dictionary(_key_type, value_type) => {
638 // Call cast to unwrap the dictionary. This could be optimized if we wanted
639 // to accept the overhead of extra code
640 let values = cast(arr, value_type.as_ref()).map_err(|e| {
641 DataFusionError::from(e)
642 .context("Casting dictionary to values in compute_array_to_string")
643 })?;
644 compute_array_to_string(w, &values, delimiter, null_string, first)
645 }
646 Null => Ok(()),
647 data_type => {

Callers 1

generate_string_arrayFunction · 0.85

Calls 7

as_list_arrayFunction · 0.85
as_fixed_size_list_arrayFunction · 0.85
as_large_list_arrayFunction · 0.85
contextMethod · 0.80
castFunction · 0.50
data_typeMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…