AssignIds.java org::apache::iceberg::types::AssignIds org::apache::iceberg::types /* *LicensedtotheApacheSoftwareFoundation(ASF)underone *ormorecontributorlicenseagreements.SeetheNOTICEfile *distributedwiththisworkforadditionalinformation *regardingcopyrightownership.TheASFlicensesthisfile *toyouundertheApacheLicense,Version2.0(the *"License");youmaynotusethisfileexceptincompliance *withtheLicense.YoumayobtainacopyoftheLicenseat * *http://www.apache.org/licenses/LICENSE-2.0 * *Unlessrequiredbyapplicablelaworagreedtoinwriting, *softwaredistributedundertheLicenseisdistributedonan *"ASIS"BASIS,WITHOUTWARRANTIESORCONDITIONSOFANY *KIND,eitherexpressorimplied.SeetheLicenseforthe *specificlanguagegoverningpermissionsandlimitations *undertheLicense. */ packageorg.apache.iceberg.types; importjava.util.Iterator; importjava.util.List; importjava.util.function.Supplier; importorg.apache.iceberg.Schema; importorg.apache.iceberg.relocated.com.google.common.collect.Lists; classAssignIdsextendsTypeUtil.CustomOrderSchemaVisitor<Type>{ privatefinalTypeUtil.GetIDgetID; AssignIds(TypeUtil.GetIDgetID){ this.getID=getID; } privateintidFor(intid){ returngetID.get(id); } @Override publicTypeschema(Schemaschema,Supplier<Type>future){ returnfuture.get(); } @Override publicTypestruct(Types.StructTypestruct,Iterable<Type>futures){ List<Types.NestedField>fields=struct.fields(); intlength=struct.fields().size(); //assignIDsforthisstruct'sfieldsfirst List<Integer>newIds=Lists.newArrayListWithExpectedSize(length); for(Types.NestedFieldfield:fields){ newIds.add(idFor(field.fieldId())); } List<Types.NestedField>newFields=Lists.newArrayListWithExpectedSize(length); Iterator<Type>types=futures.iterator(); for(inti=0;i<length;i+=1){ Types.NestedFieldfield=fields.get(i); Typetype=types.next(); if(field.isOptional()){ newFields.add(Types.NestedField.optional(newIds.get(i),field.name(),type,field.doc())); }else{ newFields.add(Types.NestedField.required(newIds.get(i),field.name(),type,field.doc())); } } returnTypes.StructType.of(newFields); } @Override publicTypefield(Types.NestedFieldfield,Supplier<Type>future){ returnfuture.get(); } @Override publicTypelist(Types.ListTypelist,Supplier<Type>future){ intnewId=idFor(list.elementId()); if(list.isElementOptional()){ returnTypes.ListType.ofOptional(newId,future.get()); }else{ returnTypes.ListType.ofRequired(newId,future.get()); } } @Override publicTypemap(Types.MapTypemap,Supplier<Type>keyFuture,Supplier<Type>valueFuture){ intnewKeyId=idFor(map.keyId()); intnewValueId=idFor(map.valueId()); if(map.isValueOptional()){ returnTypes.MapType.ofOptional(newKeyId,newValueId,keyFuture.get(),valueFuture.get()); }else{ returnTypes.MapType.ofRequired(newKeyId,newValueId,keyFuture.get(),valueFuture.get()); } } @Override publicTypeprimitive(Type.PrimitiveTypeprimitive){ returnprimitive; } }