Skip to content
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
86 changes: 82 additions & 4 deletions crates/iceberg/src/spec/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ pub(super) mod _serde {
use serde::{Deserialize, Serialize};

use super::{Operation, Snapshot, Summary};
use crate::Error;
use crate::spec::SchemaId;
use crate::spec::snapshot::SnapshotRowRange;
use crate::{Error, ErrorKind};

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
Expand Down Expand Up @@ -408,9 +408,19 @@ pub(super) mod _serde {
timestamp_ms: v1.timestamp_ms,
manifest_list: match (v1.manifest_list, v1.manifests) {
(Some(file), None) => file,
(Some(_), Some(_)) => "Invalid v1 snapshot, when manifest list provided, manifest files should be omitted".to_string(),
(None, _) => "Unsupported v1 snapshot, only manifest list is supported".to_string()
},
(Some(_), Some(_)) => {
return Err(Error::new(
ErrorKind::Unexpected,
Comment thread
Standing-Man marked this conversation as resolved.
Outdated
"v1 snapshot invariant violated: manifest_list and manifests are both set",
Comment thread
Standing-Man marked this conversation as resolved.
Outdated
));
}
(None, _) => {
return Err(Error::new(
ErrorKind::FeatureUnsupported,
Comment thread
Standing-Man marked this conversation as resolved.
Outdated
"v1 snapshot invariant violated: manifest_list is missing",
Comment thread
Standing-Man marked this conversation as resolved.
Outdated
));
}
},
summary: v1.summary.unwrap_or(Summary {
operation: Operation::default(),
additional_properties: HashMap::new(),
Expand Down Expand Up @@ -517,6 +527,7 @@ mod tests {

use chrono::{TimeZone, Utc};

use crate::spec::TableMetadata;
use crate::spec::snapshot::_serde::SnapshotV1;
use crate::spec::snapshot::{Operation, Snapshot, Summary};

Expand Down Expand Up @@ -604,6 +615,73 @@ mod tests {
);
}

#[test]
fn test_v1_snapshot_with_manifest_list_and_manifests() {
{
let metadata = r#"
{
"format-version": 1,
"table-uuid": "d20125c8-7284-442c-9aea-15fee620737c",
"location": "s3://bucket/test/location",
"last-updated-ms": 1700000000000,
"last-column-id": 1,
"schema": {
"type": "struct",
"fields": [
{"id": 1, "name": "x", "required": true, "type": "long"}
]
},
"partition-spec": [],
"properties": {},
"current-snapshot-id": 111111111,
"snapshots": [
{
"snapshot-id": 111111111,
"timestamp-ms": 1600000000000,
"summary": {"operation": "append"},
"manifest-list": "s3://bucket/metadata/snap-123.avro",
"manifests": ["s3://bucket/metadata/manifest-1.avro"]
}
]
}
"#;

let result = serde_json::from_str::<TableMetadata>(metadata);
assert!(result.is_err());
Comment thread
Standing-Man marked this conversation as resolved.
Outdated
}

{
let metadata = r#"
{
"format-version": 1,
"table-uuid": "d20125c8-7284-442c-9aea-15fee620737c",
"location": "s3://bucket/test/location",
"last-updated-ms": 1700000000000,
"last-column-id": 1,
"schema": {
"type": "struct",
"fields": [
{"id": 1, "name": "x", "required": true, "type": "long"}
]
},
"partition-spec": [],
"properties": {},
"current-snapshot-id": 111111111,
"snapshots": [
{
"snapshot-id": 111111111,
"timestamp-ms": 1600000000000,
"summary": {"operation": "append"},
"manifests": ["s3://bucket/metadata/manifest-1.avro"]
}
]
}
"#;
let result = serde_json::from_str::<TableMetadata>(metadata);
assert!(result.is_err());
Comment thread
Standing-Man marked this conversation as resolved.
Outdated
}
}

#[test]
fn test_snapshot_v1_to_v2_with_missing_summary() {
use crate::spec::snapshot::_serde::SnapshotV1;
Expand Down
Loading