From 76c3b4db61745e93156ccbb3e94540bd1a03c42c Mon Sep 17 00:00:00 2001 From: Marijn Valk Date: Sun, 5 Feb 2023 12:20:33 +0100 Subject: [PATCH 1/2] add test for min_max_schema_for_fields Signed-off-by: Marijn Valk --- rust/src/delta_arrow.rs | 59 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/rust/src/delta_arrow.rs b/rust/src/delta_arrow.rs index fbb0bda033..b2d06458f3 100644 --- a/rust/src/delta_arrow.rs +++ b/rust/src/delta_arrow.rs @@ -732,4 +732,63 @@ mod tests { crate::SchemaDataType::primitive("timestamp".to_string()) ); } + + #[test] + fn test_max_min_schema_for_fields_simple_type() { + let mut dest: Vec = Vec::new(); + let f = ArrowField::new("simple", ArrowDataType::Int32, true); + let expected = vec![ArrowField::new("simple", ArrowDataType::Int32, true)]; + max_min_schema_for_fields(&mut dest, &f); + assert_eq!(dest, expected) + } + + #[test] + fn test_max_min_schema_for_fields_struct_type() { + let mut dest: Vec = Vec::new(); + let f = ArrowField::new( + "struct", + ArrowDataType::Struct(vec![ArrowField::new("simple", ArrowDataType::Int32, true)]), + true, + ); + let expected = vec![ArrowField::new( + "struct", + ArrowDataType::Struct(vec![ArrowField::new("simple", ArrowDataType::Int32, true)]), + true, + )]; + max_min_schema_for_fields(&mut dest, &f); + assert_eq!(dest, expected) + } + + #[test] + fn test_max_min_schema_for_fields_list_and_map_type() { + let mut dest: Vec = Vec::new(); + let f1 = ArrowField::new( + "list", + ArrowDataType::List(Box::new(ArrowField::new( + "simple", + ArrowDataType::Int32, + true, + ))), + true, + ); + let f2 = 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, + ); + let expected: Vec = Vec::new(); + max_min_schema_for_fields(&mut dest, &f1); + max_min_schema_for_fields(&mut dest, &f2); + assert_eq!(dest, expected) + } } From ba7f6cbf071370e44782eaa85dfa7322d08d9c4e Mon Sep 17 00:00:00 2001 From: Marijn Valk Date: Mon, 6 Feb 2023 08:17:12 +0100 Subject: [PATCH 2/2] combine tests into 1 Signed-off-by: Marijn Valk --- rust/src/delta_arrow.rs | 90 +++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 52 deletions(-) diff --git a/rust/src/delta_arrow.rs b/rust/src/delta_arrow.rs index b2d06458f3..dac75449f8 100644 --- a/rust/src/delta_arrow.rs +++ b/rust/src/delta_arrow.rs @@ -734,61 +734,47 @@ mod tests { } #[test] - fn test_max_min_schema_for_fields_simple_type() { - let mut dest: Vec = Vec::new(); - let f = ArrowField::new("simple", ArrowDataType::Int32, true); - let expected = vec![ArrowField::new("simple", ArrowDataType::Int32, true)]; - max_min_schema_for_fields(&mut dest, &f); - assert_eq!(dest, expected) - } - - #[test] - fn test_max_min_schema_for_fields_struct_type() { - let mut dest: Vec = Vec::new(); - let f = ArrowField::new( - "struct", - ArrowDataType::Struct(vec![ArrowField::new("simple", ArrowDataType::Int32, true)]), - true, - ); - let expected = vec![ArrowField::new( - "struct", - ArrowDataType::Struct(vec![ArrowField::new("simple", ArrowDataType::Int32, true)]), - true, - )]; - max_min_schema_for_fields(&mut dest, &f); - assert_eq!(dest, expected) - } - - #[test] - fn test_max_min_schema_for_fields_list_and_map_type() { - let mut dest: Vec = Vec::new(); - let f1 = ArrowField::new( - "list", - ArrowDataType::List(Box::new(ArrowField::new( - "simple", - ArrowDataType::Int32, + fn test_max_min_schema_for_fields() { + let mut max_min_vec: Vec = Vec::new(); + let fields = [ + ArrowField::new("simple", ArrowDataType::Int32, true), + ArrowField::new( + "struct", + ArrowDataType::Struct(vec![ArrowField::new("simple", ArrowDataType::Int32, true)]), true, - ))), - true, - ); - let f2 = 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), - ]), + ), + ArrowField::new( + "list", + ArrowDataType::List(Box::new(ArrowField::new( + "simple", + ArrowDataType::Int32, true, - )), + ))), true, ), - true, - ); - let expected: Vec = Vec::new(); - max_min_schema_for_fields(&mut dest, &f1); - max_min_schema_for_fields(&mut dest, &f2); - assert_eq!(dest, expected) + 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, + ), + ]; + + let expected = vec![fields[0].clone(), fields[1].clone()]; + + fields + .iter() + .for_each(|f| max_min_schema_for_fields(&mut max_min_vec, f)); + + assert_eq!(max_min_vec, expected); } }