public void testLazyLongWrite() throws Throwable {
    try {
      ByteStream.Output out = new ByteStream.Output();

      long[] tests = {
        0L,
        -1,
        1,
        -10,
        10,
        -123,
        123,
        Long.MIN_VALUE,
        Long.MIN_VALUE + 1,
        Long.MAX_VALUE,
        Long.MAX_VALUE - 1
      };
      for (long v : tests) {
        out.reset();
        LazyLong.writeUTF8(out, v);
        Text t = new Text();
        t.set(out.getData(), 0, out.getCount());
        assertEquals(String.valueOf(v), t.toString());
      }

    } catch (Throwable e) {
      e.printStackTrace();
      throw e;
    }
  }
  private byte[] getConstantVal(Object writable, PrimitiveObjectInspector poi, boolean isKeyBinary)
      throws IOException {

    if (!isKeyBinary) {
      // Key is stored in text format. Get bytes representation of constant also of
      // text format.
      byte[] startRow;
      ByteStream.Output serializeStream = new ByteStream.Output();
      LazyUtils.writePrimitiveUTF8(serializeStream, writable, poi, false, (byte) 0, null);
      startRow = new byte[serializeStream.getLength()];
      System.arraycopy(serializeStream.getData(), 0, startRow, 0, serializeStream.getLength());
      return startRow;
    }

    PrimitiveCategory pc = poi.getPrimitiveCategory();
    switch (poi.getPrimitiveCategory()) {
      case INT:
        return Bytes.toBytes(((IntWritable) writable).get());
      case BOOLEAN:
        return Bytes.toBytes(((BooleanWritable) writable).get());
      case LONG:
        return Bytes.toBytes(((LongWritable) writable).get());
      case FLOAT:
        return Bytes.toBytes(((FloatWritable) writable).get());
      case DOUBLE:
        return Bytes.toBytes(((DoubleWritable) writable).get());
      case SHORT:
        return Bytes.toBytes(((ShortWritable) writable).get());
      case STRING:
        return Bytes.toBytes(((Text) writable).toString());
      case BYTE:
        return Bytes.toBytes(((ByteWritable) writable).get());

      default:
        throw new IOException("Type not supported " + pc);
    }
  }