public static Field convert()

in arrow/src/main/java/org/apache/iceberg/arrow/ArrowSchemaUtil.java [61:143]


  public static Field convert(final NestedField field) {
    final ArrowType arrowType;

    final List<Field> children = Lists.newArrayList();
    Map<String, String> metadata = null;

    switch (field.type().typeId()) {
      case BINARY:
        arrowType = ArrowType.Binary.INSTANCE;
        break;
      case FIXED:
        final Types.FixedType fixedType = (Types.FixedType) field.type();
        arrowType = new ArrowType.FixedSizeBinary(fixedType.length());
        break;
      case BOOLEAN:
        arrowType = ArrowType.Bool.INSTANCE;
        break;
      case INTEGER:
        arrowType = new ArrowType.Int(Integer.SIZE, true /* signed */);
        break;
      case LONG:
        arrowType = new ArrowType.Int(Long.SIZE, true /* signed */);
        break;
      case FLOAT:
        arrowType = new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE);
        break;
      case DOUBLE:
        arrowType = new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE);
        break;
      case DECIMAL:
        final Types.DecimalType decimalType = (Types.DecimalType) field.type();
        arrowType = new ArrowType.Decimal(decimalType.precision(), decimalType.scale());
        break;
      case STRING:
        arrowType = ArrowType.Utf8.INSTANCE;
        break;
      case TIME:
        arrowType = new ArrowType.Time(TimeUnit.MICROSECOND, Long.SIZE);
        break;
      case UUID:
        arrowType = new ArrowType.FixedSizeBinary(16);
        break;
      case TIMESTAMP:
        arrowType =
            new ArrowType.Timestamp(
                TimeUnit.MICROSECOND,
                ((Types.TimestampType) field.type()).shouldAdjustToUTC() ? "UTC" : null);
        break;
      case DATE:
        arrowType = new ArrowType.Date(DateUnit.DAY);
        break;
      case STRUCT:
        final StructType struct = field.type().asStructType();
        arrowType = ArrowType.Struct.INSTANCE;

        for (NestedField nested : struct.fields()) {
          children.add(convert(nested));
        }
        break;
      case LIST:
        final ListType listType = field.type().asListType();
        arrowType = ArrowType.List.INSTANCE;

        for (NestedField nested : listType.fields()) {
          children.add(convert(nested));
        }
        break;
      case MAP:
        metadata = ImmutableMap.of(ORIGINAL_TYPE, MAP_TYPE);
        final MapType mapType = field.type().asMapType();
        arrowType = new ArrowType.Map(false);
        List<Field> entryFields = Lists.transform(mapType.fields(), ArrowSchemaUtil::convert);
        Field entry =
            new Field("", new FieldType(field.isOptional(), arrowType, null), entryFields);
        children.add(entry);
        break;
      default:
        throw new UnsupportedOperationException("Unsupported field type: " + field);
    }

    return new Field(
        field.name(), new FieldType(field.isOptional(), arrowType, null, metadata), children);
  }