From 2e75e2207c1be787330f7f3769277f3338bb6c65 Mon Sep 17 00:00:00 2001 From: Marijn Valk Date: Sat, 11 Feb 2023 04:02:05 +0100 Subject: [PATCH] add test for null_count_schema_for_fields (#1135) # Description Adds a test for `null_count_schema_for_fields` # Related Issue(s) # Documentation --- rust/src/delta_arrow.rs | 55 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/rust/src/delta_arrow.rs b/rust/src/delta_arrow.rs index f158a7966f..1f667d33af 100644 --- a/rust/src/delta_arrow.rs +++ b/rust/src/delta_arrow.rs @@ -781,4 +781,59 @@ mod tests { assert_eq!(max_min_vec, expected); } + + #[test] + fn test_null_count_schema_for_fields() { + let mut null_count_vec: Vec = Vec::new(); + let fields = [ + ArrowField::new("int32", ArrowDataType::Int32, true), + ArrowField::new("int64", ArrowDataType::Int64, true), + ArrowField::new("Utf8", ArrowDataType::Utf8, true), + ArrowField::new( + "list", + ArrowDataType::List(Box::new(ArrowField::new( + "simple", + ArrowDataType::Int32, + true, + ))), + true, + ), + ArrowField::new( + "map", + ArrowDataType::Map( + Box::new(ArrowField::new( + "struct", + ArrowDataType::Struct(vec![ + ArrowField::new("key", ArrowDataType::Int32, true), + ArrowField::new("value", ArrowDataType::Int32, true), + ]), + true, + )), + true, + ), + true, + ), + ArrowField::new( + "struct", + ArrowDataType::Struct(vec![ArrowField::new("int32", ArrowDataType::Int32, true)]), + true, + ), + ]; + let expected = vec![ + ArrowField::new(fields[0].name(), ArrowDataType::Int64, true), + ArrowField::new(fields[1].name(), ArrowDataType::Int64, true), + ArrowField::new(fields[2].name(), ArrowDataType::Int64, true), + ArrowField::new(fields[3].name(), ArrowDataType::Int64, true), + ArrowField::new(fields[4].name(), ArrowDataType::Int64, true), + ArrowField::new( + fields[5].name(), + ArrowDataType::Struct(vec![ArrowField::new("int32", ArrowDataType::Int64, true)]), + true, + ), + ]; + fields + .iter() + .for_each(|f| null_count_schema_for_fields(&mut null_count_vec, f)); + assert_eq!(null_count_vec, expected); + } }