@@ -17,7 +17,6 @@ use iceberg_rust_spec::spec::{
17
17
snapshot:: {
18
18
generate_snapshot_id, SnapshotBuilder , SnapshotReference , SnapshotRetention , Summary ,
19
19
} ,
20
- types:: StructField ,
21
20
values:: { Struct , Value } ,
22
21
} ;
23
22
use iceberg_rust_spec:: util:: strip_prefix;
@@ -134,6 +133,7 @@ impl Operation {
134
133
Some ( stream:: iter ( manifest_list_reader) . filter_map ( |manifest| {
135
134
let datafiles = datafiles. clone ( ) ;
136
135
let existing_partitions = existing_partitions. clone ( ) ;
136
+ let partition_spec = partition_spec. clone ( ) ;
137
137
async move {
138
138
let manifest = manifest
139
139
. map_err ( Into :: into)
@@ -150,7 +150,6 @@ impl Operation {
150
150
summary,
151
151
datafiles. keys ( ) ,
152
152
partition_spec. fields ( ) ,
153
- schema,
154
153
) ;
155
154
if !partition_values. is_empty ( ) {
156
155
for file in & partition_values {
@@ -221,17 +220,6 @@ impl Operation {
221
220
} ,
222
221
) ;
223
222
224
- let partition_columns = Arc :: new (
225
- partition_spec
226
- . fields ( )
227
- . iter ( )
228
- . map ( |x| schema. fields ( ) . get ( * x. source_id ( ) as usize ) )
229
- . collect :: < Option < Vec < _ > > > ( )
230
- . ok_or ( Error :: InvalidFormat (
231
- "Partition column in schema" . to_string ( ) ,
232
- ) ) ?,
233
- ) ;
234
-
235
223
match existing_manifest_iter {
236
224
Some ( existing_manifest_iter) => {
237
225
let manifest_iter =
@@ -241,7 +229,6 @@ impl Operation {
241
229
. then ( |( manifest, files) : ( ManifestStatus , Vec < Struct > ) | {
242
230
let object_store = object_store. clone ( ) ;
243
231
let datafiles = datafiles. clone ( ) ;
244
- let partition_columns = partition_columns. clone ( ) ;
245
232
let branch = branch. clone ( ) ;
246
233
async move {
247
234
write_manifest (
@@ -250,7 +237,6 @@ impl Operation {
250
237
files,
251
238
datafiles,
252
239
schema,
253
- & partition_columns,
254
240
object_store,
255
241
branch,
256
242
)
@@ -271,7 +257,6 @@ impl Operation {
271
257
. then ( |( manifest, files) : ( ManifestStatus , Vec < Struct > ) | {
272
258
let object_store = object_store. clone ( ) ;
273
259
let datafiles = datafiles. clone ( ) ;
274
- let partition_columns = partition_columns. clone ( ) ;
275
260
let branch = branch. clone ( ) ;
276
261
async move {
277
262
write_manifest (
@@ -280,7 +265,6 @@ impl Operation {
280
265
files,
281
266
datafiles,
282
267
schema,
283
- & partition_columns,
284
268
object_store,
285
269
branch,
286
270
)
@@ -405,18 +389,6 @@ impl Operation {
405
389
( ManifestStatus :: New ( manifest) , vec ! [ partition_value. clone( ) ] )
406
390
} ) ;
407
391
408
- let partition_columns = Arc :: new (
409
- table_metadata
410
- . default_partition_spec ( ) ?
411
- . fields ( )
412
- . iter ( )
413
- . map ( |x| schema. fields ( ) . get ( * x. source_id ( ) as usize ) )
414
- . collect :: < Option < Vec < _ > > > ( )
415
- . ok_or ( Error :: InvalidFormat (
416
- "Partition column in schema" . to_string ( ) ,
417
- ) ) ?,
418
- ) ;
419
-
420
392
let manifest_list_schema =
421
393
ManifestListEntry :: schema ( & table_metadata. format_version ) ?;
422
394
@@ -429,7 +401,6 @@ impl Operation {
429
401
. then ( |( manifest, files) : ( ManifestStatus , Vec < Struct > ) | {
430
402
let object_store = object_store. clone ( ) ;
431
403
let datafiles = datafiles. clone ( ) ;
432
- let partition_columns = partition_columns. clone ( ) ;
433
404
let branch = branch. clone ( ) ;
434
405
let schema = & schema;
435
406
let old_storage_table_metadata = & table_metadata;
@@ -440,7 +411,6 @@ impl Operation {
440
411
files,
441
412
datafiles,
442
413
schema,
443
- & partition_columns,
444
414
object_store,
445
415
branch,
446
416
)
@@ -556,12 +526,12 @@ pub(crate) async fn write_manifest(
556
526
files : Vec < Struct > ,
557
527
datafiles : Arc < HashMap < Struct , Vec < DataFile > > > ,
558
528
schema : & Schema ,
559
- partition_columns : & [ & StructField ] ,
560
529
object_store : Arc < dyn ObjectStore > ,
561
530
branch : Option < String > ,
562
531
) -> Result < ManifestListEntry , Error > {
532
+ let partition_spec = table_metadata. default_partition_spec ( ) ?;
563
533
let manifest_schema = ManifestEntry :: schema (
564
- & partition_value_schema ( table_metadata . default_partition_spec ( ) ? . fields ( ) , schema) ?,
534
+ & partition_value_schema ( partition_spec . fields ( ) , schema) ?,
565
535
& table_metadata. format_version ,
566
536
) ?;
567
537
@@ -596,8 +566,7 @@ pub(crate) async fn write_manifest(
596
566
597
567
if manifest. partitions . is_none ( ) {
598
568
manifest. partitions = Some (
599
- table_metadata
600
- . default_partition_spec ( ) ?
569
+ partition_spec
601
570
. fields ( )
602
571
. iter ( )
603
572
. map ( |_| FieldSummary {
@@ -614,7 +583,7 @@ pub(crate) async fn write_manifest(
614
583
update_partitions (
615
584
manifest. partitions . as_mut ( ) . unwrap ( ) ,
616
585
datafile. partition ( ) ,
617
- partition_columns ,
586
+ partition_spec . fields ( ) ,
618
587
) ?;
619
588
620
589
let manifest_entry = ManifestEntry :: builder ( )
@@ -662,13 +631,10 @@ pub(crate) async fn write_manifest(
662
631
fn update_partitions (
663
632
partitions : & mut [ FieldSummary ] ,
664
633
partition_values : & Struct ,
665
- partition_columns : & [ & StructField ] ,
634
+ partition_columns : & [ PartitionField ] ,
666
635
) -> Result < ( ) , Error > {
667
636
for ( field, summary) in partition_columns. iter ( ) . zip ( partitions. iter_mut ( ) ) {
668
- let value = & partition_values. fields [ * partition_values
669
- . lookup
670
- . get ( & field. name )
671
- . ok_or_else ( || Error :: InvalidFormat ( "partition value in schema" . to_string ( ) ) ) ?] ;
637
+ let value = & partition_values. get ( field. name ( ) ) . and_then ( |x| x. as_ref ( ) ) ;
672
638
if let Some ( value) = value {
673
639
if let Some ( lower_bound) = & mut summary. lower_bound {
674
640
match ( value, lower_bound) {
@@ -770,23 +736,14 @@ fn partition_values_in_bounds<'a>(
770
736
partitions : & [ FieldSummary ] ,
771
737
partition_values : impl Iterator < Item = & ' a Struct > ,
772
738
partition_spec : & [ PartitionField ] ,
773
- schema : & Schema ,
774
739
) -> Vec < Struct > {
775
740
partition_values
776
741
. filter ( |value| {
777
742
partition_spec
778
743
. iter ( )
779
744
. map ( |field| {
780
- let name = & schema
781
- . fields ( )
782
- . get ( * field. source_id ( ) as usize )
783
- . ok_or_else ( || {
784
- Error :: InvalidFormat ( "partition values in schema" . to_string ( ) )
785
- } )
786
- . unwrap ( )
787
- . name ;
788
745
value
789
- . get ( name)
746
+ . get ( field . name ( ) )
790
747
. ok_or_else ( || {
791
748
Error :: InvalidFormat ( "partition values in schema" . to_string ( ) )
792
749
} )
0 commit comments