You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/07/25 05:13:16 UTC

[GitHub] [arrow-rs] houqp commented on a change in pull request #579: support struct array in pretty display

houqp commented on a change in pull request #579:
URL: https://github.com/apache/arrow-rs/pull/579#discussion_r676085185



##########
File path: arrow/src/util/pretty.rs
##########
@@ -507,4 +507,63 @@ mod tests {
 
         Ok(())
     }
+
+    #[test]
+    fn test_pretty_format_struct() -> Result<()> {
+        let schema = Schema::new(vec![
+            Field::new(
+                "c1",
+                DataType::Struct(vec![
+                    Field::new("c11", DataType::Int32, false),
+                    Field::new(
+                        "c12",
+                        DataType::Struct(vec![Field::new("c121", DataType::Utf8, false)]),
+                        false,
+                    ),
+                ]),
+                false,
+            ),
+            Field::new("c2", DataType::Utf8, false),
+        ]);
+
+        let c1 = StructArray::from(vec![
+            (
+                Field::new("c11", DataType::Int32, false),
+                Arc::new(Int32Array::from(vec![Some(1), None, Some(5)])) as ArrayRef,
+            ),
+            (
+                Field::new(
+                    "c12",
+                    DataType::Struct(vec![Field::new("c121", DataType::Utf8, false)]),
+                    false,
+                ),
+                Arc::new(StructArray::from(vec![(
+                    Field::new("c121", DataType::Utf8, false),
+                    Arc::new(StringArray::from(vec![Some("e"), Some("f"), Some("g")]))
+                        as ArrayRef,
+                )])) as ArrayRef,
+            ),
+        ]);
+        let c2 = StringArray::from(vec![Some("a"), Some("b"), Some("c")]);
+
+        let batch =
+            RecordBatch::try_new(Arc::new(schema), vec![Arc::new(c1), Arc::new(c2)])
+                .unwrap();
+
+        let table = pretty_format_batches(&[batch])?;
+        let expected = vec![
+            r#"+-------------------------------------+----+"#,
+            r#"| c1                                  | c2 |"#,
+            r#"+-------------------------------------+----+"#,
+            r#"| {"c11": 1, "c12": {"c121": "e"}}    | a  |"#,
+            r#"| {"c11": null, "c12": {"c121": "f"}} | b  |"#,

Review comment:
       will send a follow up PR




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org