public static byte[] encodeBinaryValue(byte[] value, String hiveType) { String rawType = getRawType(hiveType); switch(rawType) { case serdeConstants.BOOLEAN_TYPE_NAME : return String.valueOf(value[0] == 1).getBytes(); case serdeConstants.INT_TYPE_NAME : return INTEGER_LEXICODER.encode(ByteBuffer.wrap(value).asIntBuffer().get()); case serdeConstants.SMALLINT_TYPE_NAME : return INTEGER_LEXICODER.encode((int)(ByteBuffer.wrap(value).asShortBuffer().get())); case serdeConstants.TINYINT_TYPE_NAME : return INTEGER_LEXICODER.encode((int)value[0]); case serdeConstants.FLOAT_TYPE_NAME : return DOUBLE_LEXICODER.encode((double)ByteBuffer.wrap(value).asFloatBuffer().get()); case serdeConstants.DOUBLE_TYPE_NAME : return DOUBLE_LEXICODER.encode(ByteBuffer.wrap(value).asDoubleBuffer().get()); case serdeConstants.BIGINT_TYPE_NAME : return BIG_INTEGER_LEXICODER.encode(new BigInteger(value)); case serdeConstants.DECIMAL_TYPE_NAME : return new String(value).getBytes(UTF_8); default : return value; } } }
public static byte[] encodeStringValue(byte[] value, String hiveType) { String rawType = getRawType(hiveType); switch(rawType) { case serdeConstants.BOOLEAN_TYPE_NAME: return Boolean.valueOf(new String(value)).toString().getBytes(UTF_8); case serdeConstants.SMALLINT_TYPE_NAME : case serdeConstants.TINYINT_TYPE_NAME : case serdeConstants.INT_TYPE_NAME : return INTEGER_LEXICODER.encode(Integer.valueOf(new String(value))); case serdeConstants.FLOAT_TYPE_NAME : case serdeConstants.DOUBLE_TYPE_NAME : return DOUBLE_LEXICODER.encode(Double.valueOf(new String(value))); case serdeConstants.BIGINT_TYPE_NAME : return BIG_INTEGER_LEXICODER.encode(new BigInteger(new String(value), 10)); case serdeConstants.DECIMAL_TYPE_NAME : return new String(value).getBytes(UTF_8); default : // return the passed in string value return value; } }