diff --git a/crates/catalog/rest/src/catalog.rs b/crates/catalog/rest/src/catalog.rs index b6ca41df7..4e380727b 100644 --- a/crates/catalog/rest/src/catalog.rs +++ b/crates/catalog/rest/src/catalog.rs @@ -521,7 +521,7 @@ mod _serde { use serde_derive::{Deserialize, Serialize}; - use iceberg::spec::{PartitionSpec, Schema, SortOrder, TableMetadata, UnboundPartitionSpec}; + use iceberg::spec::{Schema, SortOrder, TableMetadata, UnboundPartitionSpec}; use iceberg::{Error, ErrorKind, Namespace, TableIdent, TableRequirement, TableUpdate}; pub(super) const OK: u16 = 200u16; @@ -686,9 +686,9 @@ mod tests { use chrono::{TimeZone, Utc}; use iceberg::spec::ManifestListLocation::ManifestListFile; use iceberg::spec::{ - FormatVersion, NestedField, NullOrder, Operation, PartitionField, PartitionSpec, - PrimitiveType, Schema, Snapshot, SnapshotLog, SortDirection, SortField, SortOrder, Summary, - Transform, Type, + FormatVersion, NestedField, NullOrder, Operation, PrimitiveType, Schema, Snapshot, + SnapshotLog, SortDirection, SortField, SortOrder, Summary, Transform, Type, + UnboundPartitionField, UnboundPartitionSpec, }; use iceberg::transaction::Transaction; use mockito::{Mock, Server, ServerGuard}; @@ -1233,14 +1233,12 @@ mod tests { ) .properties(HashMap::from([("owner".to_string(), "testx".to_string())])) .partition_spec( - PartitionSpec::builder() - .with_fields(vec![PartitionField::builder() + UnboundPartitionSpec::builder() + .with_fields(vec![UnboundPartitionField::builder() .source_id(1) - .field_id(1000) .transform(Transform::Truncate(3)) .name("id".to_string()) .build()]) - .with_spec_id(1) .build() .unwrap(), ) diff --git a/crates/iceberg/src/catalog/mod.rs b/crates/iceberg/src/catalog/mod.rs index 142ea3029..a0b69a154 100644 --- a/crates/iceberg/src/catalog/mod.rs +++ b/crates/iceberg/src/catalog/mod.rs @@ -20,7 +20,9 @@ use serde_derive::{Deserialize, Serialize}; use urlencoding::encode; -use crate::spec::{FormatVersion, PartitionSpec, Schema, Snapshot, SnapshotReference, SortOrder, UnboundPartitionSpec}; +use crate::spec::{ + FormatVersion, Schema, Snapshot, SnapshotReference, SortOrder, UnboundPartitionSpec, +}; use crate::table::Table; use crate::{Error, ErrorKind, Result}; use async_trait::async_trait; @@ -429,9 +431,9 @@ pub enum TableUpdate { mod tests { use crate::spec::ManifestListLocation::ManifestListFile; use crate::spec::{ - FormatVersion, NestedField, NullOrder, Operation, PartitionField, PartitionSpec, - PrimitiveType, Schema, Snapshot, SnapshotReference, SnapshotRetention, SortDirection, - SortField, SortOrder, Summary, Transform, Type, + FormatVersion, NestedField, NullOrder, Operation, PrimitiveType, Schema, Snapshot, + SnapshotReference, SnapshotRetention, SortDirection, SortField, SortOrder, Summary, + Transform, Type, UnboundPartitionField, UnboundPartitionSpec, }; use crate::{NamespaceIdent, TableIdent, TableRequirement, TableUpdate}; use serde::de::DeserializeOwned; @@ -758,23 +760,19 @@ mod tests { { "action": "add-spec", "spec": { - "spec-id": 1, "fields": [ { "source-id": 4, - "field-id": 1000, "name": "ts_day", "transform": "day" }, { "source-id": 1, - "field-id": 1001, "name": "id_bucket", "transform": "bucket[16]" }, { "source-id": 2, - "field-id": 1002, "name": "id_truncate", "transform": "truncate[4]" } @@ -783,28 +781,24 @@ mod tests { } "#, TableUpdate::AddSpec { - spec: PartitionSpec::builder() - .with_spec_id(1) - .with_partition_field( - PartitionField::builder() + spec: UnboundPartitionSpec::builder() + .with_unbound_partition_field( + UnboundPartitionField::builder() .source_id(4) - .field_id(1000) .name("ts_day".to_string()) .transform(Transform::Day) .build(), ) - .with_partition_field( - PartitionField::builder() + .with_unbound_partition_field( + UnboundPartitionField::builder() .source_id(1) - .field_id(1001) .name("id_bucket".to_string()) .transform(Transform::Bucket(16)) .build(), ) - .with_partition_field( - PartitionField::builder() + .with_unbound_partition_field( + UnboundPartitionField::builder() .source_id(2) - .field_id(1002) .name("id_truncate".to_string()) .transform(Transform::Truncate(4)) .build(), diff --git a/crates/iceberg/src/spec/partition.rs b/crates/iceberg/src/spec/partition.rs index e2f67740b..774162dec 100644 --- a/crates/iceberg/src/spec/partition.rs +++ b/crates/iceberg/src/spec/partition.rs @@ -18,13 +18,11 @@ /*! * Partitioning */ -use crate::error::{Error, ErrorKind, Result}; use serde::{Deserialize, Serialize}; use std::sync::Arc; use typed_builder::TypedBuilder; -use super::DEFAULT_SPEC_ID; -use super::{schema::SchemaRef, transform::Transform}; +use super::transform::Transform; /// Reference to [`PartitionSpec`]. pub type PartitionSpecRef = Arc; @@ -62,11 +60,9 @@ impl PartitionSpec { } } -static PARTITION_DATA_ID_START: i32 = 1000; - /// Reference to [`UnboundPartitionSpec`]. pub type UnboundPartitionSpecRef = Arc; -#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] +#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, TypedBuilder)] #[serde(rename_all = "kebab-case")] /// Unbound partition field can be built without a schema and later bound to a schema. pub struct UnboundPartitionField { @@ -74,6 +70,7 @@ pub struct UnboundPartitionField { pub source_id: i32, /// A partition field id that is used to identify a partition field and is unique within a partition spec. /// In v2 table metadata, it is unique across all partition specs. + #[builder(default, setter(strip_option))] pub partition_id: Option, /// A partition name. pub name: String, @@ -87,6 +84,7 @@ pub struct UnboundPartitionField { /// Unbound partition spec can be built without a schema and later bound to a schema. pub struct UnboundPartitionSpec { /// Identifier for PartitionSpec + #[builder(default, setter(strip_option))] pub spec_id: Option, /// Details of the partition spec #[builder(setter(each(name = "with_unbound_partition_field")))] @@ -94,16 +92,10 @@ pub struct UnboundPartitionSpec { } impl UnboundPartitionSpec { - /// last assigned id for partitioned field - pub fn unpartitioned_last_assigned_id() -> i32 { - PARTITION_DATA_ID_START - 1 - } - /// Create unbound partition spec builer pub fn builder() -> UnboundPartitionSpecBuilder { UnboundPartitionSpecBuilder::default() } - } #[cfg(test)]