From e214d6b6129f2b66283c5f2ed65323d57a64630d Mon Sep 17 00:00:00 2001 From: Raphael Taylor-Davies <1781103+tustvold@users.noreply.github.com> Date: Tue, 19 Sep 2023 11:57:15 +0100 Subject: [PATCH] Respect FormatOption::nulls for NullArray (#4836) * Respect FormatOption::nulls for NullArray * Clippy --- arrow-cast/src/display.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/arrow-cast/src/display.rs b/arrow-cast/src/display.rs index d15d57cf3c05..246135e114bc 100644 --- a/arrow-cast/src/display.rs +++ b/arrow-cast/src/display.rs @@ -399,8 +399,15 @@ impl<'a> DisplayIndex for &'a BooleanArray { } } -impl<'a> DisplayIndex for &'a NullArray { - fn write(&self, _idx: usize, _f: &mut dyn Write) -> FormatResult { +impl<'a> DisplayIndexState<'a> for &'a NullArray { + type State = &'a str; + + fn prepare(&self, options: &FormatOptions<'a>) -> Result { + Ok(options.null) + } + + fn write(&self, state: &Self::State, _idx: usize, f: &mut dyn Write) -> FormatResult { + f.write_str(state)?; Ok(()) } } @@ -1098,4 +1105,12 @@ mod tests { assert_eq!(iso[5], "-P45DT50554S"); assert_eq!(pretty[5], "-45 days -14 hours -2 mins -34 secs"); } + + #[test] + fn test_null() { + let array = NullArray::new(2); + let options = FormatOptions::new().with_null("NULL"); + let formatted = format_array(&array, &options); + assert_eq!(formatted, &["NULL".to_string(), "NULL".to_string()]) + } }