@@ -40,7 +40,7 @@ impl InclusiveProjection {
40
40
fn get_parts_for_field_id ( & mut self , field_id : i32 ) -> & Vec < PartitionField > {
41
41
if let std:: collections:: hash_map:: Entry :: Vacant ( e) = self . cached_parts . entry ( field_id) {
42
42
let mut parts: Vec < PartitionField > = vec ! [ ] ;
43
- for partition_spec_field in & self . partition_spec . fields {
43
+ for partition_spec_field in self . partition_spec . fields ( ) {
44
44
if partition_spec_field. source_id == field_id {
45
45
parts. push ( partition_spec_field. clone ( ) )
46
46
}
@@ -236,6 +236,7 @@ mod tests {
236
236
use crate :: expr:: { Bind , Predicate , Reference } ;
237
237
use crate :: spec:: {
238
238
Datum , NestedField , PartitionField , PartitionSpec , PrimitiveType , Schema , Transform , Type ,
239
+ UnboundPartitionField ,
239
240
} ;
240
241
241
242
fn build_test_schema ( ) -> Schema {
@@ -265,9 +266,8 @@ mod tests {
265
266
fn test_inclusive_projection_logic_ops ( ) {
266
267
let schema = build_test_schema ( ) ;
267
268
268
- let partition_spec = PartitionSpec :: builder ( )
269
+ let partition_spec = PartitionSpec :: builder ( & schema )
269
270
. with_spec_id ( 1 )
270
- . with_fields ( vec ! [ ] )
271
271
. build ( )
272
272
. unwrap ( ) ;
273
273
@@ -296,14 +296,17 @@ mod tests {
296
296
fn test_inclusive_projection_identity_transform ( ) {
297
297
let schema = build_test_schema ( ) ;
298
298
299
- let partition_spec = PartitionSpec :: builder ( )
299
+ let partition_spec = PartitionSpec :: builder ( & schema )
300
300
. with_spec_id ( 1 )
301
- . with_fields ( vec ! [ PartitionField :: builder( )
302
- . source_id( 1 )
303
- . name( "a" . to_string( ) )
304
- . field_id( 1 )
305
- . transform( Transform :: Identity )
306
- . build( ) ] )
301
+ . add_unbound_field (
302
+ UnboundPartitionField :: builder ( )
303
+ . source_id ( 1 )
304
+ . name ( "a" . to_string ( ) )
305
+ . partition_id ( 1 )
306
+ . transform ( Transform :: Identity )
307
+ . build ( ) ,
308
+ )
309
+ . unwrap ( )
307
310
. build ( )
308
311
. unwrap ( ) ;
309
312
@@ -330,30 +333,29 @@ mod tests {
330
333
fn test_inclusive_projection_date_transforms ( ) {
331
334
let schema = build_test_schema ( ) ;
332
335
333
- let partition_spec = PartitionSpec :: builder ( )
334
- . with_spec_id ( 1 )
335
- . with_fields ( vec ! [
336
- PartitionField :: builder( )
337
- . source_id( 2 )
338
- . name( "year" . to_string( ) )
339
- . field_id( 2 )
340
- . transform( Transform :: Year )
341
- . build( ) ,
342
- PartitionField :: builder( )
343
- . source_id( 2 )
344
- . name( "month" . to_string( ) )
345
- . field_id( 2 )
346
- . transform( Transform :: Month )
347
- . build( ) ,
348
- PartitionField :: builder( )
349
- . source_id( 2 )
350
- . name( "day" . to_string( ) )
351
- . field_id( 2 )
352
- . transform( Transform :: Day )
353
- . build( ) ,
354
- ] )
355
- . build ( )
356
- . unwrap ( ) ;
336
+ let partition_spec = PartitionSpec {
337
+ spec_id : 1 ,
338
+ fields : vec ! [
339
+ PartitionField {
340
+ source_id: 2 ,
341
+ name: "year" . to_string( ) ,
342
+ field_id: 1000 ,
343
+ transform: Transform :: Year ,
344
+ } ,
345
+ PartitionField {
346
+ source_id: 2 ,
347
+ name: "month" . to_string( ) ,
348
+ field_id: 1001 ,
349
+ transform: Transform :: Month ,
350
+ } ,
351
+ PartitionField {
352
+ source_id: 2 ,
353
+ name: "day" . to_string( ) ,
354
+ field_id: 1002 ,
355
+ transform: Transform :: Day ,
356
+ } ,
357
+ ] ,
358
+ } ;
357
359
358
360
let arc_schema = Arc :: new ( schema) ;
359
361
let arc_partition_spec = Arc :: new ( partition_spec) ;
@@ -378,14 +380,17 @@ mod tests {
378
380
fn test_inclusive_projection_truncate_transform ( ) {
379
381
let schema = build_test_schema ( ) ;
380
382
381
- let partition_spec = PartitionSpec :: builder ( )
383
+ let partition_spec = PartitionSpec :: builder ( & schema )
382
384
. with_spec_id ( 1 )
383
- . with_fields ( vec ! [ PartitionField :: builder( )
384
- . source_id( 3 )
385
- . name( "name" . to_string( ) )
386
- . field_id( 3 )
387
- . transform( Transform :: Truncate ( 4 ) )
388
- . build( ) ] )
385
+ . add_unbound_field (
386
+ UnboundPartitionField :: builder ( )
387
+ . source_id ( 3 )
388
+ . name ( "name_truncate" . to_string ( ) )
389
+ . partition_id ( 3 )
390
+ . transform ( Transform :: Truncate ( 4 ) )
391
+ . build ( ) ,
392
+ )
393
+ . unwrap ( )
389
394
. build ( )
390
395
. unwrap ( ) ;
391
396
@@ -398,15 +403,15 @@ mod tests {
398
403
399
404
// applying InclusiveProjection to bound_predicate
400
405
// should result in the 'name STARTS WITH "Testy McTest"'
401
- // predicate being transformed to 'name STARTS WITH "Test"',
406
+ // predicate being transformed to 'name_truncate STARTS WITH "Test"',
402
407
// since a `Truncate(4)` partition will map values of
403
408
// name that start with "Testy McTest" into a partition
404
409
// for values of name that start with the first four letters
405
410
// of that, ie "Test".
406
411
let mut inclusive_projection = InclusiveProjection :: new ( arc_partition_spec. clone ( ) ) ;
407
412
let result = inclusive_projection. project ( & bound_predicate) . unwrap ( ) ;
408
413
409
- let expected = "name STARTS WITH \" Test\" " . to_string ( ) ;
414
+ let expected = "name_truncate STARTS WITH \" Test\" " . to_string ( ) ;
410
415
411
416
assert_eq ! ( result. to_string( ) , expected)
412
417
}
@@ -415,14 +420,17 @@ mod tests {
415
420
fn test_inclusive_projection_bucket_transform ( ) {
416
421
let schema = build_test_schema ( ) ;
417
422
418
- let partition_spec = PartitionSpec :: builder ( )
423
+ let partition_spec = PartitionSpec :: builder ( & schema )
419
424
. with_spec_id ( 1 )
420
- . with_fields ( vec ! [ PartitionField :: builder( )
421
- . source_id( 1 )
422
- . name( "a" . to_string( ) )
423
- . field_id( 1 )
424
- . transform( Transform :: Bucket ( 7 ) )
425
- . build( ) ] )
425
+ . add_unbound_field (
426
+ UnboundPartitionField :: builder ( )
427
+ . source_id ( 1 )
428
+ . name ( "a_bucket[7]" . to_string ( ) )
429
+ . partition_id ( 1 )
430
+ . transform ( Transform :: Bucket ( 7 ) )
431
+ . build ( ) ,
432
+ )
433
+ . unwrap ( )
426
434
. build ( )
427
435
. unwrap ( ) ;
428
436
@@ -440,7 +448,7 @@ mod tests {
440
448
let mut inclusive_projection = InclusiveProjection :: new ( arc_partition_spec. clone ( ) ) ;
441
449
let result = inclusive_projection. project ( & bound_predicate) . unwrap ( ) ;
442
450
443
- let expected = "a = 2" . to_string ( ) ;
451
+ let expected = "a_bucket[7] = 2" . to_string ( ) ;
444
452
445
453
assert_eq ! ( result. to_string( ) , expected)
446
454
}
0 commit comments