@@ -31,21 +31,82 @@ use arrow_schema::ArrowError;
31
31
32
32
use crate :: display:: { ArrayFormatter , FormatOptions } ;
33
33
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
+ /// ```
35
63
pub fn pretty_format_batches ( results : & [ RecordBatch ] ) -> Result < impl Display , ArrowError > {
36
64
let options = FormatOptions :: default ( ) . with_display_error ( true ) ;
37
65
pretty_format_batches_with_options ( results, & options)
38
66
}
39
67
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
+ /// ```
41
98
pub fn pretty_format_batches_with_options (
42
99
results : & [ RecordBatch ] ,
43
100
options : & FormatOptions ,
44
101
) -> Result < impl Display , ArrowError > {
45
102
create_table ( results, options)
46
103
}
47
104
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
49
110
pub fn pretty_format_columns (
50
111
col_name : & str ,
51
112
results : & [ ArrayRef ] ,
@@ -54,7 +115,9 @@ pub fn pretty_format_columns(
54
115
pretty_format_columns_with_options ( col_name, results, & options)
55
116
}
56
117
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
58
121
fn pretty_format_columns_with_options (
59
122
col_name : & str ,
60
123
results : & [ ArrayRef ] ,
0 commit comments