@@ -134,7 +134,7 @@ pub struct UnboundPartitionField {
134
134
/// A partition field id that is used to identify a partition field and is unique within a partition spec.
135
135
/// In v2 table metadata, it is unique across all partition specs.
136
136
#[ builder( default , setter( strip_option) ) ]
137
- pub partition_id : Option < i32 > ,
137
+ pub field_id : Option < i32 > ,
138
138
/// A partition name.
139
139
pub name : String ,
140
140
/// A transform that is applied to the source column to produce a partition value.
@@ -177,7 +177,7 @@ impl From<PartitionField> for UnboundPartitionField {
177
177
fn from ( field : PartitionField ) -> Self {
178
178
UnboundPartitionField {
179
179
source_id : field. source_id ,
180
- partition_id : Some ( field. field_id ) ,
180
+ field_id : Some ( field. field_id ) ,
181
181
name : field. name ,
182
182
transform : field. transform ,
183
183
}
@@ -224,7 +224,7 @@ impl UnboundPartitionSpecBuilder {
224
224
) -> Result < Self > {
225
225
let field = UnboundPartitionField {
226
226
source_id,
227
- partition_id : None ,
227
+ field_id : None ,
228
228
name : target_name. to_string ( ) ,
229
229
transform : transformation,
230
230
} ;
@@ -246,8 +246,8 @@ impl UnboundPartitionSpecBuilder {
246
246
fn add_partition_field_internal ( mut self , field : UnboundPartitionField ) -> Result < Self > {
247
247
self . check_name_set_and_unique ( & field. name ) ?;
248
248
self . check_for_redundant_partitions ( field. source_id , & field. transform ) ?;
249
- if let Some ( partition_id ) = field. partition_id {
250
- self . check_partition_id_unique ( partition_id ) ?;
249
+ if let Some ( partition_field_id ) = field. field_id {
250
+ self . check_partition_id_unique ( partition_field_id ) ?;
251
251
}
252
252
self . fields . push ( field) ;
253
253
Ok ( self )
@@ -331,7 +331,7 @@ impl<'a> PartitionSpecBuilder<'a> {
331
331
. id ;
332
332
let field = UnboundPartitionField {
333
333
source_id,
334
- partition_id : None ,
334
+ field_id : None ,
335
335
name : target_name. into ( ) ,
336
336
transform,
337
337
} ;
@@ -341,15 +341,15 @@ impl<'a> PartitionSpecBuilder<'a> {
341
341
342
342
/// Add a new partition field to the partition spec.
343
343
///
344
- /// If `partition_id` is set, it is used as the field id.
344
+ /// If partition field id is set, it is used as the field id.
345
345
/// Otherwise, a new `field_id` is assigned.
346
346
pub fn add_unbound_field ( mut self , field : UnboundPartitionField ) -> Result < Self > {
347
347
self . check_name_set_and_unique ( & field. name ) ?;
348
348
self . check_for_redundant_partitions ( field. source_id , & field. transform ) ?;
349
349
Self :: check_name_does_not_collide_with_schema ( & field, self . schema ) ?;
350
350
Self :: check_transform_compatibility ( & field, self . schema ) ?;
351
- if let Some ( partition_id ) = field. partition_id {
352
- self . check_partition_id_unique ( partition_id ) ?;
351
+ if let Some ( partition_field_id ) = field. field_id {
352
+ self . check_partition_id_unique ( partition_field_id ) ?;
353
353
}
354
354
355
355
// Non-fallible from here
@@ -387,7 +387,7 @@ impl<'a> PartitionSpecBuilder<'a> {
387
387
// we skip it.
388
388
let assigned_ids = fields
389
389
. iter ( )
390
- . filter_map ( |f| f. partition_id )
390
+ . filter_map ( |f| f. field_id )
391
391
. collect :: < std:: collections:: HashSet < _ > > ( ) ;
392
392
393
393
fn _check_add_1 ( prev : i32 ) -> Result < i32 > {
@@ -401,9 +401,9 @@ impl<'a> PartitionSpecBuilder<'a> {
401
401
402
402
let mut bound_fields = Vec :: with_capacity ( fields. len ( ) ) ;
403
403
for field in fields. into_iter ( ) {
404
- let partition_id = if let Some ( partition_id ) = field. partition_id {
405
- last_assigned_field_id = std:: cmp:: max ( last_assigned_field_id, partition_id ) ;
406
- partition_id
404
+ let partition_field_id = if let Some ( partition_field_id ) = field. field_id {
405
+ last_assigned_field_id = std:: cmp:: max ( last_assigned_field_id, partition_field_id ) ;
406
+ partition_field_id
407
407
} else {
408
408
last_assigned_field_id = _check_add_1 ( last_assigned_field_id) ?;
409
409
while assigned_ids. contains ( & last_assigned_field_id) {
@@ -414,7 +414,7 @@ impl<'a> PartitionSpecBuilder<'a> {
414
414
415
415
bound_fields. push ( PartitionField {
416
416
source_id : field. source_id ,
417
- field_id : partition_id ,
417
+ field_id : partition_field_id ,
418
418
name : field. name ,
419
419
transform : field. transform ,
420
420
} )
@@ -544,11 +544,7 @@ trait CorePartitionSpecValidator {
544
544
545
545
/// Check field / partition_id unique within the partition spec if set
546
546
fn check_partition_id_unique ( & self , field_id : i32 ) -> Result < ( ) > {
547
- if self
548
- . fields ( )
549
- . iter ( )
550
- . any ( |f| f. partition_id == Some ( field_id) )
551
- {
547
+ if self . fields ( ) . iter ( ) . any ( |f| f. field_id == Some ( field_id) ) {
552
548
return Err ( Error :: new (
553
549
ErrorKind :: DataInvalid ,
554
550
format ! (
@@ -698,17 +694,17 @@ mod tests {
698
694
"spec-id": 1,
699
695
"fields": [ {
700
696
"source-id": 4,
701
- "partition -id": 1000,
697
+ "field -id": 1000,
702
698
"name": "ts_day",
703
699
"transform": "day"
704
700
}, {
705
701
"source-id": 1,
706
- "partition -id": 1001,
702
+ "field -id": 1001,
707
703
"name": "id_bucket",
708
704
"transform": "bucket[16]"
709
705
}, {
710
706
"source-id": 2,
711
- "partition -id": 1002,
707
+ "field -id": 1002,
712
708
"name": "id_truncate",
713
709
"transform": "truncate[4]"
714
710
} ]
@@ -719,17 +715,17 @@ mod tests {
719
715
assert_eq ! ( Some ( 1 ) , partition_spec. spec_id) ;
720
716
721
717
assert_eq ! ( 4 , partition_spec. fields[ 0 ] . source_id) ;
722
- assert_eq ! ( Some ( 1000 ) , partition_spec. fields[ 0 ] . partition_id ) ;
718
+ assert_eq ! ( Some ( 1000 ) , partition_spec. fields[ 0 ] . field_id ) ;
723
719
assert_eq ! ( "ts_day" , partition_spec. fields[ 0 ] . name) ;
724
720
assert_eq ! ( Transform :: Day , partition_spec. fields[ 0 ] . transform) ;
725
721
726
722
assert_eq ! ( 1 , partition_spec. fields[ 1 ] . source_id) ;
727
- assert_eq ! ( Some ( 1001 ) , partition_spec. fields[ 1 ] . partition_id ) ;
723
+ assert_eq ! ( Some ( 1001 ) , partition_spec. fields[ 1 ] . field_id ) ;
728
724
assert_eq ! ( "id_bucket" , partition_spec. fields[ 1 ] . name) ;
729
725
assert_eq ! ( Transform :: Bucket ( 16 ) , partition_spec. fields[ 1 ] . transform) ;
730
726
731
727
assert_eq ! ( 2 , partition_spec. fields[ 2 ] . source_id) ;
732
- assert_eq ! ( Some ( 1002 ) , partition_spec. fields[ 2 ] . partition_id ) ;
728
+ assert_eq ! ( Some ( 1002 ) , partition_spec. fields[ 2 ] . field_id ) ;
733
729
assert_eq ! ( "id_truncate" , partition_spec. fields[ 2 ] . name) ;
734
730
assert_eq ! ( Transform :: Truncate ( 4 ) , partition_spec. fields[ 2 ] . transform) ;
735
731
@@ -746,7 +742,7 @@ mod tests {
746
742
assert_eq ! ( None , partition_spec. spec_id) ;
747
743
748
744
assert_eq ! ( 4 , partition_spec. fields[ 0 ] . source_id) ;
749
- assert_eq ! ( None , partition_spec. fields[ 0 ] . partition_id ) ;
745
+ assert_eq ! ( None , partition_spec. fields[ 0 ] . field_id ) ;
750
746
assert_eq ! ( "ts_day" , partition_spec. fields[ 0 ] . name) ;
751
747
assert_eq ! ( Transform :: Day , partition_spec. fields[ 0 ] . transform) ;
752
748
}
@@ -963,14 +959,14 @@ mod tests {
963
959
PartitionSpec :: builder ( & schema)
964
960
. add_unbound_field ( UnboundPartitionField {
965
961
source_id : 1 ,
966
- partition_id : Some ( 1000 ) ,
962
+ field_id : Some ( 1000 ) ,
967
963
name : "id" . to_string ( ) ,
968
964
transform : Transform :: Identity ,
969
965
} )
970
966
. unwrap ( )
971
967
. add_unbound_field ( UnboundPartitionField {
972
968
source_id : 2 ,
973
- partition_id : Some ( 1000 ) ,
969
+ field_id : Some ( 1000 ) ,
974
970
name : "id_bucket" . to_string ( ) ,
975
971
transform : Transform :: Bucket ( 16 ) ,
976
972
} )
@@ -1004,22 +1000,22 @@ mod tests {
1004
1000
source_id : 1 ,
1005
1001
name : "id" . to_string ( ) ,
1006
1002
transform : Transform :: Identity ,
1007
- partition_id : Some ( 1012 ) ,
1003
+ field_id : Some ( 1012 ) ,
1008
1004
} )
1009
1005
. unwrap ( )
1010
1006
. add_unbound_field ( UnboundPartitionField {
1011
1007
source_id : 2 ,
1012
1008
name : "name_void" . to_string ( ) ,
1013
1009
transform : Transform :: Void ,
1014
- partition_id : None ,
1010
+ field_id : None ,
1015
1011
} )
1016
1012
. unwrap ( )
1017
1013
// Should keep its ID even if its lower
1018
1014
. add_unbound_field ( UnboundPartitionField {
1019
1015
source_id : 3 ,
1020
1016
name : "year" . to_string ( ) ,
1021
1017
transform : Transform :: Year ,
1022
- partition_id : Some ( 1 ) ,
1018
+ field_id : Some ( 1 ) ,
1023
1019
} )
1024
1020
. unwrap ( )
1025
1021
. build ( )
@@ -1090,7 +1086,7 @@ mod tests {
1090
1086
. with_spec_id ( 1 )
1091
1087
. add_unbound_field ( UnboundPartitionField {
1092
1088
source_id : 1 ,
1093
- partition_id : None ,
1089
+ field_id : None ,
1094
1090
name : "id" . to_string ( ) ,
1095
1091
transform : Transform :: Bucket ( 16 ) ,
1096
1092
} )
@@ -1123,7 +1119,7 @@ mod tests {
1123
1119
. with_spec_id ( 1 )
1124
1120
. add_unbound_field ( UnboundPartitionField {
1125
1121
source_id : 1 ,
1126
- partition_id : None ,
1122
+ field_id : None ,
1127
1123
name : "id" . to_string ( ) ,
1128
1124
transform : Transform :: Identity ,
1129
1125
} )
@@ -1136,7 +1132,7 @@ mod tests {
1136
1132
. with_spec_id ( 1 )
1137
1133
. add_unbound_field ( UnboundPartitionField {
1138
1134
source_id : 2 ,
1139
- partition_id : None ,
1135
+ field_id : None ,
1140
1136
name : "id" . to_string ( ) ,
1141
1137
transform : Transform :: Identity ,
1142
1138
} )
@@ -1171,13 +1167,13 @@ mod tests {
1171
1167
. add_unbound_fields ( vec ! [
1172
1168
UnboundPartitionField {
1173
1169
source_id: 1 ,
1174
- partition_id : None ,
1170
+ field_id : None ,
1175
1171
name: "id_bucket" . to_string( ) ,
1176
1172
transform: Transform :: Bucket ( 16 ) ,
1177
1173
} ,
1178
1174
UnboundPartitionField {
1179
1175
source_id: 2 ,
1180
- partition_id : None ,
1176
+ field_id : None ,
1181
1177
name: "name" . to_string( ) ,
1182
1178
transform: Transform :: Identity ,
1183
1179
} ,
@@ -1192,13 +1188,13 @@ mod tests {
1192
1188
. add_unbound_fields ( vec ! [
1193
1189
UnboundPartitionField {
1194
1190
source_id: 1 ,
1195
- partition_id : None ,
1191
+ field_id : None ,
1196
1192
name: "id_bucket" . to_string( ) ,
1197
1193
transform: Transform :: Bucket ( 16 ) ,
1198
1194
} ,
1199
1195
UnboundPartitionField {
1200
1196
source_id: 4 ,
1201
- partition_id : None ,
1197
+ field_id : None ,
1202
1198
name: "name" . to_string( ) ,
1203
1199
transform: Transform :: Identity ,
1204
1200
} ,
@@ -1237,7 +1233,7 @@ mod tests {
1237
1233
. with_spec_id ( 1 )
1238
1234
. add_unbound_field ( UnboundPartitionField {
1239
1235
source_id : 1 ,
1240
- partition_id : None ,
1236
+ field_id : None ,
1241
1237
name : "id_year" . to_string ( ) ,
1242
1238
transform : Transform :: Year ,
1243
1239
} )
@@ -1250,7 +1246,7 @@ mod tests {
1250
1246
. with_spec_id ( 1 )
1251
1247
. add_partition_fields ( vec ! [ UnboundPartitionField {
1252
1248
source_id: 1 ,
1253
- partition_id : None ,
1249
+ field_id : None ,
1254
1250
name: "id_bucket[16]" . to_string( ) ,
1255
1251
transform: Transform :: Bucket ( 16 ) ,
1256
1252
} ] )
@@ -1261,7 +1257,7 @@ mod tests {
1261
1257
spec_id: Some ( 1 ) ,
1262
1258
fields: vec![ UnboundPartitionField {
1263
1259
source_id: 1 ,
1264
- partition_id : None ,
1260
+ field_id : None ,
1265
1261
name: "id_bucket[16]" . to_string( ) ,
1266
1262
transform: Transform :: Bucket ( 16 ) ,
1267
1263
} ]
0 commit comments