You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2021/12/29 19:50:45 UTC

[arrow-rs] branch master updated: Print the 'FixedSizeBinaryArray' like a normal 'BinaryArray' (#1097)

This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new 74591a5  Print the 'FixedSizeBinaryArray' like a normal 'BinaryArray' (#1097)
74591a5 is described below

commit 74591a5c96042e5d6dde7e015decb7358bfc33a0
Author: Francis Le Roy <36...@users.noreply.github.com>
AuthorDate: Wed Dec 29 20:50:40 2021 +0100

    Print the 'FixedSizeBinaryArray' like a normal 'BinaryArray' (#1097)
    
    * Print the 'FixedBinaryArray' like a normal 'BinaryArray'
    
    * apply cargo fmt
    
    Co-authored-by: Andrew Lamb <an...@nerdnetworks.org>
---
 arrow/src/util/display.rs |  3 +++
 arrow/src/util/pretty.rs  | 42 ++++++++++++++++++++++++++++++++++++++----
 2 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/arrow/src/util/display.rs b/arrow/src/util/display.rs
index e427dcc..91f64db 100644
--- a/arrow/src/util/display.rs
+++ b/arrow/src/util/display.rs
@@ -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),
diff --git a/arrow/src/util/pretty.rs b/arrow/src/util/pretty.rs
index ac7caa8..44fe050 100644
--- a/arrow/src/util/pretty.rs
+++ b/arrow/src/util/pretty.rs
@@ -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},
@@ -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`