Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for min_max_schema_for_fields #1122

Merged
merged 2 commits into from
Feb 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions rust/src/delta_arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArrowField> = 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<ArrowField> = 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,
)];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have to repeat this, and it's probably clearer they are meant to be the same field if we just clone f. Same applies for test above.

Suggested change
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,
)];
let f = ArrowField::new(
"struct",
ArrowDataType::Struct(vec![ArrowField::new("simple", ArrowDataType::Int32, true)]),
true,
);
let expected = vec![f.clone()];

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<ArrowField> = 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<ArrowField> = Vec::new();
max_min_schema_for_fields(&mut dest, &f1);
max_min_schema_for_fields(&mut dest, &f2);
assert_eq!(dest, expected)
}
}