You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2023/09/19 10:57:21 UTC
[arrow-rs] branch master updated: Respect FormatOption::nulls for NullArray (#4836)
This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new e214d6b612 Respect FormatOption::nulls for NullArray (#4836)
e214d6b612 is described below
commit e214d6b6129f2b66283c5f2ed65323d57a64630d
Author: Raphael Taylor-Davies <17...@users.noreply.github.com>
AuthorDate: Tue Sep 19 11:57:15 2023 +0100
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 d15d57cf3c..246135e114 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<Self::State, ArrowError> {
+ 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()])
+ }
}