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: Added UpdatePartitionSpec #967

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions crates/iceberg/src/spec/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ pub struct PartitionField {
}

impl PartitionField {
/// Creates new `PartitionField`` instance
pub fn new(source_id: i32, field_id: i32, name: String, transform: Transform) -> Self {
Self {
source_id,
field_id,
name,
transform,
}
}

/// To unbound partition field
pub fn into_unbound(self) -> UnboundPartitionField {
self.into()
Expand Down
7 changes: 7 additions & 0 deletions crates/iceberg/src/spec/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ pub struct Schema {
field_id_to_accessor: HashMap<i32, Arc<StructAccessor>>,
}

impl Schema {
/// Returns id to field mapping
pub fn id_to_field(&self) -> HashMap<i32, NestedFieldRef> {
self.id_to_field.clone()
}
}

impl PartialEq for Schema {
fn eq(&self, other: &Self) -> bool {
self.r#struct == other.r#struct
Expand Down
23 changes: 21 additions & 2 deletions crates/iceberg/src/spec/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use crate::ErrorKind;
/// predicates and partition predicates.
///
/// All transforms must return `null` for a `null` input value.
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
pub enum Transform {
/// Source value, unmodified
///
Expand Down Expand Up @@ -355,11 +355,30 @@ impl Transform {
}

/// Check if `Transform` is applicable on datum's `PrimitiveType`
fn can_transform(&self, datum: &Datum) -> bool {
pub fn can_transform(&self, datum: &Datum) -> bool {
let input_type = datum.data_type().clone();
self.result_type(&Type::Primitive(input_type)).is_ok()
}

/// Checks if can transform from type
pub fn can_transform_from_primitive_type(&self, primitive_type: &PrimitiveType) -> bool {
self.result_type(&Type::Primitive(primitive_type.clone()))
.is_ok()
}

/// Checks if time transform
pub fn is_time_transform(&self) -> bool {
matches!(
self,
Transform::Hour | Transform::Day | Transform::Month | Transform::Year
)
}

/// Checks if void transform
pub fn is_void_transform(&self) -> bool {
matches!(self, Transform::Void)
}

/// Creates a unary predicate from a given operator and a reference name.
fn project_unary(op: PredicateOperator, name: &str) -> Result<Option<Predicate>> {
Ok(Some(Predicate::Unary(UnaryExpression::new(
Expand Down
Loading
Loading