jorgecarleitao commented on a change in pull request #579:
URL: https://github.com/apache/arrow-rs/pull/579#discussion_r676031934
##########
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:
it could have been useful to have a struct with a validity tested, to
make sure we do not miss that case.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]