Skip to content
Closed
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
53 changes: 34 additions & 19 deletions iceberg-rust/src/view/transaction/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,17 @@ impl Operation {
schema,
branch,
} => {
let schema_changed = metadata.current_schema(branch.as_deref())
.map(|s| schema != *s.fields())
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In theory identifier_field_ids can change while the fields remain the same, so we should also test for that when deducing a schema change?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

In theory you're right, but looks like iceberg-rs doesn't support changing identifier_field_ids, so identifier_field_ids are not even represented in variant Operation::UpdateRepresentation

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Oh I see; then no need to test it now.

.unwrap_or(true);

let version = metadata.current_version(branch.as_deref())?;
let version_id = metadata.versions.keys().max().unwrap_or(&0) + 1;
let schema_id = metadata.schemas.keys().max().unwrap_or(&0) + 1;
let schema_id = if schema_changed {
metadata.schemas.keys().max().unwrap_or(&0) + 1
} else {
*metadata.current_schema(branch.as_deref()).unwrap().schema_id()
};
let last_column_id = schema.iter().map(|x| x.id).max().unwrap_or(0);

let version = Version {
Expand All @@ -72,28 +80,35 @@ impl Operation {

let branch_name = branch.unwrap_or("main".to_string());

let mut view_updates: Vec<ViewUpdate<T>> = if schema_changed {
vec![ViewUpdate::AddSchema {
schema: Schema::from_struct_type(schema, schema_id, None),
last_column_id: Some(last_column_id),
}]
} else {
vec![]
};

view_updates.append(&mut vec![
ViewUpdate::AddViewVersion {
view_version: version,
},
ViewUpdate::SetCurrentViewVersion {
view_version_id: version_id,
},
ViewUpdate::SetProperties {
updates: HashMap::from_iter(vec![(
REF_PREFIX.to_string() + &branch_name,
version_id.to_string(),
)]),
},
]);

Ok((
Some(ViewRequirement::AssertViewUuid {
uuid: metadata.view_uuid,
}),
vec![
ViewUpdate::AddViewVersion {
view_version: version,
},
ViewUpdate::SetCurrentViewVersion {
view_version_id: version_id,
},
ViewUpdate::AddSchema {
schema: Schema::from_struct_type(schema, schema_id, None),
last_column_id: Some(last_column_id),
},
ViewUpdate::SetProperties {
updates: HashMap::from_iter(vec![(
REF_PREFIX.to_string() + &branch_name,
version_id.to_string(),
)]),
},
],
view_updates,
))
}
Operation::UpdateProperties(entries) => Ok((
Expand Down