ArrowSchemaUtil.java org::apache::iceberg::arrow::ArrowSchemaUtil org::apache::iceberg::arrow /* *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.arrow; importjava.util.List; importjava.util.Map; importorg.apache.arrow.vector.types.DateUnit; importorg.apache.arrow.vector.types.FloatingPointPrecision; importorg.apache.arrow.vector.types.TimeUnit; importorg.apache.arrow.vector.types.pojo.ArrowType; importorg.apache.arrow.vector.types.pojo.Field; importorg.apache.arrow.vector.types.pojo.FieldType; importorg.apache.arrow.vector.types.pojo.Schema; importorg.apache.iceberg.relocated.com.google.common.collect.ImmutableList; importorg.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; importorg.apache.iceberg.relocated.com.google.common.collect.Lists; importorg.apache.iceberg.types.Types; importorg.apache.iceberg.types.Types.ListType; importorg.apache.iceberg.types.Types.MapType; importorg.apache.iceberg.types.Types.NestedField; importorg.apache.iceberg.types.Types.StructType; publicclassArrowSchemaUtil{ privatestaticfinalStringORIGINAL_TYPE="originalType"; privatestaticfinalStringMAP_TYPE="mapType"; privateArrowSchemaUtil(){} publicstaticSchemaconvert(finalorg.apache.iceberg.Schemaschema){ ImmutableList.Builder<Field>fields=ImmutableList.builder(); for(NestedFieldf:schema.columns()){ fields.add(convert(f)); } returnnewSchema(fields.build()); } publicstaticFieldconvert(finalNestedFieldfield){ finalArrowTypearrowType; finalList<Field>children=Lists.newArrayList(); Map<String,String>metadata=null; switch(field.type().typeId()){ caseBINARY: arrowType=ArrowType.Binary.INSTANCE; break; caseFIXED: finalTypes.FixedTypefixedType=(Types.FixedType)field.type(); arrowType=newArrowType.FixedSizeBinary(fixedType.length()); break; caseBOOLEAN: arrowType=ArrowType.Bool.INSTANCE; break; caseINTEGER: arrowType=newArrowType.Int(Integer.SIZE,true/*signed*/); break; caseLONG: arrowType=newArrowType.Int(Long.SIZE,true/*signed*/); break; caseFLOAT: arrowType=newArrowType.FloatingPoint(FloatingPointPrecision.SINGLE); break; caseDOUBLE: arrowType=newArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE); break; caseDECIMAL: finalTypes.DecimalTypedecimalType=(Types.DecimalType)field.type(); arrowType=newArrowType.Decimal(decimalType.precision(),decimalType.scale()); break; caseSTRING: arrowType=ArrowType.Utf8.INSTANCE; break; caseTIME: arrowType=newArrowType.Time(TimeUnit.MICROSECOND,Long.SIZE); break; caseUUID: arrowType=newArrowType.FixedSizeBinary(16); break; caseTIMESTAMP: arrowType= newArrowType.Timestamp( TimeUnit.MICROSECOND, ((Types.TimestampType)field.type()).shouldAdjustToUTC()?"UTC":null); break; caseDATE: arrowType=newArrowType.Date(DateUnit.DAY); break; caseSTRUCT: finalStructTypestruct=field.type().asStructType(); arrowType=ArrowType.Struct.INSTANCE; for(NestedFieldnested:struct.fields()){ children.add(convert(nested)); } break; caseLIST: finalListTypelistType=field.type().asListType(); arrowType=ArrowType.List.INSTANCE; for(NestedFieldnested:listType.fields()){ children.add(convert(nested)); } break; caseMAP: metadata=ImmutableMap.of(ORIGINAL_TYPE,MAP_TYPE); finalMapTypemapType=field.type().asMapType(); arrowType=newArrowType.Map(false); List<Field>entryFields=Lists.transform(mapType.fields(),ArrowSchemaUtil::convert); Fieldentry= newField("",newFieldType(field.isOptional(),arrowType,null),entryFields); children.add(entry); break; default: thrownewUnsupportedOperationException("Unsupportedfieldtype:"+field); } returnnewField( field.name(),newFieldType(field.isOptional(),arrowType,null,metadata),children); } }