List of usage examples for org.apache.hadoop.io BinaryComparable getBytes
public abstract byte[] getBytes();
From source file:com.proofpoint.hive.serde.JsonSerde.java
License:Apache License
private Object doDeserialize(BinaryComparable binary) throws SerDeException { try {/*from ww w .j a v a 2 s . c om*/ JsonParser jsonParser = jsonFactory.createJsonParser(binary.getBytes(), 0, binary.getLength()); return buildStruct(jsonParser.readValueAsTree()); } catch (IOException e) { throw new SerDeException("error parsing JSON", e); } }
From source file:io.prestosql.plugin.hive.GenericHiveRecordCursor.java
License:Apache License
private void parseStringColumn(int column) { loaded[column] = true;/* w w w .j a v a2 s. c o m*/ Object fieldData = rowInspector.getStructFieldData(rowData, structFields[column]); if (fieldData == null) { nulls[column] = true; } else { Object fieldValue = ((PrimitiveObjectInspector) fieldInspectors[column]) .getPrimitiveWritableObject(fieldData); 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 = Slices.wrappedBuffer(hiveValue.getBytes(), 0, hiveValue.getLength()); Type type = types[column]; if (isVarcharType(type)) { value = truncateToLength(value, type); } if (isCharType(type)) { value = truncateToLengthAndTrimSpaces(value, type); } // store a copy of the bytes, since the hive reader can reuse the underlying buffer slices[column] = Slices.copyOf(value); nulls[column] = false; } }
From source file:org.apache.orc.mapred.OrcMapredRecordWriter.java
License:Apache License
static void setBinaryValue(ColumnVector vector, int row, BinaryComparable value) { ((BytesColumnVector) vector).setVal(row, value.getBytes(), 0, value.getLength()); }
From source file:org.apache.orc.mapred.OrcMapredRecordWriter.java
License:Apache License
static void setBinaryValue(ColumnVector vector, int row, BinaryComparable value, int maxLength) { ((BytesColumnVector) vector).setVal(row, value.getBytes(), 0, Math.min(maxLength, value.getLength())); }
From source file:org.commoncrawl.util.BinaryComparableWithOffset.java
License:Open Source License
/** * Compare bytes from {#getBytes()}.//from w w w .j a va 2 s. c o m * @see org.apache.hadoop.io.WritableComparator#compareBytes(byte[],int,int,byte[],int,int) */ public int compareTo(BinaryComparable other) { if (this == other) return 0; if (other instanceof BinaryComparableWithOffset) { return WritableComparator.compareBytes(getBytes(), getOffset(), getLength(), other.getBytes(), ((BinaryComparableWithOffset) other).getOffset(), other.getLength()); } else { return WritableComparator.compareBytes(getBytes(), getOffset(), getLength(), other.getBytes(), 0, other.getLength()); } }