public Type getTrinoType()

in trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/util/GeneralDataTypeTransformer.java [58:130]


  public Type getTrinoType(org.apache.gravitino.rel.types.Type type) {
    switch (type.name()) {
      case BOOLEAN:
        return BOOLEAN;
      case BYTE:
        if (((Types.ByteType) type).signed()) {
          return TinyintType.TINYINT;
        } else {
          return SmallintType.SMALLINT;
        }
      case SHORT:
        if (((Types.ShortType) type).signed()) {
          return SmallintType.SMALLINT;
        } else {
          return INTEGER;
        }
      case INTEGER:
        if (((Types.IntegerType) type).signed()) {
          return INTEGER;
        } else {
          return BIGINT;
        }
      case LONG:
        if (((Types.LongType) type).signed()) {
          return BIGINT;
        } else {
          return io.trino.spi.type.DecimalType.createDecimalType(20, 0);
        }
      case FLOAT:
        return RealType.REAL;
      case DOUBLE:
        return DOUBLE;
      case DECIMAL:
        DecimalType decimalType = (DecimalType) type;
        return io.trino.spi.type.DecimalType.createDecimalType(
            decimalType.precision(), decimalType.scale());
      case FIXEDCHAR:
        return CharType.createCharType(((Types.FixedCharType) type).length());
      case STRING:
        return VARCHAR;
      case VARCHAR:
        return VarcharType.createVarcharType(((Types.VarCharType) type).length());
      case BINARY:
        return VARBINARY;
      case DATE:
        return DATE;
      case TIME:
        return TimeType.TIME_MILLIS;
      case TIMESTAMP:
        if (((Types.TimestampType) type).hasTimeZone()) {
          return TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS;
        } else {
          return TimestampType.TIMESTAMP_MILLIS;
        }
      case LIST:
        return new ArrayType(getTrinoType(((Types.ListType) type).elementType()));
      case MAP:
        Types.MapType mapType = (Types.MapType) type;
        return new MapType(
            getTrinoType(mapType.keyType()),
            getTrinoType(mapType.valueType()),
            new TypeOperators());
      case STRUCT:
        Types.StructType structType = (Types.StructType) type;
        return gravitinoRowTypeToTrinoRowType(structType);
      case UUID:
        return UuidType.UUID;
      default:
        throw new TrinoException(
            GravitinoErrorCode.GRAVITINO_UNSUPPORTED_GRAVITINO_DATATYPE,
            "Unsupported gravitino datatype: " + type);
    }
  }