private Object readField()

in odps-sdk/odps-sdk-core/src/main/java/com/aliyun/odps/commons/proto/ProtobufRecordStreamReader.java [282:396]


  private Object readField(TypeInfo type) throws IOException {
    switch (type.getOdpsType()) {
      case DOUBLE: {
        double v = in.readDouble();
        crc.update(v);
        return v;
      }
      case FLOAT: {
        float v = in.readFloat();
        crc.update(v);
        return v;
      }
      case BOOLEAN: {
        boolean v = in.readBool();
        crc.update(v);
        return v;
      }
      case BIGINT: {
        long v = in.readSInt64();
        crc.update(v);
        return v;
      }
      case INTERVAL_YEAR_MONTH: {
        long v = in.readSInt64();
        crc.update(v);
        return new IntervalYearMonth((int) v);
      }
      case INT: {
        long v = in.readSInt64();
        crc.update(v);
        return (int)v;
      }
      case SMALLINT: {
        long v = in.readSInt64();
        crc.update(v);
        return (short) v;
      }
      case TINYINT: {
        long v = in.readSInt64();
        crc.update(v);
        return (byte) v;
      }
      case JSON: {
        return new SimpleJsonValue(readString());
      }
      case STRING: {
        return readBytes();
      }
      case VARCHAR: {
        return new Varchar(readString());
      }
      case CHAR: {
        return new Char(readString());
      }
      case BINARY:{
        return new Binary(readBytes());
      }
      case DATETIME:{
        long v = in.readSInt64();
        crc.update(v);
        return shouldTransform ? DateUtils.ms2date(v, DateUtils.LOCAL_CAL).toInstant().atZone(ZoneId.systemDefault()) :
               Instant.ofEpochMilli(v).atZone(ZoneId.systemDefault());
      }
      case DATE: {
        long v = in.readSInt64();
        crc.update(v);
        // translate to sql.date
        return LocalDate.ofEpochDay(v);
      }
      case INTERVAL_DAY_TIME: {
        long time = in.readSInt64();
        int nano = in.readSInt32();
        crc.update(time);
        crc.update(nano);
        return new IntervalDayTime(time, nano);
      }
      case TIMESTAMP_NTZ: {
        long time = in.readSInt64();
        int nano = in.readSInt32();
        crc.update(time);
        crc.update(nano);
        return LocalDateTime.ofEpochSecond(time, nano, ZoneOffset.UTC);
      }
      case TIMESTAMP: {
        long time = in.readSInt64();
        int nano = in.readSInt32();
        crc.update(time);
        crc.update(nano);
        return Instant.ofEpochSecond(time, nano);
      }
      case DECIMAL: {
        int size = in.readRawVarint32();
        byte[] bytes = in.readRawBytes(size);
        crc.update(bytes, 0, bytes.length);
        try {
          return new BigDecimal(new String(bytes, "UTF-8"));
        } catch (Exception e) {
          // if decimal is inf or nan, return null
          return null;
        }
      }
      case ARRAY: {
        return readArray(((ArrayTypeInfo) type).getElementTypeInfo());
      }
      case MAP: {
        MapTypeInfo mapTypeInfo = (MapTypeInfo) type;
        return readMap(mapTypeInfo.getKeyTypeInfo(), mapTypeInfo.getValueTypeInfo());
      }
      case STRUCT: {
        return readStruct(type);
      }
      default:
        throw new IOException("Unsupported type " + type.getTypeName());
    }
  }