private static Writable readDatum()

in odps-sdk/odps-sdk-commons/src/main/java/com/aliyun/odps/io/TupleReaderWriter.java [212:296]


  private static Writable readDatum(DataInput in, byte type) throws IOException {
    switch (type) {
      case TUPLE:
        int sz = in.readInt();
        // if sz == 0, we construct an "empty" tuple -
        // presumably the writer wrote an empty tuple!
        if (sz < 0) {
          throw new IOException("Invalid size " + sz + " for a tuple");
        }
        Tuple tp = new Tuple(sz);
        for (int i = 0; i < sz; i++) {
          byte b = in.readByte();
          tp.set(i, readDatum(in, b));
        }

        return tp;

      case NULL:
        return null;

      case INTWRITABLE:
        IntWritable iw = new IntWritable();
        iw.readFields(in);
        return iw;

      case LONGWRITABLE:
        LongWritable lw = new LongWritable();
        lw.readFields(in);
        return lw;

      case DATETIMEWRITABLE:
        DatetimeWritable dtw = new DatetimeWritable();
        dtw.readFields(in);
        return dtw;

      case DOUBLEWRITABLE:
        DoubleWritable dw = new DoubleWritable();
        dw.readFields(in);
        return dw;

      case BOOLEANWRITABLE:
        BooleanWritable bw = new BooleanWritable();
        bw.readFields(in);
        return bw;

      case BYTESWRITABLE:
        BytesWritable bsw = new BytesWritable();
        bsw.readFields(in);
        return bsw;

      case TEXT:
        Text t = new Text();
        t.readFields(in);
        return t;

      case NULLWRITABLE:
        NullWritable nw = NullWritable.get();
        nw.readFields(in);
        return nw;

      case UNKNOWN:
        String clsName = in.readUTF();
        try {
          Class<? extends Writable> cls;
          ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
          if (classLoader != null) {
            cls = (Class<? extends Writable>) Class.forName(clsName, true, classLoader);
          } else {
            cls = (Class<? extends Writable>) Class.forName(clsName);
          }
          Writable w = (Writable) ReflectionUtils.newInstance(cls, null);
          w.readFields(in);
          return w;
        } catch (RuntimeException re) {
          LOG.info(re.getMessage());
          throw new IOException(re);
        } catch (ClassNotFoundException cnfe) {
          throw new IOException(cnfe);
        }

      default:
        throw new RuntimeException("Unexpected data type " + type
                                   + " found in stream.");
    }
  }