@@ -371,6 +371,7 @@ public static class Builder {
371371 new AtomicInteger (unpartitionedLastAssignedId ());
372372 // check if there are conflicts between partition and schema field name
373373 private boolean checkConflicts = true ;
374+ private boolean caseSensitive = true ;
374375
375376 private Builder (Schema schema ) {
376377 this .schema = schema ;
@@ -390,7 +391,8 @@ Builder checkConflicts(boolean check) {
390391 }
391392
392393 private void checkAndAddPartitionName (String name , Integer sourceColumnId ) {
393- Types .NestedField schemaField = schema .findField (name );
394+ Types .NestedField schemaField =
395+ this .caseSensitive ? schema .findField (name ) : schema .caseInsensitiveFindField (name );
394396 if (checkConflicts ) {
395397 if (sourceColumnId != null ) {
396398 // for identity transform case we allow conflicts between partition and schema field name
@@ -427,20 +429,31 @@ private void checkForRedundantPartitions(PartitionField field) {
427429 dedupFields .put (dedupKey , field );
428430 }
429431
432+ public Builder caseSensitive (boolean sensitive ) {
433+ this .caseSensitive = sensitive ;
434+ return this ;
435+ }
436+
430437 public Builder withSpecId (int newSpecId ) {
431438 this .specId = newSpecId ;
432439 return this ;
433440 }
434441
435442 private Types .NestedField findSourceColumn (String sourceName ) {
436- Types .NestedField sourceColumn = schema .findField (sourceName );
443+ Types .NestedField sourceColumn =
444+ this .caseSensitive
445+ ? schema .findField (sourceName )
446+ : schema .caseInsensitiveFindField (sourceName );
437447 Preconditions .checkArgument (
438448 sourceColumn != null , "Cannot find source column: %s" , sourceName );
439449 return sourceColumn ;
440450 }
441451
442452 Builder identity (String sourceName , String targetName ) {
443- Types .NestedField sourceColumn = findSourceColumn (sourceName );
453+ return identity (findSourceColumn (sourceName ), targetName );
454+ }
455+
456+ private Builder identity (Types .NestedField sourceColumn , String targetName ) {
444457 checkAndAddPartitionName (targetName , sourceColumn .fieldId ());
445458 PartitionField field =
446459 new PartitionField (
@@ -451,12 +464,16 @@ Builder identity(String sourceName, String targetName) {
451464 }
452465
453466 public Builder identity (String sourceName ) {
454- return identity (sourceName , sourceName );
467+ Types .NestedField sourceColumn = findSourceColumn (sourceName );
468+ return identity (sourceColumn , schema .findColumnName (sourceColumn .fieldId ()));
455469 }
456470
457471 public Builder year (String sourceName , String targetName ) {
472+ return year (findSourceColumn (sourceName ), targetName );
473+ }
474+
475+ private Builder year (Types .NestedField sourceColumn , String targetName ) {
458476 checkAndAddPartitionName (targetName );
459- Types .NestedField sourceColumn = findSourceColumn (sourceName );
460477 PartitionField field =
461478 new PartitionField (sourceColumn .fieldId (), nextFieldId (), targetName , Transforms .year ());
462479 checkForRedundantPartitions (field );
@@ -465,12 +482,17 @@ public Builder year(String sourceName, String targetName) {
465482 }
466483
467484 public Builder year (String sourceName ) {
468- return year (sourceName , sourceName + "_year" );
485+ Types .NestedField sourceColumn = findSourceColumn (sourceName );
486+ String columnName = schema .findColumnName (sourceColumn .fieldId ());
487+ return year (sourceColumn , columnName + "_year" );
469488 }
470489
471490 public Builder month (String sourceName , String targetName ) {
491+ return month (findSourceColumn (sourceName ), targetName );
492+ }
493+
494+ private Builder month (Types .NestedField sourceColumn , String targetName ) {
472495 checkAndAddPartitionName (targetName );
473- Types .NestedField sourceColumn = findSourceColumn (sourceName );
474496 PartitionField field =
475497 new PartitionField (sourceColumn .fieldId (), nextFieldId (), targetName , Transforms .month ());
476498 checkForRedundantPartitions (field );
@@ -479,12 +501,17 @@ public Builder month(String sourceName, String targetName) {
479501 }
480502
481503 public Builder month (String sourceName ) {
482- return month (sourceName , sourceName + "_month" );
504+ Types .NestedField sourceColumn = findSourceColumn (sourceName );
505+ String columnName = schema .findColumnName (sourceColumn .fieldId ());
506+ return month (sourceColumn , columnName + "_month" );
483507 }
484508
485509 public Builder day (String sourceName , String targetName ) {
510+ return day (findSourceColumn (sourceName ), targetName );
511+ }
512+
513+ private Builder day (Types .NestedField sourceColumn , String targetName ) {
486514 checkAndAddPartitionName (targetName );
487- Types .NestedField sourceColumn = findSourceColumn (sourceName );
488515 PartitionField field =
489516 new PartitionField (sourceColumn .fieldId (), nextFieldId (), targetName , Transforms .day ());
490517 checkForRedundantPartitions (field );
@@ -493,12 +520,17 @@ public Builder day(String sourceName, String targetName) {
493520 }
494521
495522 public Builder day (String sourceName ) {
496- return day (sourceName , sourceName + "_day" );
523+ Types .NestedField sourceColumn = findSourceColumn (sourceName );
524+ String columnName = schema .findColumnName (sourceColumn .fieldId ());
525+ return day (sourceColumn , columnName + "_day" );
497526 }
498527
499528 public Builder hour (String sourceName , String targetName ) {
529+ return hour (findSourceColumn (sourceName ), targetName );
530+ }
531+
532+ private Builder hour (Types .NestedField sourceColumn , String targetName ) {
500533 checkAndAddPartitionName (targetName );
501- Types .NestedField sourceColumn = findSourceColumn (sourceName );
502534 PartitionField field =
503535 new PartitionField (sourceColumn .fieldId (), nextFieldId (), targetName , Transforms .hour ());
504536 checkForRedundantPartitions (field );
@@ -507,37 +539,52 @@ public Builder hour(String sourceName, String targetName) {
507539 }
508540
509541 public Builder hour (String sourceName ) {
510- return hour (sourceName , sourceName + "_hour" );
542+ Types .NestedField sourceColumn = findSourceColumn (sourceName );
543+ String columnName = schema .findColumnName (sourceColumn .fieldId ());
544+ return hour (sourceColumn , columnName + "_hour" );
511545 }
512546
513547 public Builder bucket (String sourceName , int numBuckets , String targetName ) {
548+ return bucket (findSourceColumn (sourceName ), numBuckets , targetName );
549+ }
550+
551+ private Builder bucket (Types .NestedField sourceColumn , int numBuckets , String targetName ) {
514552 checkAndAddPartitionName (targetName );
515- Types .NestedField sourceColumn = findSourceColumn (sourceName );
516553 fields .add (
517554 new PartitionField (
518555 sourceColumn .fieldId (), nextFieldId (), targetName , Transforms .bucket (numBuckets )));
519556 return this ;
520557 }
521558
522559 public Builder bucket (String sourceName , int numBuckets ) {
523- return bucket (sourceName , numBuckets , sourceName + "_bucket" );
560+ Types .NestedField sourceColumn = findSourceColumn (sourceName );
561+ String columnName = schema .findColumnName (sourceColumn .fieldId ());
562+ return bucket (sourceColumn , numBuckets , columnName + "_bucket" );
524563 }
525564
526565 public Builder truncate (String sourceName , int width , String targetName ) {
566+ return truncate (findSourceColumn (sourceName ), width , targetName );
567+ }
568+
569+ private Builder truncate (Types .NestedField sourceColumn , int width , String targetName ) {
527570 checkAndAddPartitionName (targetName );
528- Types .NestedField sourceColumn = findSourceColumn (sourceName );
529571 fields .add (
530572 new PartitionField (
531573 sourceColumn .fieldId (), nextFieldId (), targetName , Transforms .truncate (width )));
532574 return this ;
533575 }
534576
535577 public Builder truncate (String sourceName , int width ) {
536- return truncate (sourceName , width , sourceName + "_trunc" );
578+ Types .NestedField sourceColumn = findSourceColumn (sourceName );
579+ String columnName = schema .findColumnName (sourceColumn .fieldId ());
580+ return truncate (sourceColumn , width , columnName + "_trunc" );
537581 }
538582
539583 public Builder alwaysNull (String sourceName , String targetName ) {
540- Types .NestedField sourceColumn = findSourceColumn (sourceName );
584+ return alwaysNull (findSourceColumn (sourceName ), targetName );
585+ }
586+
587+ private Builder alwaysNull (Types .NestedField sourceColumn , String targetName ) {
541588 checkAndAddPartitionName (
542589 targetName , sourceColumn .fieldId ()); // can duplicate a source column name
543590 fields .add (
@@ -547,7 +594,9 @@ public Builder alwaysNull(String sourceName, String targetName) {
547594 }
548595
549596 public Builder alwaysNull (String sourceName ) {
550- return alwaysNull (sourceName , sourceName + "_null" );
597+ Types .NestedField sourceColumn = findSourceColumn (sourceName );
598+ String columnName = schema .findColumnName (sourceColumn .fieldId ());
599+ return alwaysNull (sourceColumn , columnName + "_null" );
551600 }
552601
553602 // add a partition field with an auto-increment partition field id starting from
0 commit comments