public TypeInfo fromGravitino()

in catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/converter/HiveDataTypeConverter.java [65:134]


  public TypeInfo fromGravitino(Type type) {
    switch (type.name()) {
      case BOOLEAN:
        return getPrimitiveTypeInfo(BOOLEAN_TYPE_NAME);
      case BYTE:
        return getPrimitiveTypeInfo(TINYINT_TYPE_NAME);
      case SHORT:
        return getPrimitiveTypeInfo(SMALLINT_TYPE_NAME);
      case INTEGER:
        return getPrimitiveTypeInfo(INT_TYPE_NAME);
      case LONG:
        return getPrimitiveTypeInfo(BIGINT_TYPE_NAME);
      case FLOAT:
        return getPrimitiveTypeInfo(FLOAT_TYPE_NAME);
      case DOUBLE:
        return getPrimitiveTypeInfo(DOUBLE_TYPE_NAME);
      case STRING:
        return getPrimitiveTypeInfo(STRING_TYPE_NAME);
      case VARCHAR:
        return getVarcharTypeInfo(((Types.VarCharType) type).length());
      case FIXEDCHAR:
        return getCharTypeInfo(((Types.FixedCharType) type).length());
      case DATE:
        return getPrimitiveTypeInfo(DATE_TYPE_NAME);
      case TIMESTAMP:
        if (type instanceof Types.TimestampType) {
          Types.TimestampType tsType = (Types.TimestampType) type;
          // Timestamps are interpreted to be timezoneless in Hive:
          // https://hive.apache.org/docs/latest/languagemanual-types_27838462/#timestamps
          if (tsType.hasTimeZone()) {
            throw new UnsupportedOperationException(
                "Unsupported conversion: Please use the TIMESTAMP WITHOUT TIMEZONE type. TIMESTAMP WITH TIMEZONE type is not supported by Hive.");
          }
          return getPrimitiveTypeInfo(TIMESTAMP_TYPE_NAME);
        }
        throw new UnsupportedOperationException("Unknown timestamp type: " + type);
      case DECIMAL:
        Types.DecimalType decimalType = (Types.DecimalType) type;
        return getDecimalTypeInfo(decimalType.precision(), decimalType.scale());
      case BINARY:
        return getPrimitiveTypeInfo(BINARY_TYPE_NAME);
      case INTERVAL_YEAR:
        return getPrimitiveTypeInfo(INTERVAL_YEAR_MONTH_TYPE_NAME);
      case INTERVAL_DAY:
        return getPrimitiveTypeInfo(INTERVAL_DAY_TIME_TYPE_NAME);
      case LIST:
        return getListTypeInfo(fromGravitino(((Types.ListType) type).elementType()));
      case MAP:
        Types.MapType mapType = (Types.MapType) type;
        return getMapTypeInfo(fromGravitino(mapType.keyType()), fromGravitino(mapType.valueType()));
      case STRUCT:
        Types.StructType structType = (Types.StructType) type;
        List<TypeInfo> typeInfos =
            Arrays.stream(structType.fields())
                .map(t -> fromGravitino(t.type()))
                .collect(Collectors.toList());
        List<String> names =
            Arrays.stream(structType.fields())
                .map(Types.StructType.Field::name)
                .collect(Collectors.toList());
        return getStructTypeInfo(names, typeInfos);
      case UNION:
        return getUnionTypeInfo(
            Arrays.stream(((Types.UnionType) type).types())
                .map(this::fromGravitino)
                .collect(Collectors.toList()));
      default:
        throw new UnsupportedOperationException("Unsupported conversion to Hive type: " + type);
    }
  }