@@ -31,21 +31,84 @@ 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
+ /// ```
63
+
35
64
pub fn pretty_format_batches ( results : & [ RecordBatch ] ) -> Result < impl Display , ArrowError > {
36
65
let options = FormatOptions :: default ( ) . with_display_error ( true ) ;
37
66
pretty_format_batches_with_options ( results, & options)
38
67
}
39
68
40
- /// Create a visual representation of record batches
69
+ /// Create a visual representation of [`RecordBatch`]es with formatting options.
70
+ ///
71
+ /// # Arguments
72
+ /// * `results` - A slice of record batches to display
73
+ /// * `options` - [`FormatOptions`] that control the resulting display
74
+ ///
75
+ /// # Example
76
+ /// ```
77
+ /// # use std::sync::Arc;
78
+ /// # use arrow_array::{ArrayRef, Int32Array, RecordBatch, StringArray};
79
+ /// # use arrow_cast::display::FormatOptions;
80
+ /// # use arrow_cast::pretty::{pretty_format_batches, pretty_format_batches_with_options};
81
+ /// # let batch = RecordBatch::try_from_iter(vec![
82
+ /// # ("a", Arc::new(Int32Array::from(vec![1, 2])) as ArrayRef),
83
+ /// # ("b", Arc::new(StringArray::from(vec![Some("a"), None]))),
84
+ /// # ]).unwrap();
85
+ /// let options = FormatOptions::new()
86
+ /// .with_null("<NULL>");
87
+ /// // Note, returned object implements `Display`
88
+ /// let pretty_table = pretty_format_batches_with_options(&[batch], &options).unwrap();
89
+ /// let table_str = format!("Batches:\n{}", pretty_table);
90
+ /// assert_eq!(table_str,
91
+ /// r#"Batches:
92
+ /// +---+--------+
93
+ /// | a | b |
94
+ /// +---+--------+
95
+ /// | 1 | a |
96
+ /// | 2 | <NULL> |
97
+ /// +---+--------+"#);
98
+ /// ```
99
+
41
100
pub fn pretty_format_batches_with_options (
42
101
results : & [ RecordBatch ] ,
43
102
options : & FormatOptions ,
44
103
) -> Result < impl Display , ArrowError > {
45
104
create_table ( results, options)
46
105
}
47
106
48
- /// Create a visual representation of columns
107
+ /// Create a visual representation of [`ArrayRef`]
108
+ ///
109
+ /// Uses default values for display. See [`pretty_format_columns_with_options`]
110
+ ///
111
+ /// See [`pretty_format_batches`] for an example
49
112
pub fn pretty_format_columns (
50
113
col_name : & str ,
51
114
results : & [ ArrayRef ] ,
@@ -54,7 +117,10 @@ pub fn pretty_format_columns(
54
117
pretty_format_columns_with_options ( col_name, results, & options)
55
118
}
56
119
57
- /// Utility function to create a visual representation of columns with options
120
+ /// Create a visual representation of [`ArrayRef`] with formatting options.
121
+ ///
122
+ /// See [`pretty_format_batches_with_options`] for an example
123
+
58
124
fn pretty_format_columns_with_options (
59
125
col_name : & str ,
60
126
results : & [ ArrayRef ] ,
0 commit comments