Skip to content

Commit 9d3ca08

Browse files
committed
WIP - alot with schemas
1 parent 1cc2304 commit 9d3ca08

File tree

12 files changed

+1294
-121
lines changed

12 files changed

+1294
-121
lines changed

crates/catalog/rest/tests/rest_catalog_test.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,8 @@ async fn test_create_table() {
293293
assert_eq!(table.metadata().format_version(), FormatVersion::V2);
294294
assert!(table.metadata().current_snapshot().is_none());
295295
assert!(table.metadata().history().is_empty());
296-
assert!(table.metadata().default_sort_order().unwrap().is_unsorted());
297-
assert!(table
298-
.metadata()
299-
.default_partition_spec()
300-
.unwrap()
301-
.is_unpartitioned());
296+
assert!(table.metadata().default_sort_order().is_unsorted());
297+
assert!(table.metadata().default_partition_spec().is_unpartitioned());
302298
}
303299

304300
#[tokio::test]

crates/iceberg/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub enum ErrorKind {
4747
/// Validation failed.
4848
///
4949
/// This error is returned when Table or View Metadata is manipulated
50-
/// in non-allowed ways.
50+
/// in forbidden ways that would produce corrupt metadata.
5151
ValidationFailed,
5252
}
5353

crates/iceberg/src/io/object_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ mod tests {
252252
async fn setup_manifest_files(&mut self) {
253253
let current_snapshot = self.table.metadata().current_snapshot().unwrap();
254254
let current_schema = current_snapshot.schema(self.table.metadata()).unwrap();
255-
let current_partition_spec = self.table.metadata().default_partition_spec().unwrap();
255+
let current_partition_spec = self.table.metadata().default_partition_spec();
256256

257257
// Write data files
258258
let data_file_manifest = ManifestWriter::new(

crates/iceberg/src/scan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ mod tests {
966966
.parent_snapshot(self.table.metadata())
967967
.unwrap();
968968
let current_schema = current_snapshot.schema(self.table.metadata()).unwrap();
969-
let current_partition_spec = self.table.metadata().default_partition_spec().unwrap();
969+
let current_partition_spec = self.table.metadata().default_partition_spec();
970970

971971
// Write data files
972972
let data_file_manifest = ManifestWriter::new(

crates/iceberg/src/spec/datatypes.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,12 @@ impl NestedField {
668668
self.write_default = Some(value);
669669
self
670670
}
671+
672+
/// Set the id of the field.
673+
pub(crate) fn with_id(mut self, id: i32) -> Self {
674+
self.id = id;
675+
self
676+
}
671677
}
672678

673679
impl fmt::Display for NestedField {

crates/iceberg/src/spec/partition.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,60 @@ impl PartitionSpec {
121121
pub fn to_unbound(self) -> UnboundPartitionSpec {
122122
self.into()
123123
}
124+
125+
/// Check if this partition spec is compatible with another partition spec.
126+
///
127+
/// Returns true if the partition spec is equal to the other spec with partition field ids ignored and
128+
/// spec_id ignored. The following must be identical:
129+
/// * The number of fields
130+
/// * Field order
131+
/// * Field names
132+
/// * Source column ids
133+
/// * Transforms
134+
pub fn compatible_with(&self, other: &UnboundPartitionSpec) -> bool {
135+
if self.fields.len() != other.fields.len() {
136+
return false;
137+
}
138+
139+
for (this_field, other_field) in self.fields.iter().zip(&other.fields) {
140+
if this_field.source_id != other_field.source_id
141+
|| this_field.transform != other_field.transform
142+
|| this_field.name != other_field.name
143+
{
144+
return false;
145+
}
146+
}
147+
148+
true
149+
}
150+
151+
/// Check if this partition spec has sequential partition ids.
152+
/// Sequential ids start from 1000 and increment by 1 for each field.
153+
/// This is required for spec version
154+
pub fn has_sequential_ids(&self) -> bool {
155+
for (index, field) in self.fields.iter().enumerate() {
156+
let expected_id = (UNPARTITIONED_LAST_ASSIGNED_ID as i64)
157+
.checked_add(1)
158+
.and_then(|id| id.checked_add(index as i64))
159+
.unwrap_or(i64::MAX);
160+
161+
if field.field_id as i64 != expected_id {
162+
return false;
163+
}
164+
}
165+
166+
true
167+
}
168+
169+
/// Get the highest field id in the partition spec.
170+
/// If the partition spec is unpartitioned, it returns the last unpartitioned last assigned id (999).
171+
pub fn highest_field_id(&self) -> i32 {
172+
self.fields
173+
.iter()
174+
.map(|f| f.field_id)
175+
.max()
176+
.unwrap_or(UNPARTITIONED_LAST_ASSIGNED_ID)
177+
}
124178
}
125179

126180
/// Reference to [`UnboundPartitionSpec`].
@@ -1263,4 +1317,7 @@ mod tests {
12631317
}]
12641318
});
12651319
}
1320+
1321+
#[test]
1322+
fn test_has_sequential_ids() {}
12661323
}

0 commit comments

Comments
 (0)