Skip to content

Commit

Permalink
little update
Browse files Browse the repository at this point in the history
  • Loading branch information
my-vegetable-has-exploded committed Nov 28, 2023
1 parent f97b229 commit 0a4a7ed
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 57 deletions.
4 changes: 2 additions & 2 deletions crates/catalog/rest/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ mod _serde {

use serde_derive::{Deserialize, Serialize};

use iceberg::spec::{PartitionSpec, Schema, SortOrder, TableMetadata};
use iceberg::spec::{PartitionSpec, Schema, SortOrder, TableMetadata, UnboundPartitionSpec};
use iceberg::{Error, ErrorKind, Namespace, TableIdent, TableRequirement, TableUpdate};

pub(super) const OK: u16 = 200u16;
Expand Down Expand Up @@ -660,7 +660,7 @@ mod _serde {
pub(super) name: String,
pub(super) location: Option<String>,
pub(super) schema: Schema,
pub(super) partition_spec: Option<PartitionSpec>,
pub(super) partition_spec: Option<UnboundPartitionSpec>,
pub(super) write_order: Option<SortOrder>,
pub(super) stage_create: Option<bool>,
pub(super) properties: Option<HashMap<String, String>>,
Expand Down
6 changes: 3 additions & 3 deletions crates/iceberg/src/catalog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use serde_derive::{Deserialize, Serialize};
use urlencoding::encode;

use crate::spec::{FormatVersion, PartitionSpec, Schema, Snapshot, SnapshotReference, SortOrder};
use crate::spec::{FormatVersion, PartitionSpec, Schema, Snapshot, SnapshotReference, SortOrder, UnboundPartitionSpec};
use crate::table::Table;
use crate::{Error, ErrorKind, Result};
use async_trait::async_trait;
Expand Down Expand Up @@ -226,7 +226,7 @@ pub struct TableCreation {
pub schema: Schema,
/// The partition spec of the table, could be None.
#[builder(default, setter(strip_option))]
pub partition_spec: Option<PartitionSpec>,
pub partition_spec: Option<UnboundPartitionSpec>,
/// The sort order of the table.
#[builder(default, setter(strip_option))]
pub sort_order: Option<SortOrder>,
Expand Down Expand Up @@ -361,7 +361,7 @@ pub enum TableUpdate {
/// Add a new partition spec to the table
AddSpec {
/// The partition spec to add.
spec: PartitionSpec,
spec: UnboundPartitionSpec,
},
/// Set table's default spec
#[serde(rename_all = "kebab-case")]
Expand Down
3 changes: 0 additions & 3 deletions crates/iceberg/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ pub enum ErrorKind {
/// service error.
Unexpected,

/// Iceberg finds some conflict when checking.
Conflict,
/// Iceberg data is invalid.
///
/// This error is returned when we try to read a table from iceberg but
Expand All @@ -59,7 +57,6 @@ impl From<ErrorKind> for &'static str {
fn from(v: ErrorKind) -> &'static str {
match v {
ErrorKind::Unexpected => "Unexpected",
ErrorKind::Conflict => "conflict",
ErrorKind::DataInvalid => "DataInvalid",
ErrorKind::FeatureUnsupported => "FeatureUnsupported",
}
Expand Down
49 changes: 0 additions & 49 deletions crates/iceberg/src/spec/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,55 +104,6 @@ impl UnboundPartitionSpec {
UnboundPartitionSpecBuilder::default()
}

/// Bind unbound partition spec to a schema
pub fn bind(&self, schema: SchemaRef) -> Result<PartitionSpec> {
let mut fields = Vec::with_capacity(self.fields.len());
let mut last_assigned_field_id: i32 =
UnboundPartitionSpec::unpartitioned_last_assigned_id();
for field in &self.fields {
let field_id = match field.partition_id {
Some(id) => id,
None => {
last_assigned_field_id += 1;
last_assigned_field_id
}
};
match schema.field_by_id(field.source_id) {
Some(f) => {
if f.name != field.name {
return Err(Error::new(
ErrorKind::Conflict,
format!(
"Field name {} in partition spec does not match schema",
field.name
),
));
}
}
None => {
return Err(Error::new(
ErrorKind::Conflict,
format!(
"Field id {} in partition spec is not in schema",
field.source_id
),
));
}
}
last_assigned_field_id = last_assigned_field_id.max(field_id);
fields.push(PartitionField {
source_id: field.source_id,
field_id,
name: field.name.clone(),
transform: field.transform,
});
}
let spec_id = match self.spec_id {
Some(id) => id,
None => DEFAULT_SPEC_ID,
};
Ok(PartitionSpec { spec_id, fields })
}
}

#[cfg(test)]
Expand Down

0 comments on commit 0a4a7ed

Please sign in to comment.