@@ -31,21 +31,82 @@ use arrow_schema::ArrowError;
3131
3232use crate :: display:: { ArrayFormatter , FormatOptions } ;
3333
34- /// Create a visual representation of record batches
34+ /// Create a visual representation of [`RecordBatch`]es
35+ ///
36+ /// Uses default values for display. See [`pretty_format_batches_with_options`]
37+ /// for more control.
38+ ///
39+ /// # Example
40+ /// ```
41+ /// # use std::sync::Arc;
42+ /// # use arrow_array::{ArrayRef, Int32Array, RecordBatch, StringArray};
43+ /// # use arrow_cast::pretty::pretty_format_batches;
44+ /// # let batch = RecordBatch::try_from_iter(vec![
45+ /// # ("a", Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5])) as ArrayRef),
46+ /// # ("b", Arc::new(StringArray::from(vec![Some("a"), Some("b"), None, Some("d"), Some("e")]))),
47+ /// # ]).unwrap();
48+ /// // Note, returned object implements `Display`
49+ /// let pretty_table = pretty_format_batches(&[batch]).unwrap();
50+ /// let table_str = format!("Batches:\n{}", pretty_table);
51+ /// assert_eq!(table_str,
52+ /// r#"Batches:
53+ /// +---+---+
54+ /// | a | b |
55+ /// +---+---+
56+ /// | 1 | a |
57+ /// | 2 | b |
58+ /// | 3 | |
59+ /// | 4 | d |
60+ /// | 5 | e |
61+ /// +---+---+"#);
62+ /// ```
3563pub fn pretty_format_batches ( results : & [ RecordBatch ] ) -> Result < impl Display , ArrowError > {
3664 let options = FormatOptions :: default ( ) . with_display_error ( true ) ;
3765 pretty_format_batches_with_options ( results, & options)
3866}
3967
40- /// Create a visual representation of record batches
68+ /// Create a visual representation of [`RecordBatch`]es with formatting options.
69+ ///
70+ /// # Arguments
71+ /// * `results` - A slice of record batches to display
72+ /// * `options` - [`FormatOptions`] that control the resulting display
73+ ///
74+ /// # Example
75+ /// ```
76+ /// # use std::sync::Arc;
77+ /// # use arrow_array::{ArrayRef, Int32Array, RecordBatch, StringArray};
78+ /// # use arrow_cast::display::FormatOptions;
79+ /// # use arrow_cast::pretty::{pretty_format_batches, pretty_format_batches_with_options};
80+ /// # let batch = RecordBatch::try_from_iter(vec![
81+ /// # ("a", Arc::new(Int32Array::from(vec![1, 2])) as ArrayRef),
82+ /// # ("b", Arc::new(StringArray::from(vec![Some("a"), None]))),
83+ /// # ]).unwrap();
84+ /// let options = FormatOptions::new()
85+ /// .with_null("<NULL>");
86+ /// // Note, returned object implements `Display`
87+ /// let pretty_table = pretty_format_batches_with_options(&[batch], &options).unwrap();
88+ /// let table_str = format!("Batches:\n{}", pretty_table);
89+ /// assert_eq!(table_str,
90+ /// r#"Batches:
91+ /// +---+--------+
92+ /// | a | b |
93+ /// +---+--------+
94+ /// | 1 | a |
95+ /// | 2 | <NULL> |
96+ /// +---+--------+"#);
97+ /// ```
4198pub fn pretty_format_batches_with_options (
4299 results : & [ RecordBatch ] ,
43100 options : & FormatOptions ,
44101) -> Result < impl Display , ArrowError > {
45102 create_table ( results, options)
46103}
47104
48- /// Create a visual representation of columns
105+ /// Create a visual representation of [`ArrayRef`]
106+ ///
107+ /// Uses default values for display. See [`pretty_format_columns_with_options`]
108+ ///
109+ /// See [`pretty_format_batches`] for an example
49110pub fn pretty_format_columns (
50111 col_name : & str ,
51112 results : & [ ArrayRef ] ,
@@ -54,7 +115,9 @@ pub fn pretty_format_columns(
54115 pretty_format_columns_with_options ( col_name, results, & options)
55116}
56117
57- /// Utility function to create a visual representation of columns with options
118+ /// Create a visual representation of [`ArrayRef`] with formatting options.
119+ ///
120+ /// See [`pretty_format_batches_with_options`] for an example
58121fn pretty_format_columns_with_options (
59122 col_name : & str ,
60123 results : & [ ArrayRef ] ,
0 commit comments