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

feat: Implement TableRequirement checks #689

Merged
merged 4 commits into from
Nov 11, 2024

Conversation

c-thiel
Copy link
Collaborator

@c-thiel c-thiel commented Nov 7, 2024

No description provided.

@@ -312,29 +312,29 @@ pub enum TableRequirement {
LastAssignedFieldIdMatch {
/// The last assigned field id of the table to assert.
#[serde(rename = "last-assigned-field-id")]
last_assigned_field_id: i64,
last_assigned_field_id: i32,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Introduced type changes to match TableMetadata and TableUpdate

Copy link
Contributor

@liurenjie1024 liurenjie1024 left a comment

Choose a reason for hiding this comment

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

Thanks @c-thiel for this pr! Left some minor points to discuss, others look great!

},
/// The table's current schema id must match the requirement.
#[serde(rename = "assert-current-schema-id")]
CurrentSchemaIdMatch {
/// Current schema id of the table to assert.
#[serde(rename = "current-schema-id")]
current_schema_id: i64,
current_schema_id: i32,
Copy link
Contributor

Choose a reason for hiding this comment

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

Use SchemaId here?

@@ -44,6 +44,8 @@ pub enum ErrorKind {
///
/// This error is returned when given iceberg feature is not supported.
FeatureUnsupported,
/// A requirement check failed.
RequirementFailed,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we actually add this? I think DataInvalid would be enough? We should be cautious when adding new error kind, if user can't take different actions from existing error kind. cc @Xuanwo

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Java is a bit more detailed here. I am also fine with keeping DataInvalid, but would in that case add in the message that the data is actually not invalid, but just the requirement not met.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed it in the latest commit, let me know what you think!

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks !

impl TableRequirement {
/// Check that the requirement is met by the table metadata.
/// If the requirement is not met, an appropriate error is returned.
pub fn check(&self, metadata: &TableMetadata, exists: bool) -> Result<()> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub fn check(&self, metadata: &TableMetadata, exists: bool) -> Result<()> {
pub fn check(&self, metadata: Option<&TableMetadata>) -> Result<()> {

How about use Option here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are right, this is better.
My motivation was that the Option approach is not able to combine any other Requirement with the TableDoesNotExist Requirement. Paradoxically tables can actually NotExist even if Metadata is available: The staged-create create table does exactly this - prepare metadata while the table technically doesn't exist yet.

However, I checked Java, and it doesn't allow the combination in question, so we don't need to prepare for it.
https://github.com/apache/iceberg/blob/fff9ec3bbc322080da6363b657415b039c0e92a0/core/src/main/java/org/apache/iceberg/rest/CatalogHandlers.java#L361C1-L376C4

crates/iceberg/src/catalog/mod.rs Outdated Show resolved Hide resolved
"Current schema id does not match",
)
.with_context("expected", current_schema_id.to_string())
.with_context("found", metadata.current_schema_id.to_string()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ditto ;)

ErrorKind::RequirementFailed,
"Default sort order id does not match",
)
.with_context("expected", default_sort_order_id.to_string())
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ditto ;)

"Default sort order id does not match",
)
.with_context("expected", default_sort_order_id.to_string())
.with_context("found", metadata.default_sort_order().order_id.to_string()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ditto ;)

if snapshot_ref.snapshot_id() != *snapshot_id {
return Err(Error::new(
ErrorKind::RequirementFailed,
format!("Branch or tag `{}` has changed", r#ref),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
format!("Branch or tag `{}` has changed", r#ref),
format!("Branch or tag `{}`'s snapshot has changed", r#ref),

@c-thiel
Copy link
Collaborator Author

c-thiel commented Nov 8, 2024

@liurenjie1024 ready for another round!

Copy link
Contributor

@liurenjie1024 liurenjie1024 left a comment

Choose a reason for hiding this comment

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

Thanks @c-thiel for this pr, LGTM!

@liurenjie1024 liurenjie1024 merged commit 52296eb into apache:main Nov 11, 2024
16 checks passed
ZENOTME pushed a commit to risingwavelabs/iceberg-rust that referenced this pull request Nov 15, 2024
* Impelment TableRequirement check

* Address comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants