Skip to content

Commit

Permalink
Respect FormatOption::nulls for NullArray (apache#4836)
Browse files Browse the repository at this point in the history
* Respect FormatOption::nulls for NullArray

* Clippy
  • Loading branch information
tustvold authored Sep 19, 2023
1 parent f7464bc commit e214d6b
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions arrow-cast/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self::State, ArrowError> {
Ok(options.null)
}

fn write(&self, state: &Self::State, _idx: usize, f: &mut dyn Write) -> FormatResult {
f.write_str(state)?;
Ok(())
}
}
Expand Down Expand Up @@ -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()])
}
}

0 comments on commit e214d6b

Please sign in to comment.