Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
c-thiel committed Aug 26, 2024
1 parent 905ebd2 commit 1cc2304
Show file tree
Hide file tree
Showing 5 changed files with 365 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crates/iceberg/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ pub enum ErrorKind {
///
/// This error is returned when given iceberg feature is not supported.
FeatureUnsupported,
/// Validation failed.
///
/// This error is returned when Table or View Metadata is manipulated
/// in non-allowed ways.
ValidationFailed,
}

impl ErrorKind {
Expand All @@ -59,6 +64,7 @@ impl From<ErrorKind> for &'static str {
ErrorKind::Unexpected => "Unexpected",
ErrorKind::DataInvalid => "DataInvalid",
ErrorKind::FeatureUnsupported => "FeatureUnsupported",
ErrorKind::ValidationFailed => "ValidationFailed",
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/iceberg/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mod schema;
mod snapshot;
mod sort;
mod table_metadata;
mod table_metadata_builder;
mod transform;
mod values;
mod view_metadata;
Expand Down
13 changes: 13 additions & 0 deletions crates/iceberg/src/spec/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,19 @@ impl Schema {
pub fn accessor_by_field_id(&self, field_id: i32) -> Option<Arc<StructAccessor>> {
self.field_id_to_accessor.get(&field_id).cloned()
}

/// Check if this schema is identical to another schema semantically - excluding schema id.
pub fn is_same_schema(&self, other: &SchemaRef) -> bool {
self.as_struct().eq(other.as_struct())
&& self.identifier_field_ids().eq(other.identifier_field_ids())
}

/// Change the schema id of this schema.
// This is redundant with the `with_schema_id` method on the builder, but useful
// as it is infallible in contrast to the builder `build()` method.
pub(crate) fn with_schema_id(self, schema_id: SchemaId) -> Self {
Self { schema_id, ..self }
}
}

impl Display for Schema {
Expand Down
7 changes: 7 additions & 0 deletions crates/iceberg/src/spec/table_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ pub struct TableMetadata {
}

impl TableMetadata {
/// Convert this Table Metadata into a builder for modification
#[must_use]
pub fn into_builder(self) -> super::table_metadata_builder::TableMetadataBuilder {
super::table_metadata_builder::TableMetadataBuilder::new_from_metadata(self)
}

/// Returns format version of this metadata.
#[inline]
pub fn format_version(&self) -> FormatVersion {
Expand Down Expand Up @@ -258,6 +264,7 @@ impl TableMetadata {

/// Append snapshot to table
pub fn append_snapshot(&mut self, snapshot: Snapshot) {
// ToDo: Fix - support more branches? Required if we have the new builder?
self.last_updated_ms = snapshot.timestamp().timestamp_millis();
self.last_sequence_number = snapshot.sequence_number();

Expand Down
Loading

0 comments on commit 1cc2304

Please # to comment.