diff --git a/arrow-cast/src/display.rs b/arrow-cast/src/display.rs index 669b8a664c2..3c61797c96d 100644 --- a/arrow-cast/src/display.rs +++ b/arrow-cast/src/display.rs @@ -72,6 +72,8 @@ pub struct FormatOptions<'a> { time_format: TimeFormat<'a>, /// Duration format duration_format: DurationFormat, + /// Show types in visual representation batches + types_info: bool, } impl Default for FormatOptions<'_> { @@ -92,6 +94,7 @@ impl<'a> FormatOptions<'a> { timestamp_tz_format: None, time_format: None, duration_format: DurationFormat::ISO8601, + types_info: false, } } @@ -158,6 +161,18 @@ impl<'a> FormatOptions<'a> { ..self } } + + /// Overrides if types should be shown + /// + /// Defaults to [`false`] + pub const fn with_types_info(self, types_info: bool) -> Self { + Self { types_info, ..self } + } + + /// Returns true if type info should be included in visual representation of batches + pub const fn types_info(&self) -> bool { + self.types_info + } } /// Implements [`Display`] for a specific array value diff --git a/arrow-cast/src/pretty.rs b/arrow-cast/src/pretty.rs index ad3b952c327..74d6d2475c9 100644 --- a/arrow-cast/src/pretty.rs +++ b/arrow-cast/src/pretty.rs @@ -88,7 +88,15 @@ fn create_table(results: &[RecordBatch], options: &FormatOptions) -> Result = column.lines().collect(); - assert_eq!(expected, actual, "Actual result:\n{column}"); + assert_eq!(expected_column, actual, "Actual result:\n{column}"); + + let batch = pretty_format_batches_with_options(&[batch], &options) + .unwrap() + .to_string(); + + let expected_table = vec![ + "+---------------+----------------+", + "| my_int32_name | my_string_name |", + "| Int32 | Utf8 |", + "+---------------+----------------+", + "| 1 | foo |", + "| 2 | bar |", + "| null | null |", + "| 3 | baz |", + "| 4 | null |", + "+---------------+----------------+", + ]; let actual: Vec<&str> = batch.lines().collect(); - assert_eq!(expected, actual, "Actual result:\n{batch}"); + assert_eq!(expected_table, actual, "Actual result:\n{batch}"); } }