Skip to content

Commit 9bd451b

Browse files
committed
fix: TableUpdate::AddSnapshot serialization with row lineage
1 parent a49cd9d commit 9bd451b

File tree

1 file changed

+55
-4
lines changed
  • crates/iceberg/src/catalog

1 file changed

+55
-4
lines changed

crates/iceberg/src/catalog/mod.rs

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,10 @@ pub(super) mod _serde {
796796
summary: Summary,
797797
#[serde(skip_serializing_if = "Option::is_none")]
798798
schema_id: Option<SchemaId>,
799+
#[serde(skip_serializing_if = "Option::is_none")]
800+
first_row_id: Option<u64>,
801+
#[serde(skip_serializing_if = "Option::is_none")]
802+
added_rows: Option<u64>,
799803
}
800804

801805
impl From<CatalogSnapshot> for Snapshot {
@@ -808,6 +812,8 @@ pub(super) mod _serde {
808812
manifest_list,
809813
schema_id,
810814
summary,
815+
first_row_id,
816+
added_rows,
811817
} = snapshot;
812818
let builder = Snapshot::builder()
813819
.with_snapshot_id(snapshot_id)
@@ -816,10 +822,17 @@ pub(super) mod _serde {
816822
.with_timestamp_ms(timestamp_ms)
817823
.with_manifest_list(manifest_list)
818824
.with_summary(summary);
819-
if let Some(schema_id) = schema_id {
820-
builder.with_schema_id(schema_id).build()
821-
} else {
822-
builder.build()
825+
let row_range = first_row_id.zip(added_rows);
826+
match (schema_id, row_range) {
827+
(None, None) => builder.build(),
828+
(Some(schema_id), None) => builder.with_schema_id(schema_id).build(),
829+
(None, Some((first_row_id, last_row_id))) => {
830+
builder.with_row_range(first_row_id, last_row_id).build()
831+
}
832+
(Some(schema_id), Some((first_row_id, last_row_id))) => builder
833+
.with_schema_id(schema_id)
834+
.with_row_range(first_row_id, last_row_id)
835+
.build(),
823836
}
824837
}
825838
}
@@ -1692,6 +1705,44 @@ mod tests {
16921705
assert_eq!(actual, update, "Parsed value is not equal to expected");
16931706
}
16941707

1708+
#[test]
1709+
fn test_add_snapshot_with_row_lineage() {
1710+
let json = r#"
1711+
{
1712+
"action": "add-snapshot",
1713+
"snapshot": {
1714+
"snapshot-id": 3055729675574597000,
1715+
"parent-snapshot-id": 3051729675574597000,
1716+
"timestamp-ms": 1555100955770,
1717+
"first-row-id":0,
1718+
"added-rows":2,
1719+
"summary": {
1720+
"operation": "append"
1721+
},
1722+
"manifest-list": "s3://a/b/2.avro"
1723+
}
1724+
}
1725+
"#;
1726+
1727+
let update = TableUpdate::AddSnapshot {
1728+
snapshot: Snapshot::builder()
1729+
.with_snapshot_id(3055729675574597000)
1730+
.with_parent_snapshot_id(Some(3051729675574597000))
1731+
.with_timestamp_ms(1555100955770)
1732+
.with_sequence_number(0)
1733+
.with_manifest_list("s3://a/b/2.avro")
1734+
.with_row_range(0, 2)
1735+
.with_summary(Summary {
1736+
operation: Operation::Append,
1737+
additional_properties: HashMap::default(),
1738+
})
1739+
.build(),
1740+
};
1741+
1742+
let actual: TableUpdate = serde_json::from_str(json).expect("Failed to parse from json");
1743+
assert_eq!(actual, update, "Parsed value is not equal to expected");
1744+
}
1745+
16951746
#[test]
16961747
fn test_remove_snapshots() {
16971748
let json = r#"

0 commit comments

Comments
 (0)