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

fix: default_partition_spec using the partion_spec_id set #190

Merged
merged 2 commits into from
Feb 6, 2024
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
40 changes: 38 additions & 2 deletions crates/iceberg/src/spec/table_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl TableMetadata {
self.partition_spec_by_id(DEFAULT_SPEC_ID)
} else {
Some(
self.partition_spec_by_id(DEFAULT_SPEC_ID)
self.partition_spec_by_id(self.default_spec_id)
.expect("Default partition spec id set, but not found in table metadata"),
)
}
Expand Down Expand Up @@ -856,6 +856,13 @@ mod tests {
assert_eq!(parsed_json_value, desered_type);
}

fn get_test_table_metadata(file_name: &str) -> TableMetadata {
let path = format!("testdata/table_metadata/{}", file_name);
let metadata: String = fs::read_to_string(path).unwrap();

serde_json::from_str(&metadata).unwrap()
}

#[test]
fn test_table_data_v2() {
let data = r#"
Expand Down Expand Up @@ -1529,9 +1536,38 @@ mod tests {
}

#[test]
fn order_of_format_version() {
fn test_order_of_format_version() {
assert!(FormatVersion::V1 < FormatVersion::V2);
assert_eq!(FormatVersion::V1, FormatVersion::V1);
assert_eq!(FormatVersion::V2, FormatVersion::V2);
}

#[test]
fn test_default_partition_spec() {
let default_spec_id = 1234;
let mut table_meta_data = get_test_table_metadata("TableMetadataV2Valid.json");
table_meta_data.default_spec_id = default_spec_id;
table_meta_data
.partition_specs
.insert(default_spec_id, Arc::new(PartitionSpec::default()));

assert_eq!(
table_meta_data.default_partition_spec(),
table_meta_data.partition_spec_by_id(default_spec_id)
);
}
#[test]
fn test_default_sort_order() {
let default_sort_order_id = 1234;
let mut table_meta_data = get_test_table_metadata("TableMetadataV2Valid.json");
table_meta_data.default_sort_order_id = default_sort_order_id;
table_meta_data
.sort_orders
.insert(default_sort_order_id, Arc::new(SortOrder::default()));

assert_eq!(
table_meta_data.default_sort_order(),
table_meta_data.sort_orders.get(&default_sort_order_id)
)
}
}
Loading