Search in sources :

Example 11 with BinaryComparable

use of org.apache.hadoop.io.BinaryComparable in project presto by prestodb.

the class GenericHiveRecordCursor method parseStringFromPrimitiveWritableObjectValue.

private static Slice parseStringFromPrimitiveWritableObjectValue(Type type, Object fieldValue) {
    checkState(fieldValue != null, "fieldValue should not be null");
    BinaryComparable hiveValue;
    if (fieldValue instanceof Text) {
        hiveValue = (Text) fieldValue;
    } else if (fieldValue instanceof BytesWritable) {
        hiveValue = (BytesWritable) fieldValue;
    } else if (fieldValue instanceof HiveVarcharWritable) {
        hiveValue = ((HiveVarcharWritable) fieldValue).getTextValue();
    } else if (fieldValue instanceof HiveCharWritable) {
        hiveValue = ((HiveCharWritable) fieldValue).getTextValue();
    } else {
        throw new IllegalStateException("unsupported string field type: " + fieldValue.getClass().getName());
    }
    // create a slice view over the hive value and trim to character limits
    Slice value = trimStringToCharacterLimits(type, Slices.wrappedBuffer(hiveValue.getBytes(), 0, hiveValue.getLength()));
    // store a copy of the bytes, since the hive reader can reuse the underlying buffer
    return Slices.copyOf(value);
}
Also used : BinaryComparable(org.apache.hadoop.io.BinaryComparable) Slice(io.airlift.slice.Slice) HiveVarcharWritable(org.apache.hadoop.hive.serde2.io.HiveVarcharWritable) HiveCharWritable(org.apache.hadoop.hive.serde2.io.HiveCharWritable) Text(org.apache.hadoop.io.Text) BytesWritable(org.apache.hadoop.io.BytesWritable)

Aggregations

BinaryComparable (org.apache.hadoop.io.BinaryComparable)11 BytesWritable (org.apache.hadoop.io.BytesWritable)5 Configuration (org.apache.hadoop.conf.Configuration)4 Test (org.junit.Test)4 IOException (java.io.IOException)2 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)2 SerDeException (org.apache.hadoop.hive.serde2.SerDeException)2 Slice (io.airlift.slice.Slice)1 ArrayList (java.util.ArrayList)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 ExecMapperContext (org.apache.hadoop.hive.ql.exec.mr.ExecMapperContext)1 HiveCharWritable (org.apache.hadoop.hive.serde2.io.HiveCharWritable)1 HiveVarcharWritable (org.apache.hadoop.hive.serde2.io.HiveVarcharWritable)1 ByteArrayRef (org.apache.hadoop.hive.serde2.lazy.ByteArrayRef)1 RawComparator (org.apache.hadoop.io.RawComparator)1 Text (org.apache.hadoop.io.Text)1 Job (org.apache.hadoop.mapreduce.Job)1