From b3f99f09745daab92d5afcbc707d92a47df3b1be Mon Sep 17 00:00:00 2001 From: kamille Date: Tue, 2 Jul 2024 03:54:42 +0800 Subject: [PATCH 1/6] improve dispaly for interval. --- arrow-cast/src/display.rs | 110 ++++++++++++++++++++++++++------------ 1 file changed, 75 insertions(+), 35 deletions(-) diff --git a/arrow-cast/src/display.rs b/arrow-cast/src/display.rs index 6a40d036350a..1ad464fb30d7 100644 --- a/arrow-cast/src/display.rs +++ b/arrow-cast/src/display.rs @@ -656,7 +656,7 @@ impl<'a> DisplayIndex for &'a PrimitiveArray { write!( f, - "{years} years {month} mons 0 days 0 hours 0 mins 0.00 secs", + "{years} years {month} mons", )?; Ok(()) } @@ -666,61 +666,101 @@ impl<'a> DisplayIndex for &'a PrimitiveArray { fn write(&self, idx: usize, f: &mut dyn Write) -> FormatResult { let value = self.value(idx); - let secs = value.milliseconds / 1_000; + if value.days != 0 { + write!(f, "{} days ", value.days,)?; + } + + if value.milliseconds != 0 { + let millis_fmt = MillisecondsFormatter(value.milliseconds); + millis_fmt.fmt(f)?; + } + + Ok(()) + } +} + +impl<'a> DisplayIndex for &'a PrimitiveArray { + fn write(&self, idx: usize, f: &mut dyn Write) -> FormatResult { + let value = self.value(idx); + + if value.months != 0 { + write!(f, "{} mons ", value.months,)?; + } + + if value.days != 0 { + write!(f, "{} days ", value.days,)?; + } + + if value.nanoseconds != 0 { + let nano_fmt = NanosecondsFormatter(value.nanoseconds); + nano_fmt.fmt(f)?; + } + + Ok(()) + } +} + +struct NanosecondsFormatter(i64); + +impl Display for NanosecondsFormatter { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let secs = self.0 / 1_000_000_000; let mins = secs / 60; let hours = mins / 60; let secs = secs - (mins * 60); let mins = mins - (hours * 60); - let milliseconds = value.milliseconds % 1_000; + let nanoseconds = self.0 % 1_000_000_000; - let secs_sign = if secs < 0 || milliseconds < 0 { - "-" - } else { - "" - }; + if hours != 0 { + write!(f, "{} hours ", hours,)?; + } + + if mins != 0 { + write!(f, "{} mins ", mins,)?; + } + + if secs != 0 || nanoseconds != 0 { + let secs_sign = if secs < 0 || nanoseconds < 0 { "-" } else { "" }; + write!(f, "{}{}.{:09} secs", secs_sign, secs, nanoseconds)?; + } - write!( - f, - "0 years 0 mons {} days {} hours {} mins {}{}.{:03} secs", - value.days, - hours, - mins, - secs_sign, - secs.abs(), - milliseconds.abs(), - )?; Ok(()) } } -impl<'a> DisplayIndex for &'a PrimitiveArray { - fn write(&self, idx: usize, f: &mut dyn Write) -> FormatResult { - let value = self.value(idx); +struct MillisecondsFormatter(i32); - let secs = value.nanoseconds / 1_000_000_000; +impl Display for MillisecondsFormatter { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let secs = self.0 / 1_000; let mins = secs / 60; let hours = mins / 60; let secs = secs - (mins * 60); let mins = mins - (hours * 60); - let nanoseconds = value.nanoseconds % 1_000_000_000; + let milliseconds = self.0 % 1_000; - let secs_sign = if secs < 0 || nanoseconds < 0 { "-" } else { "" }; + if hours != 0 { + write!(f, "{} hours ", hours,)?; + } + + if mins != 0 { + write!(f, "{} mins ", mins,)?; + } + + if secs != 0 || milliseconds != 0 { + let secs_sign = if secs < 0 || milliseconds < 0 { + "-" + } else { + "" + }; + + write!(f, "{}{}.{:03} secs", secs_sign, secs, milliseconds)?; + } - write!( - f, - "0 years {} mons {} days {} hours {} mins {}{}.{:09} secs", - value.months, - value.days, - hours, - mins, - secs_sign, - secs.abs(), - nanoseconds.abs(), - )?; Ok(()) } } From f7e1b07820bdc678603182b6500613d5e04149ff Mon Sep 17 00:00:00 2001 From: kamille Date: Fri, 5 Jul 2024 17:06:00 +0800 Subject: [PATCH 2/6] update test in pretty, and fix display problem. --- arrow-cast/src/display.rs | 26 +++++++++++++------ arrow-cast/src/pretty.rs | 54 +++++++++++++++++++-------------------- 2 files changed, 45 insertions(+), 35 deletions(-) diff --git a/arrow-cast/src/display.rs b/arrow-cast/src/display.rs index 1ad464fb30d7..0dcaafcf467d 100644 --- a/arrow-cast/src/display.rs +++ b/arrow-cast/src/display.rs @@ -35,6 +35,7 @@ use arrow_buffer::ArrowNativeType; use arrow_schema::*; use chrono::{NaiveDate, NaiveDateTime, SecondsFormat, TimeZone, Utc}; use lexical_core::FormattedSize; +use num::Signed; type TimeFormat<'a> = Option<&'a str>; @@ -654,10 +655,7 @@ impl<'a> DisplayIndex for &'a PrimitiveArray { let years = (interval / 12_f64).floor(); let month = interval - (years * 12_f64); - write!( - f, - "{years} years {month} mons", - )?; + write!(f, "{years} years {month} mons",)?; Ok(()) } } @@ -672,7 +670,7 @@ impl<'a> DisplayIndex for &'a PrimitiveArray { if value.milliseconds != 0 { let millis_fmt = MillisecondsFormatter(value.milliseconds); - millis_fmt.fmt(f)?; + f.write_fmt(format_args!("{millis_fmt}"))?; } Ok(()) @@ -693,7 +691,7 @@ impl<'a> DisplayIndex for &'a PrimitiveArray { if value.nanoseconds != 0 { let nano_fmt = NanosecondsFormatter(value.nanoseconds); - nano_fmt.fmt(f)?; + f.write_fmt(format_args!("{nano_fmt}"))?; } Ok(()) @@ -723,7 +721,13 @@ impl Display for NanosecondsFormatter { if secs != 0 || nanoseconds != 0 { let secs_sign = if secs < 0 || nanoseconds < 0 { "-" } else { "" }; - write!(f, "{}{}.{:09} secs", secs_sign, secs, nanoseconds)?; + write!( + f, + "{}{}.{:09} secs", + secs_sign, + secs.abs(), + nanoseconds.abs() + )?; } Ok(()) @@ -758,7 +762,13 @@ impl Display for MillisecondsFormatter { "" }; - write!(f, "{}{}.{:03} secs", secs_sign, secs, milliseconds)?; + write!( + f, + "{}{}.{:03} secs", + secs_sign, + secs.abs(), + milliseconds.abs() + )?; } Ok(()) diff --git a/arrow-cast/src/pretty.rs b/arrow-cast/src/pretty.rs index 9383b9f73f61..9c7a85eb1441 100644 --- a/arrow-cast/src/pretty.rs +++ b/arrow-cast/src/pretty.rs @@ -986,16 +986,16 @@ mod tests { let table = pretty_format_batches(&[batch]).unwrap().to_string(); let expected = vec![ - "+----------------------------------------------------+", - "| IntervalDayTime |", - "+----------------------------------------------------+", - "| 0 years 0 mons -1 days 0 hours -10 mins 0.000 secs |", - "| 0 years 0 mons 0 days 0 hours 0 mins -1.001 secs |", - "| 0 years 0 mons 0 days 0 hours 0 mins -0.001 secs |", - "| 0 years 0 mons 0 days 0 hours 0 mins 0.001 secs |", - "| 0 years 0 mons 0 days 0 hours 0 mins 0.010 secs |", - "| 0 years 0 mons 0 days 0 hours 0 mins 0.100 secs |", - "+----------------------------------------------------+", + "+-------------------+", + "| IntervalDayTime |", + "+-------------------+", + "| -1 days -10 mins |", + "| -1.001 secs |", + "| -0.001 secs |", + "| 0.001 secs |", + "| 0.010 secs |", + "| 0.100 secs |", + "+-------------------+", ]; let actual: Vec<&str> = table.lines().collect(); @@ -1032,23 +1032,23 @@ mod tests { let table = pretty_format_batches(&[batch]).unwrap().to_string(); let expected = vec![ - "+-----------------------------------------------------------+", - "| IntervalMonthDayNano |", - "+-----------------------------------------------------------+", - "| 0 years -1 mons -1 days 0 hours -10 mins 0.000000000 secs |", - "| 0 years 0 mons 0 days 0 hours 0 mins -1.000000001 secs |", - "| 0 years 0 mons 0 days 0 hours 0 mins -0.000000001 secs |", - "| 0 years 0 mons 0 days 0 hours 0 mins 0.000000001 secs |", - "| 0 years 0 mons 0 days 0 hours 0 mins 0.000000010 secs |", - "| 0 years 0 mons 0 days 0 hours 0 mins 0.000000100 secs |", - "| 0 years 0 mons 0 days 0 hours 0 mins 0.000001000 secs |", - "| 0 years 0 mons 0 days 0 hours 0 mins 0.000010000 secs |", - "| 0 years 0 mons 0 days 0 hours 0 mins 0.000100000 secs |", - "| 0 years 0 mons 0 days 0 hours 0 mins 0.001000000 secs |", - "| 0 years 0 mons 0 days 0 hours 0 mins 0.010000000 secs |", - "| 0 years 0 mons 0 days 0 hours 0 mins 0.100000000 secs |", - "| 0 years 0 mons 0 days 0 hours 0 mins 1.000000000 secs |", - "+-----------------------------------------------------------+", + "+---------------------------+", + "| IntervalMonthDayNano |", + "+---------------------------+", + "| -1 mons -1 days -10 mins |", + "| -1.000000001 secs |", + "| -0.000000001 secs |", + "| 0.000000001 secs |", + "| 0.000000010 secs |", + "| 0.000000100 secs |", + "| 0.000001000 secs |", + "| 0.000010000 secs |", + "| 0.000100000 secs |", + "| 0.001000000 secs |", + "| 0.010000000 secs |", + "| 0.100000000 secs |", + "| 1.000000000 secs |", + "+---------------------------+", ]; let actual: Vec<&str> = table.lines().collect(); From 55f64569d0afdb054cc2b9120bc4b723e58ae401 Mon Sep 17 00:00:00 2001 From: kamille Date: Fri, 5 Jul 2024 18:01:26 +0800 Subject: [PATCH 3/6] tmp --- arrow-cast/src/cast/mod.rs | 16 ++--- arrow-cast/src/display.rs | 124 ++++++++++++++++++++++++++++--------- 2 files changed, 102 insertions(+), 38 deletions(-) diff --git a/arrow-cast/src/cast/mod.rs b/arrow-cast/src/cast/mod.rs index c9de714e7d55..0d6e048563fc 100644 --- a/arrow-cast/src/cast/mod.rs +++ b/arrow-cast/src/cast/mod.rs @@ -4366,16 +4366,16 @@ mod tests { IntervalUnit::MonthDayNano, IntervalMonthDayNanoArray, vec![ - Some("0 years 13 mons 1 days 0 hours 0 mins 0.000000000 secs"), + Some("13 mons 1 days "), None, - Some("0 years 31 mons 35 days 0 hours 0 mins 0.001400000 secs"), - Some("0 years 0 mons 3 days 0 hours 0 mins 0.000000000 secs"), - Some("0 years 0 mons 0 days 0 hours 0 mins 8.000000000 secs"), + Some("31 mons 35 days 0.001400000 secs"), + Some("3 days "), + Some("8.000000000 secs"), None, - Some("0 years 0 mons 1 days 0 hours 0 mins 29.800000000 secs"), - Some("0 years 3 mons 0 days 0 hours 0 mins 1.000000000 secs"), - Some("0 years 0 mons 0 days 0 hours 8 mins 0.000000000 secs"), - Some("0 years 63 mons 9 days 19 hours 9 mins 2.222000000 secs"), + Some("1 days 29.800000000 secs"), + Some("3 mons 1.000000000 secs"), + Some("8 mins "), + Some("63 mons 9 days 19 hours 9 mins 2.222000000 secs"), None, ] ); diff --git a/arrow-cast/src/display.rs b/arrow-cast/src/display.rs index 0dcaafcf467d..f301393ca6ea 100644 --- a/arrow-cast/src/display.rs +++ b/arrow-cast/src/display.rs @@ -23,6 +23,7 @@ //! record batch pretty printing. //! //! [`pretty`]: crate::pretty +use std::f32::consts::E; use std::fmt::{Display, Formatter, Write}; use std::ops::Range; @@ -663,13 +664,19 @@ impl<'a> DisplayIndex for &'a PrimitiveArray { impl<'a> DisplayIndex for &'a PrimitiveArray { fn write(&self, idx: usize, f: &mut dyn Write) -> FormatResult { let value = self.value(idx); + let mut first_part = true; if value.days != 0 { - write!(f, "{} days ", value.days,)?; + write!(f, "{} days ", value.days)?; + first_part = false; } - + if value.milliseconds != 0 { - let millis_fmt = MillisecondsFormatter(value.milliseconds); + let millis_fmt = MillisecondsFormatter { + milliseconds:value.milliseconds, + first_part, + }; + f.write_fmt(format_args!("{millis_fmt}"))?; } @@ -680,17 +687,27 @@ impl<'a> DisplayIndex for &'a PrimitiveArray { impl<'a> DisplayIndex for &'a PrimitiveArray { fn write(&self, idx: usize, f: &mut dyn Write) -> FormatResult { let value = self.value(idx); + let mut first_part = true; if value.months != 0 { - write!(f, "{} mons ", value.months,)?; + write!(f, "{} mons ", value.months)?; + first_part = false; } if value.days != 0 { - write!(f, "{} days ", value.days,)?; + if first_part { + write!(f, "{} days ", value.days)?; + first_part = false; + } else { + write!(f, " {} days ", value.days)?; + } } if value.nanoseconds != 0 { - let nano_fmt = NanosecondsFormatter(value.nanoseconds); + let nano_fmt = NanosecondsFormatter { + nanoseconds: value.nanoseconds, + first_part, + }; f.write_fmt(format_args!("{nano_fmt}"))?; } @@ -698,61 +715,98 @@ impl<'a> DisplayIndex for &'a PrimitiveArray { } } -struct NanosecondsFormatter(i64); +struct NanosecondsFormatter { + nanoseconds: i64, + first_part: bool, +} impl Display for NanosecondsFormatter { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - let secs = self.0 / 1_000_000_000; + let secs = self.nanoseconds / 1_000_000_000; let mins = secs / 60; let hours = mins / 60; let secs = secs - (mins * 60); let mins = mins - (hours * 60); - let nanoseconds = self.0 % 1_000_000_000; + let nanoseconds = self.nanoseconds % 1_000_000_000; if hours != 0 { - write!(f, "{} hours ", hours,)?; + if self.first_part { + write!(f, "{} hours", hours)?; + self.first_part = false; + } else { + write!(f, " {} hours", hours)?; + } } if mins != 0 { - write!(f, "{} mins ", mins,)?; + if self.first_part { + write!(f, "{} mins", mins)?; + self.first_part = false; + } else { + write!(f, " {} mins", mins)?; + } } if secs != 0 || nanoseconds != 0 { let secs_sign = if secs < 0 || nanoseconds < 0 { "-" } else { "" }; - write!( - f, - "{}{}.{:09} secs", - secs_sign, - secs.abs(), - nanoseconds.abs() - )?; + + if self.first_part { + write!( + f, + "{}{}.{:09} secs", + secs_sign, + secs.abs(), + nanoseconds.abs() + )?; + } else { + write!( + f, + " {}{}.{:09} secs", + secs_sign, + secs.abs(), + nanoseconds.abs() + )?; + } } Ok(()) } } -struct MillisecondsFormatter(i32); +struct MillisecondsFormatter { + milliseconds: i32, + first_part: bool, +} impl Display for MillisecondsFormatter { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - let secs = self.0 / 1_000; + let secs = self.milliseconds / 1_000; let mins = secs / 60; let hours = mins / 60; let secs = secs - (mins * 60); let mins = mins - (hours * 60); - let milliseconds = self.0 % 1_000; + let milliseconds = self.milliseconds % 1_000; if hours != 0 { - write!(f, "{} hours ", hours,)?; + if self.first_part { + write!(f, "{} hours", hours,)?; + } else { + write!(f, " {} hours", hours,)?; + self.first_part = false; + } } if mins != 0 { - write!(f, "{} mins ", mins,)?; + if self.first_part { + write!(f, "{} mins", mins,)?; + } else { + write!(f, " {} mins", mins,)?; + self.first_part = false; + } } if secs != 0 || milliseconds != 0 { @@ -762,13 +816,23 @@ impl Display for MillisecondsFormatter { "" }; - write!( - f, - "{}{}.{:03} secs", - secs_sign, - secs.abs(), - milliseconds.abs() - )?; + if self.first_part { + write!( + f, + "{}{}.{:03} secs", + secs_sign, + secs.abs(), + milliseconds.abs() + )?; + } else { + write!( + f, + " {}{}.{:03} secs", + secs_sign, + secs.abs(), + milliseconds.abs() + )?; + } } Ok(()) From fc975d39d4ef3a1f62e3dfe057e19f7fceb8fe19 Mon Sep 17 00:00:00 2001 From: kamille Date: Fri, 5 Jul 2024 18:23:52 +0800 Subject: [PATCH 4/6] fix tests in arrow-cast. --- arrow-cast/src/cast/mod.rs | 18 +++++++++--------- arrow-cast/src/display.rs | 34 ++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/arrow-cast/src/cast/mod.rs b/arrow-cast/src/cast/mod.rs index 0d6e048563fc..e447c8854062 100644 --- a/arrow-cast/src/cast/mod.rs +++ b/arrow-cast/src/cast/mod.rs @@ -4314,8 +4314,8 @@ mod tests { IntervalUnit::YearMonth, IntervalYearMonthArray, vec![ - Some("1 years 1 mons 0 days 0 hours 0 mins 0.00 secs"), - Some("2 years 7 mons 0 days 0 hours 0 mins 0.00 secs"), + Some("1 years 1 mons"), + Some("2 years 7 mons"), None, None, None, @@ -4338,12 +4338,12 @@ mod tests { IntervalUnit::DayTime, IntervalDayTimeArray, vec![ - Some("0 years 0 mons 390 days 0 hours 0 mins 0.000 secs"), - Some("0 years 0 mons 930 days 0 hours 0 mins 0.000 secs"), - Some("0 years 0 mons 30 days 0 hours 0 mins 0.000 secs"), + Some("390 days"), + Some("930 days"), + Some("30 days"), None, None, - ] + ] ); } @@ -4366,15 +4366,15 @@ mod tests { IntervalUnit::MonthDayNano, IntervalMonthDayNanoArray, vec![ - Some("13 mons 1 days "), + Some("13 mons 1 days"), None, Some("31 mons 35 days 0.001400000 secs"), - Some("3 days "), + Some("3 days"), Some("8.000000000 secs"), None, Some("1 days 29.800000000 secs"), Some("3 mons 1.000000000 secs"), - Some("8 mins "), + Some("8 mins"), Some("63 mons 9 days 19 hours 9 mins 2.222000000 secs"), None, ] diff --git a/arrow-cast/src/display.rs b/arrow-cast/src/display.rs index f301393ca6ea..6eba3f9e5893 100644 --- a/arrow-cast/src/display.rs +++ b/arrow-cast/src/display.rs @@ -23,7 +23,6 @@ //! record batch pretty printing. //! //! [`pretty`]: crate::pretty -use std::f32::consts::E; use std::fmt::{Display, Formatter, Write}; use std::ops::Range; @@ -36,7 +35,6 @@ use arrow_buffer::ArrowNativeType; use arrow_schema::*; use chrono::{NaiveDate, NaiveDateTime, SecondsFormat, TimeZone, Utc}; use lexical_core::FormattedSize; -use num::Signed; type TimeFormat<'a> = Option<&'a str>; @@ -667,7 +665,7 @@ impl<'a> DisplayIndex for &'a PrimitiveArray { let mut first_part = true; if value.days != 0 { - write!(f, "{} days ", value.days)?; + write!(f, "{} days", value.days)?; first_part = false; } @@ -690,16 +688,16 @@ impl<'a> DisplayIndex for &'a PrimitiveArray { let mut first_part = true; if value.months != 0 { - write!(f, "{} mons ", value.months)?; + write!(f, "{} mons", value.months)?; first_part = false; } if value.days != 0 { if first_part { - write!(f, "{} days ", value.days)?; + write!(f, "{} days", value.days)?; first_part = false; } else { - write!(f, " {} days ", value.days)?; + write!(f, " {} days", value.days)?; } } @@ -722,6 +720,8 @@ struct NanosecondsFormatter { impl Display for NanosecondsFormatter { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let mut first_part = self.first_part; + let secs = self.nanoseconds / 1_000_000_000; let mins = secs / 60; let hours = mins / 60; @@ -732,18 +732,18 @@ impl Display for NanosecondsFormatter { let nanoseconds = self.nanoseconds % 1_000_000_000; if hours != 0 { - if self.first_part { + if first_part { write!(f, "{} hours", hours)?; - self.first_part = false; + first_part = false; } else { write!(f, " {} hours", hours)?; } } if mins != 0 { - if self.first_part { + if first_part { write!(f, "{} mins", mins)?; - self.first_part = false; + first_part = false; } else { write!(f, " {} mins", mins)?; } @@ -752,7 +752,7 @@ impl Display for NanosecondsFormatter { if secs != 0 || nanoseconds != 0 { let secs_sign = if secs < 0 || nanoseconds < 0 { "-" } else { "" }; - if self.first_part { + if first_part { write!( f, "{}{}.{:09} secs", @@ -782,6 +782,8 @@ struct MillisecondsFormatter { impl Display for MillisecondsFormatter { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let mut first_part = self.first_part; + let secs = self.milliseconds / 1_000; let mins = secs / 60; let hours = mins / 60; @@ -792,20 +794,20 @@ impl Display for MillisecondsFormatter { let milliseconds = self.milliseconds % 1_000; if hours != 0 { - if self.first_part { + if first_part { write!(f, "{} hours", hours,)?; + first_part = false; } else { write!(f, " {} hours", hours,)?; - self.first_part = false; } } if mins != 0 { - if self.first_part { + if first_part { write!(f, "{} mins", mins,)?; + first_part = false; } else { write!(f, " {} mins", mins,)?; - self.first_part = false; } } @@ -816,7 +818,7 @@ impl Display for MillisecondsFormatter { "" }; - if self.first_part { + if first_part { write!( f, "{}{}.{:03} secs", From fbcadfdbd169c13d15c63e92efb90e19d9fa7093 Mon Sep 17 00:00:00 2001 From: kamille Date: Fri, 5 Jul 2024 18:26:33 +0800 Subject: [PATCH 5/6] fix tests in pretty. --- arrow-cast/src/pretty.rs | 54 ++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/arrow-cast/src/pretty.rs b/arrow-cast/src/pretty.rs index 9c7a85eb1441..f41471e38d5e 100644 --- a/arrow-cast/src/pretty.rs +++ b/arrow-cast/src/pretty.rs @@ -986,16 +986,16 @@ mod tests { let table = pretty_format_batches(&[batch]).unwrap().to_string(); let expected = vec![ - "+-------------------+", - "| IntervalDayTime |", - "+-------------------+", - "| -1 days -10 mins |", - "| -1.001 secs |", - "| -0.001 secs |", - "| 0.001 secs |", - "| 0.010 secs |", - "| 0.100 secs |", - "+-------------------+", + "+------------------+", + "| IntervalDayTime |", + "+------------------+", + "| -1 days -10 mins |", + "| -1.001 secs |", + "| -0.001 secs |", + "| 0.001 secs |", + "| 0.010 secs |", + "| 0.100 secs |", + "+------------------+", ]; let actual: Vec<&str> = table.lines().collect(); @@ -1032,23 +1032,23 @@ mod tests { let table = pretty_format_batches(&[batch]).unwrap().to_string(); let expected = vec![ - "+---------------------------+", - "| IntervalMonthDayNano |", - "+---------------------------+", - "| -1 mons -1 days -10 mins |", - "| -1.000000001 secs |", - "| -0.000000001 secs |", - "| 0.000000001 secs |", - "| 0.000000010 secs |", - "| 0.000000100 secs |", - "| 0.000001000 secs |", - "| 0.000010000 secs |", - "| 0.000100000 secs |", - "| 0.001000000 secs |", - "| 0.010000000 secs |", - "| 0.100000000 secs |", - "| 1.000000000 secs |", - "+---------------------------+", + "+--------------------------+", + "| IntervalMonthDayNano |", + "+--------------------------+", + "| -1 mons -1 days -10 mins |", + "| -1.000000001 secs |", + "| -0.000000001 secs |", + "| 0.000000001 secs |", + "| 0.000000010 secs |", + "| 0.000000100 secs |", + "| 0.000001000 secs |", + "| 0.000010000 secs |", + "| 0.000100000 secs |", + "| 0.001000000 secs |", + "| 0.010000000 secs |", + "| 0.100000000 secs |", + "| 1.000000000 secs |", + "+--------------------------+", ]; let actual: Vec<&str> = table.lines().collect(); From 059def841983e949c1b7f6416182553b5b58e7fe Mon Sep 17 00:00:00 2001 From: kamille Date: Fri, 5 Jul 2024 18:27:06 +0800 Subject: [PATCH 6/6] fix style. --- arrow-cast/src/cast/mod.rs | 2 +- arrow-cast/src/display.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arrow-cast/src/cast/mod.rs b/arrow-cast/src/cast/mod.rs index e447c8854062..3f9c9c8a3356 100644 --- a/arrow-cast/src/cast/mod.rs +++ b/arrow-cast/src/cast/mod.rs @@ -4343,7 +4343,7 @@ mod tests { Some("30 days"), None, None, - ] + ] ); } diff --git a/arrow-cast/src/display.rs b/arrow-cast/src/display.rs index 6eba3f9e5893..ab172cb240cf 100644 --- a/arrow-cast/src/display.rs +++ b/arrow-cast/src/display.rs @@ -668,10 +668,10 @@ impl<'a> DisplayIndex for &'a PrimitiveArray { write!(f, "{} days", value.days)?; first_part = false; } - + if value.milliseconds != 0 { let millis_fmt = MillisecondsFormatter { - milliseconds:value.milliseconds, + milliseconds: value.milliseconds, first_part, }; @@ -715,7 +715,7 @@ impl<'a> DisplayIndex for &'a PrimitiveArray { struct NanosecondsFormatter { nanoseconds: i64, - first_part: bool, + first_part: bool, } impl Display for NanosecondsFormatter { @@ -777,7 +777,7 @@ impl Display for NanosecondsFormatter { struct MillisecondsFormatter { milliseconds: i32, - first_part: bool, + first_part: bool, } impl Display for MillisecondsFormatter {