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 extract_partition_values #1159

Merged
merged 1 commit into from
Feb 22, 2023
Merged
Changes from all commits
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
45 changes: 44 additions & 1 deletion rust/src/writer/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,15 @@ fn extract_partition_values(

#[cfg(test)]
mod tests {
use super::*;
use crate::arrow::array::Int32Array;
use crate::arrow::datatypes::{
DataType as ArrowDataType, Field as ArrowField, Schema as ArrowSchema,
};
use crate::writer::test_utils::get_delta_schema;
use crate::writer::DeltaWriter;
use crate::writer::JsonWriter;
use crate::Schema;
use arrow::datatypes::Schema as ArrowSchema;
use parquet::file::reader::FileReader;
use parquet::file::serialized_reader::SerializedFileReader;
use std::fs::File;
Expand Down Expand Up @@ -488,4 +492,43 @@ mod tests {
.collect::<Vec<String>>();
assert_eq!(columns, vec!["id".to_string(), "value".to_string()]);
}

#[test]
fn test_extract_partition_values() {
let record_batch = RecordBatch::try_new(
Arc::new(ArrowSchema::new(vec![
ArrowField::new("col1", ArrowDataType::Int32, false),
ArrowField::new("col2", ArrowDataType::Int32, false),
ArrowField::new("col3", ArrowDataType::Int32, true),
])),
vec![
Arc::new(Int32Array::from(vec![1, 2])),
Arc::new(Int32Array::from(vec![2, 1])),
Arc::new(Int32Array::from(vec![None, None])),
],
)
.unwrap();

assert_eq!(
extract_partition_values(
&[
String::from("col1"),
String::from("col2"),
String::from("col3")
],
&record_batch
)
.unwrap(),
HashMap::from([
(String::from("col1"), Some(String::from("1"))),
(String::from("col2"), Some(String::from("2"))),
(String::from("col3"), None),
])
);
assert_eq!(
extract_partition_values(&[String::from("col1")], &record_batch).unwrap(),
HashMap::from([(String::from("col1"), Some(String::from("1"))),])
);
assert!(extract_partition_values(&[String::from("col4")], &record_batch).is_err())
}
}