Struct iceberg::spec::TableMetadataBuilder
source · pub struct TableMetadataBuilder { /* private fields */ }
Expand description
Manipulating table metadata.
For this builder the order of called functions matters. Functions are applied in-order.
All operations applied to the TableMetadata
are tracked in changes
as a chronologically
ordered vec of TableUpdate
.
If an operation does not lead to a change of the TableMetadata
, the corresponding update
is omitted from changes
.
Unlike a typical builder pattern, the order of function calls matters. Some basic rules:
add_schema
must be called beforeset_current_schema
.- If a new partition spec and schema are added, the schema should be added first.
Implementations§
source§impl TableMetadataBuilder
impl TableMetadataBuilder
sourcepub const LAST_ADDED: i32 = -1i32
pub const LAST_ADDED: i32 = -1i32
Proxy id for “last added” items, including schema, partition spec, sort order.
sourcepub fn new(
schema: Schema,
spec: impl Into<UnboundPartitionSpec>,
sort_order: SortOrder,
location: String,
format_version: FormatVersion,
properties: HashMap<String, String>,
) -> Result<Self>
pub fn new( schema: Schema, spec: impl Into<UnboundPartitionSpec>, sort_order: SortOrder, location: String, format_version: FormatVersion, properties: HashMap<String, String>, ) -> Result<Self>
Create a TableMetadata
object from scratch.
This method re-assign ids of fields in the schema, schema.id, sort_order.id and spec.id. It should only be used to create new table metadata from scratch.
sourcepub fn new_from_metadata(
previous: TableMetadata,
previous_file_location: Option<String>,
) -> Self
pub fn new_from_metadata( previous: TableMetadata, previous_file_location: Option<String>, ) -> Self
Creates a new table metadata builder from the given metadata to modify it.
current_file_location
is the location where the current version
of the metadata file is stored. This is used to update the metadata log.
If current_file_location
is None
, the metadata log will not be updated.
This should only be used to stage-create tables.
sourcepub fn from_table_creation(table_creation: TableCreation) -> Result<Self>
pub fn from_table_creation(table_creation: TableCreation) -> Result<Self>
Creates a new table metadata builder from the given table creation.
sourcepub fn assign_uuid(self, uuid: Uuid) -> Self
pub fn assign_uuid(self, uuid: Uuid) -> Self
Changes uuid of table metadata.
sourcepub fn upgrade_format_version(
self,
format_version: FormatVersion,
) -> Result<Self>
pub fn upgrade_format_version( self, format_version: FormatVersion, ) -> Result<Self>
Upgrade FormatVersion
. Downgrades are not allowed.
§Errors
- Cannot downgrade to older format versions.
sourcepub fn set_properties(self, properties: HashMap<String, String>) -> Result<Self>
pub fn set_properties(self, properties: HashMap<String, String>) -> Result<Self>
Set properties. If a property already exists, it will be overwritten.
If a reserved property is set, the corresponding action is performed and the property is not persisted. Currently the following reserved properties are supported:
- format-version: Set the format version of the table.
§Errors
- If properties contains a reserved property
sourcepub fn remove_properties(self, properties: &[String]) -> Result<Self>
pub fn remove_properties(self, properties: &[String]) -> Result<Self>
Remove properties from the table metadata. Does nothing if the key is not present.
§Errors
- If properties to remove contains a reserved property
sourcepub fn set_location(self, location: String) -> Self
pub fn set_location(self, location: String) -> Self
Set the location of the table metadata, stripping any trailing slashes.
sourcepub fn add_snapshot(self, snapshot: Snapshot) -> Result<Self>
pub fn add_snapshot(self, snapshot: Snapshot) -> Result<Self>
Add a snapshot to the table metadata.
§Errors
- Snapshot id already exists.
- For format version > 1: the sequence number of the snapshot is lower than the highest sequence number specified so far.
sourcepub fn set_branch_snapshot(
self,
snapshot: Snapshot,
branch: &str,
) -> Result<Self>
pub fn set_branch_snapshot( self, snapshot: Snapshot, branch: &str, ) -> Result<Self>
Append a snapshot to the specified branch.
Retention settings from the branch
are re-used.
§Errors
- Any of the preconditions of
self.add_snapshot
are not met.
sourcepub fn remove_snapshots(self, snapshot_ids: &[i64]) -> Self
pub fn remove_snapshots(self, snapshot_ids: &[i64]) -> Self
Remove snapshots by its ids from the table metadata. Does nothing if a snapshot id is not present. Keeps as changes only the snapshots that were actually removed.
sourcepub fn set_ref(
self,
ref_name: &str,
reference: SnapshotReference,
) -> Result<Self>
pub fn set_ref( self, ref_name: &str, reference: SnapshotReference, ) -> Result<Self>
sourcepub fn remove_ref(self, ref_name: &str) -> Self
pub fn remove_ref(self, ref_name: &str) -> Self
Remove a reference
If ref_name='main'
the current snapshot id is set to -1.
sourcepub fn add_schema(self, schema: Schema) -> Self
pub fn add_schema(self, schema: Schema) -> Self
Add a schema to the table metadata.
The provided schema.schema_id
may not be used.
Important: Use this method with caution. The builder does not check if the added schema is compatible with the current schema.
sourcepub fn set_current_schema(self, schema_id: i32) -> Result<Self>
pub fn set_current_schema(self, schema_id: i32) -> Result<Self>
Set the current schema id.
If schema_id
is -1, the last added schema is set as the current schema.
Errors:
- provided
schema_id
is -1 but no schema has been added viaadd_schema
. - No schema with the provided
schema_id
exists.
sourcepub fn add_current_schema(self, schema: Schema) -> Result<Self>
pub fn add_current_schema(self, schema: Schema) -> Result<Self>
Add a schema and set it as the current schema.
sourcepub fn add_partition_spec(
self,
unbound_spec: UnboundPartitionSpec,
) -> Result<Self>
pub fn add_partition_spec( self, unbound_spec: UnboundPartitionSpec, ) -> Result<Self>
Add a partition spec to the table metadata.
The spec is bound eagerly to the current schema. If a schema is added in the same set of changes, the schema should be added first.
Even if unbound_spec.spec_id
is provided as Some
, it may not be used.
§Errors
- The partition spec cannot be bound to the current schema.
- The partition spec has non-sequential field ids and the table format version is 1.
sourcepub fn set_default_partition_spec(self, spec_id: i32) -> Result<Self>
pub fn set_default_partition_spec(self, spec_id: i32) -> Result<Self>
Set the default partition spec.
§Errors
- spec_id is -1 but no spec has been added via
add_partition_spec
. - No partition spec with the provided
spec_id
exists.
sourcepub fn add_default_partition_spec(
self,
unbound_spec: UnboundPartitionSpec,
) -> Result<Self>
pub fn add_default_partition_spec( self, unbound_spec: UnboundPartitionSpec, ) -> Result<Self>
Add a partition spec and set it as the default
sourcepub fn add_sort_order(self, sort_order: SortOrder) -> Result<Self>
pub fn add_sort_order(self, sort_order: SortOrder) -> Result<Self>
Add a sort order to the table metadata.
The spec is bound eagerly to the current schema and must be valid for it. If a schema is added in the same set of changes, the schema should be added first.
Even if sort_order.order_id
is provided, it may not be used.
§Errors
- Sort order id to add already exists.
- Sort order is incompatible with the current schema.
sourcepub fn set_default_sort_order(self, sort_order_id: i64) -> Result<Self>
pub fn set_default_sort_order(self, sort_order_id: i64) -> Result<Self>
Set the default sort order. If sort_order_id
is -1, the last added sort order is set as default.
§Errors
- sort_order_id is -1 but no sort order has been added via
add_sort_order
. - No sort order with the provided
sort_order_id
exists.
sourcepub fn build(self) -> Result<TableMetadataBuildResult>
pub fn build(self) -> Result<TableMetadataBuildResult>
Build the table metadata.
Trait Implementations§
source§impl Clone for TableMetadataBuilder
impl Clone for TableMetadataBuilder
source§fn clone(&self) -> TableMetadataBuilder
fn clone(&self) -> TableMetadataBuilder
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for TableMetadataBuilder
impl RefUnwindSafe for TableMetadataBuilder
impl Send for TableMetadataBuilder
impl Sync for TableMetadataBuilder
impl Unpin for TableMetadataBuilder
impl UnwindSafe for TableMetadataBuilder
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.