Skip to content

Commit e2d8864

Browse files
committed
all util file
1 parent 5cf41fd commit e2d8864

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

src/util/mod.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
pub mod util;
2+
3+
use arrow::record_batch::RecordBatch;
4+
use arrow::datatypes::{DataType, Field, Schema, SchemaRef};
5+
use arrow::error::ArrowError;
6+
7+
pub fn record_batch_to_string(batch: &RecordBatch) -> Result<String, ArrowError> {
8+
let mut output = String::new();
9+
for row in 0..batch.num_rows() {
10+
for col in 0..batch.num_columns() {
11+
if col != 0 {
12+
output.push(' ');
13+
}
14+
let column = batch.column(col);
15+
16+
// NULL values are rendered as "NULL".
17+
if column.is_null(row) {
18+
output.push_str("NULL");
19+
continue;
20+
}
21+
let string = array_value_to_string(column, row)?;
22+
23+
// Empty strings are rendered as "(empty)".
24+
if *column.data_type() == DataType::Utf8 && string.is_empty() {
25+
output.push_str("(empty)");
26+
continue;
27+
}
28+
output.push_str(&string);
29+
}
30+
output.push('\n');
31+
}
32+
33+
Ok(output)
34+
}

0 commit comments

Comments
 (0)