Skip to content

Commit

Permalink
Print the 'FixedSizeBinaryArray' like a normal 'BinaryArray' (#1097)
Browse files Browse the repository at this point in the history
* Print the 'FixedBinaryArray' like a normal 'BinaryArray'

* apply cargo fmt

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
  • Loading branch information
GrandChaman and alamb authored Dec 29, 2021
1 parent 78de3ab commit 74591a5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
3 changes: 3 additions & 0 deletions arrow/src/util/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ pub fn array_value_to_string(column: &array::ArrayRef, row: usize) -> Result<Str
DataType::LargeUtf8 => make_string!(array::LargeStringArray, column, row),
DataType::Binary => make_string_hex!(array::BinaryArray, column, row),
DataType::LargeBinary => make_string_hex!(array::LargeBinaryArray, column, row),
DataType::FixedSizeBinary(_) => {
make_string_hex!(array::FixedSizeBinaryArray, column, row)
}
DataType::Boolean => make_string!(array::BooleanArray, column, row),
DataType::Int8 => make_string!(array::Int8Array, column, row),
DataType::Int16 => make_string!(array::Int16Array, column, row),
Expand Down
42 changes: 38 additions & 4 deletions arrow/src/util/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ fn create_column(field: &str, columns: &[ArrayRef]) -> Result<Table> {
mod tests {
use crate::{
array::{
self, new_null_array, Array, Date32Array, Date64Array, PrimitiveBuilder,
StringArray, StringBuilder, StringDictionaryBuilder, StructArray,
Time32MillisecondArray, Time32SecondArray, Time64MicrosecondArray,
Time64NanosecondArray, TimestampMicrosecondArray, TimestampMillisecondArray,
self, new_null_array, Array, Date32Array, Date64Array,
FixedSizeBinaryBuilder, PrimitiveBuilder, StringArray, StringBuilder,
StringDictionaryBuilder, StructArray, Time32MillisecondArray,
Time32SecondArray, Time64MicrosecondArray, Time64NanosecondArray,
TimestampMicrosecondArray, TimestampMillisecondArray,
TimestampNanosecondArray, TimestampSecondArray,
},
datatypes::{DataType, Field, Int32Type, Schema},
Expand Down Expand Up @@ -308,6 +309,39 @@ mod tests {
Ok(())
}

#[test]
fn test_pretty_format_fixed_size_binary() -> Result<()> {
// define a schema.
let field_type = DataType::FixedSizeBinary(3);
let schema = Arc::new(Schema::new(vec![Field::new("d1", field_type, true)]));

let mut builder = FixedSizeBinaryBuilder::new(3, 3);

builder.append_value(&[1, 2, 3]).unwrap();
builder.append_null();
builder.append_value(&[7, 8, 9]).unwrap();

let array = Arc::new(builder.finish());

let batch = RecordBatch::try_new(schema, vec![array])?;
let table = pretty_format_batches(&[batch])?.to_string();
let expected = vec![
"+--------+",
"| d1 |",
"+--------+",
"| 010203 |",
"| |",
"| 070809 |",
"+--------+",
];

let actual: Vec<&str> = table.lines().collect();

assert_eq!(expected, actual, "Actual result:\n{}", table);

Ok(())
}

/// Generate an array with type $ARRAYTYPE with a numeric value of
/// $VALUE, and compare $EXPECTED_RESULT to the output of
/// formatting that array with `pretty_format_batches`
Expand Down

0 comments on commit 74591a5

Please sign in to comment.