/** * Override base class implementation to support varchar values. */ @Override Text getTextValue(Object obj) { return (((HiveVarcharObjectInspector) inspector) .getPrimitiveWritableObject(obj)).getTextValue(); } }
@Override public void init(ByteArrayRef bytes, int start, int length) { // re-use existing text member in varchar writable Text textValue = data.getTextValue(); textValue.set(bytes.getData(), start, length); data.enforceMaxLength(maxLength); }
@Override void serialize(RandomAccessOutput byteStream, Object obj, ObjectInspector objInspector, boolean skipLengthPrefix, BooleanRef warnedOnceNullMapKey) { HiveVarcharObjectInspector hcoi = (HiveVarcharObjectInspector) objInspector; Text t = hcoi.getPrimitiveWritableObject(obj).getTextValue(); serializeText(byteStream, t, skipLengthPrefix); } }
@Override public void setSafeValue(ObjectInspector oi, Object hiveFieldValue, ValueVector outputVV, int outputIndex) { final Text value = ((HiveVarcharObjectInspector)oi).getPrimitiveWritableObject(hiveFieldValue).getTextValue(); final byte[] valueBytes = value.getBytes(); final int valueLen = value.getLength(); ((NullableVarCharVector) outputVV).getMutator().setSafe(outputIndex, valueBytes, 0, valueLen); } }
/** * Write VARCHAR(N). * The representation of Varchar in Teradata binary format is: * the first two bytes represent the length N of this varchar field, * the next N bytes represent the content of this varchar field. * To pad the null varchar, the length will be 0 and the content will be none. * * @param writable the writable * @throws IOException the io exception */ public void writeVarChar(HiveVarcharWritable writable) throws IOException { if (writable == null) { EndianUtils.writeSwappedShort(this, (short) 0); return; } Text t = writable.getTextValue(); int varcharLength = t.getLength(); EndianUtils.writeSwappedShort(this, (short) varcharLength); // write the varchar length write(t.getBytes(), 0, varcharLength); // write the varchar content }
hiveValue = ((HiveVarcharWritable) fieldValue).getTextValue();
@Override public void init(ByteArrayRef bytes, int start, int length) { if (oi.isEscaped()) { Text textData = data.getTextValue(); // This is doing a lot of copying here, this could be improved by enforcing length // at the same time as escaping rather than as separate steps. LazyUtils.copyAndEscapeStringDataToText(bytes.getData(), start, length, oi.getEscapeChar(),textData); data.set(textData.toString(), maxLength); isNull = false; } else { try { String byteData = null; byteData = Text.decode(bytes.getData(), start, length); data.set(byteData, maxLength); isNull = false; } catch (CharacterCodingException e) { isNull = true; LOG.debug("Data not in the HiveVarchar data type range so converted to null.", e); } } }
Text t = hc.getTextValue(); writeEscaped(out, t.getBytes(), 0, t.getLength(), escaped, escapeChar, needsEscape);
public static BytesWritable getBinary(Object o, PrimitiveObjectInspector oi) { if (null == o) { return null; } switch (oi.getPrimitiveCategory()) { case VOID: return null; case STRING: Text text = ((StringObjectInspector) oi).getPrimitiveWritableObject(o); return getBinaryFromText(text); case CHAR: // char to binary conversion: include trailing spaces? return getBinaryFromText( ((HiveCharObjectInspector) oi).getPrimitiveWritableObject(o).getPaddedValue()); case VARCHAR: return getBinaryFromText( ((HiveVarcharObjectInspector) oi).getPrimitiveWritableObject(o).getTextValue()); case BINARY: return ((BinaryObjectInspector) oi).getPrimitiveWritableObject(o); default: throw new RuntimeException("Cannot convert to Binary from: " + oi.getTypeName()); } }
Text text = ((HiveVarcharObjectInspector)poi).getPrimitiveWritableObject(o).getTextValue(); return Murmur3.hash32(text.getBytes(), text.getLength());
hiveVarcharWritable = writableHiveVarcharObjectOI.getPrimitiveWritableObject(value); Text t = hiveVarcharWritable.getTextValue();
BytesColumnVector vector = (BytesColumnVector) column; Text blob = ((HiveVarcharObjectInspector) inspector) .getPrimitiveWritableObject(obj).getTextValue(); vector.setVal(rowId, blob.getBytes(), 0, blob.getLength()); break;
case VARCHAR: Text vVarChar = ((HiveVarcharObjectInspector)inputOI). getPrimitiveWritableObject(parameters[0]).getTextValue(); bf.addBytes(vVarChar.getBytes(), 0, vVarChar.getLength()); break;
reuse == null ? new HiveVarcharWritable() : (HiveVarcharWritable) reuse; deserializeText(buffer, invert, r.getTextValue());
BytesColumnVector vector = (BytesColumnVector) column; Text blob = ((HiveVarcharObjectInspector) inspector) .getPrimitiveWritableObject(obj).getTextValue(); vector.setVal(rowId, blob.getBytes(), 0, blob.getLength()); break;
case VARCHAR: Text vVarChar = ((HiveVarcharObjectInspector)inputOI). getPrimitiveWritableObject(parameters[0]).getTextValue(); bf.addBytes(vVarChar.getBytes(), 0, vVarChar.getLength()); break;
HiveVarcharWritable hc = hcoi.getPrimitiveWritableObject(o); Text t = hc.getTextValue(); serializeBytes(buffer, t.getBytes(), t.getLength(), invert); return;
case VARCHAR: Text vVarchar = ((HiveVarcharObjectInspector) valObjectInspector). getPrimitiveWritableObject(arguments[0].get()).getTextValue(); return bloomFilter.testBytes(vVarchar.getBytes(), 0, vVarchar.getLength()); case STRING:
case VARCHAR: Text vVarchar = ((HiveVarcharObjectInspector) valObjectInspector). getPrimitiveWritableObject(arguments[0].get()).getTextValue(); return bloomFilter.testBytes(vVarchar.getBytes(), 0, vVarchar.getLength()); case STRING:
Text t = hcoi.getPrimitiveWritableObject(obj).getTextValue(); serializeText(byteStream, t, skipLengthPrefix); return;