MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / array_to_string

Function array_to_string

src/expr/src/scalar/func/variadic.rs:446–472  ·  view source on GitHub ↗
(
    &self,
    array: Array<'a>,
    delimiter: &str,
    null_str_arg: OptionalArg<Option<&str>>,
)

Source from the content-addressed store, hash-verified

444
445#[sqlfunc]
446fn array_to_string<'a>(
447 &self,
448 array: Array<'a>,
449 delimiter: &str,
450 null_str_arg: OptionalArg<Option<&str>>,
451) -> Result<String, EvalError> {
452 // `flatten` treats absent arguments (`None`) the same as explicit NULL
453 // (`Some(None)`), both becoming `None`.
454 let null_str = null_str_arg.flatten();
455 let mut out = String::new();
456 for elem in array.elements().iter() {
457 if elem.is_null() {
458 if let Some(null_str) = null_str {
459 out.push_str(null_str);
460 out.push_str(delimiter);
461 }
462 } else {
463 stringify_datum(&mut out, elem, &self.elem_type)?;
464 out.push_str(delimiter);
465 }
466 }
467 if out.len() > 0 {
468 // Lop off last delimiter only if string is not empty
469 out.truncate(out.len() - delimiter.len());
470 }
471 Ok(out)
472}
473
474#[derive(
475 Ord,

Callers

nothing calls this directly

Calls 7

stringify_datumFunction · 0.85
elementsMethod · 0.80
flattenMethod · 0.45
iterMethod · 0.45
is_nullMethod · 0.45
lenMethod · 0.45
truncateMethod · 0.45

Tested by

no test coverage detected