public void writeDatum()

in src/org/apache/pig/data/BinInterSedes.java [467:599]


    public void writeDatum(DataOutput out, Object val, byte type) throws IOException {
        switch (type) {
        case DataType.TUPLE:
            writeTuple(out, (Tuple) val);
            break;

        case DataType.BAG:
            writeBag(out, (DataBag) val);
            break;

        case DataType.MAP: {
            writeMap(out, (Map<String, Object>) val);
            break;
        }

        case DataType.INTERNALMAP: {
            out.writeByte(INTERNALMAP);
            Map<Object, Object> m = (Map<Object, Object>) val;
            out.writeInt(m.size());
            Iterator<Map.Entry<Object, Object>> i = m.entrySet().iterator();
            while (i.hasNext()) {
                Map.Entry<Object, Object> entry = i.next();
                writeDatum(out, entry.getKey());
                writeDatum(out, entry.getValue());
            }
            break;
        }

        case DataType.INTEGER:
            int i = (Integer) val;
            if (i == 0) {
                out.writeByte(INTEGER_0);
            } else if (i == 1) {
                out.writeByte(INTEGER_1);
            } else if (Byte.MIN_VALUE <= i && i <= Byte.MAX_VALUE) {
                out.writeByte(INTEGER_INBYTE);
                out.writeByte(i);
            } else if (Short.MIN_VALUE <= i && i <= Short.MAX_VALUE) {
                out.writeByte(INTEGER_INSHORT);
                out.writeShort(i);
            } else {
                out.writeByte(INTEGER);
                out.writeInt(i);
            }
            break;

        case DataType.LONG:
            long lng = (Long) val;
            if (lng == 0) {
                out.writeByte(LONG_0);
            } else if (lng == 1) {
                out.writeByte(LONG_1);
            } else if (Byte.MIN_VALUE <= lng && lng <= Byte.MAX_VALUE) {
                out.writeByte(LONG_INBYTE);
                out.writeByte((int)lng);
            } else if (Short.MIN_VALUE <= lng && lng <= Short.MAX_VALUE) {
                out.writeByte(LONG_INSHORT);
                out.writeShort((int)lng);
            } else if (Integer.MIN_VALUE <= lng && lng <= Integer.MAX_VALUE) {
                out.writeByte(LONG_ININT);
                out.writeInt((int)lng);
            } else {
            out.writeByte(LONG);
                out.writeLong(lng);
            }
            break;

        case DataType.DATETIME:
            out.writeByte(DATETIME);
            out.writeLong(((DateTime) val).getMillis());
            out.writeShort(((DateTime) val).getZone().getOffset((DateTime) val) / ONE_MINUTE);
            break;

        case DataType.FLOAT:
            out.writeByte(FLOAT);
            out.writeFloat((Float) val);
            break;

        case DataType.BIGINTEGER:
            out.writeByte(BIGINTEGER);
            writeBigInteger(out, (BigInteger)val);
            break;

        case DataType.BIGDECIMAL:
            out.writeByte(BIGDECIMAL);
            writeBigDecimal(out, (BigDecimal)val);
            break;

        case DataType.DOUBLE:
            out.writeByte(DOUBLE);
            out.writeDouble((Double) val);
            break;

        case DataType.BOOLEAN:
            if ((Boolean) val)
                out.writeByte(BOOLEAN_TRUE);
            else
                out.writeByte(BOOLEAN_FALSE);
            break;

        case DataType.BYTE:
            out.writeByte(BYTE);
            out.writeByte((Byte) val);
            break;

        case DataType.BYTEARRAY: {
            DataByteArray bytes = (DataByteArray) val;
            SedesHelper.writeBytes(out, bytes.mData);
            break;

        }

        case DataType.CHARARRAY: {
            SedesHelper.writeChararray(out, (String) val);
            break;
        }
        case DataType.GENERIC_WRITABLECOMPARABLE:
            out.writeByte(GENERIC_WRITABLECOMPARABLE);
            // store the class name, so we know the class to create on read
            writeDatum(out, val.getClass().getName());
            Writable writable = (Writable) val;
            writable.write(out);
            break;

        case DataType.NULL:
            out.writeByte(NULL);
            break;

        default:
            throw new RuntimeException("Unexpected data type " + val.getClass().getName() + " found in stream. " +
                    "Note only standard Pig type is supported when you output from UDF/LoadFunc");
        }
    }