public Optional primitive()

in orc/src/main/java/org/apache/iceberg/orc/OrcToIcebergVisitor.java [126:198]


  public Optional<Types.NestedField> primitive(TypeDescription primitive) {
    boolean isOptional = ORCSchemaUtil.isOptional(primitive);
    Optional<Integer> icebergIdOpt = ORCSchemaUtil.icebergID(primitive);

    if (!icebergIdOpt.isPresent()) {
      return Optional.empty();
    }

    Types.NestedField.Builder builder =
        Types.NestedField.builder()
            .withId(icebergIdOpt.get())
            .isOptional(isOptional)
            .withName(currentFieldName());
    switch (primitive.getCategory()) {
      case BOOLEAN:
        builder.ofType(Types.BooleanType.get());
        break;
      case BYTE:
      case SHORT:
      case INT:
        builder.ofType(Types.IntegerType.get());
        break;
      case LONG:
        convertLong(primitive, builder);
        break;
      case FLOAT:
        builder.ofType(Types.FloatType.get());
        break;
      case DOUBLE:
        builder.ofType(Types.DoubleType.get());
        break;
      case STRING:
      case CHAR:
      case VARCHAR:
        builder.ofType(Types.StringType.get());
        break;
      case BINARY:
        convertBinary(primitive, builder);
        break;
      case DATE:
        builder.ofType(Types.DateType.get());
        break;
      case TIMESTAMP:
        String unit = primitive.getAttributeValue(ORCSchemaUtil.TIMESTAMP_UNIT);
        if (unit == null || ORCSchemaUtil.MICROS.equalsIgnoreCase(unit)) {
          builder.ofType(Types.TimestampType.withoutZone());
        } else if (unit.equalsIgnoreCase(ORCSchemaUtil.NANOS)) {
          builder.ofType(Types.TimestampNanoType.withoutZone());
        } else {
          throw new IllegalStateException("Invalid Timestamp type unit: %s" + unit);
        }

        break;
      case TIMESTAMP_INSTANT:
        String tsUnit = primitive.getAttributeValue(ORCSchemaUtil.TIMESTAMP_UNIT);
        if (tsUnit == null || ORCSchemaUtil.MICROS.equalsIgnoreCase(tsUnit)) {
          builder.ofType(Types.TimestampType.withZone());
        } else if (tsUnit.equalsIgnoreCase(ORCSchemaUtil.NANOS)) {
          builder.ofType(Types.TimestampNanoType.withZone());
        } else {
          throw new IllegalStateException("Invalid Timestamp type unit: %s" + tsUnit);
        }

        break;
      case DECIMAL:
        builder.ofType(Types.DecimalType.of(primitive.getPrecision(), primitive.getScale()));
        break;
      default:
        throw new IllegalArgumentException("Can't handle " + primitive);
    }

    return Optional.of(builder.build());
  }