1919package org .apache .iceberg ;
2020
2121import java .util .List ;
22+ import org .apache .iceberg .relocated .com .google .common .base .Preconditions ;
2223import org .apache .iceberg .relocated .com .google .common .collect .Lists ;
2324import org .apache .iceberg .transforms .Transform ;
2425import org .apache .iceberg .transforms .Transforms ;
@@ -54,17 +55,17 @@ private PartitionSpec.Builder copyToBuilder(Schema schema) {
5455 PartitionSpec .Builder builder = PartitionSpec .builderFor (schema ).withSpecId (specId );
5556
5657 for (UnboundPartitionField field : fields ) {
57- Type fieldType = schema .findType (field .sourceId );
58+ Type fieldType = schema .findType (field .sourceIds . get ( 0 ) );
5859 Transform <?, ?> transform ;
5960 if (fieldType != null ) {
6061 transform = Transforms .fromString (fieldType , field .transform .toString ());
6162 } else {
6263 transform = Transforms .fromString (field .transform .toString ());
6364 }
6465 if (field .partitionId != null ) {
65- builder .add (field .sourceId , field .partitionId , field .name , transform );
66+ builder .add (field .sourceIds , field .partitionId , field .name , transform );
6667 } else {
67- builder .add (field .sourceId , field .name , transform );
68+ builder .add (field .sourceIds , field .name , transform );
6869 }
6970 }
7071
@@ -88,14 +89,23 @@ Builder withSpecId(int newSpecId) {
8889 return this ;
8990 }
9091
92+ Builder addField (
93+ String transformAsString , List <Integer > sourceIds , int partitionId , String name ) {
94+ fields .add (new UnboundPartitionField (transformAsString , sourceIds , partitionId , name ));
95+ return this ;
96+ }
97+
9198 Builder addField (String transformAsString , int sourceId , int partitionId , String name ) {
92- fields .add (new UnboundPartitionField (transformAsString , sourceId , partitionId , name ));
99+ return addField (transformAsString , List .of (sourceId ), partitionId , name );
100+ }
101+
102+ Builder addField (String transformAsString , List <Integer > sourceIds , String name ) {
103+ fields .add (new UnboundPartitionField (transformAsString , sourceIds , null , name ));
93104 return this ;
94105 }
95106
96107 Builder addField (String transformAsString , int sourceId , String name ) {
97- fields .add (new UnboundPartitionField (transformAsString , sourceId , null , name ));
98- return this ;
108+ return addField (transformAsString , List .of (sourceId ), name );
99109 }
100110
101111 UnboundPartitionSpec build () {
@@ -105,7 +115,7 @@ UnboundPartitionSpec build() {
105115
106116 static class UnboundPartitionField {
107117 private final Transform <?, ?> transform ;
108- private final int sourceId ;
118+ private final List < Integer > sourceIds ;
109119 private final Integer partitionId ;
110120 private final String name ;
111121
@@ -118,7 +128,12 @@ public String transformAsString() {
118128 }
119129
120130 public int sourceId () {
121- return sourceId ;
131+ Preconditions .checkArgument (sourceIds .size () == 1 , "Only one source is expected" );
132+ return sourceIds .get (0 );
133+ }
134+
135+ public List <Integer > sourceIds () {
136+ return sourceIds ;
122137 }
123138
124139 public Integer partitionId () {
@@ -130,9 +145,9 @@ public String name() {
130145 }
131146
132147 private UnboundPartitionField (
133- String transformAsString , int sourceId , Integer partitionId , String name ) {
148+ String transformAsString , List < Integer > sourceIds , Integer partitionId , String name ) {
134149 this .transform = Transforms .fromString (transformAsString );
135- this .sourceId = sourceId ;
150+ this .sourceIds = sourceIds ;
136151 this .partitionId = partitionId ;
137152 this .name = name ;
138153 }
0 commit comments