@Override public BytesWritable set(Object o, BytesWritable bw) { BytesWritable incoming = (BytesWritable)o; if (bw != null){ incoming.set(bw); } return incoming; }
@Override public BytesWritable set(Object o, byte[] bb) { BytesWritable incoming = (BytesWritable)o; if (bb != null){ incoming.set(bb, 0, bb.length); } return incoming; }
public static BytesWritable copyBytesWritable(BytesWritable bw) { BytesWritable copy = new BytesWritable(); copy.set(bw); return copy; }
@Override public BytesWritable create(BytesWritable bw) { BytesWritable newCpy = new BytesWritable(); if (null != bw){ newCpy.set(bw); } return newCpy; }
public static BytesWritable getBinaryFromText(Text text) { BytesWritable bw = new BytesWritable(); bw.set(text.getBytes(), 0, text.getLength()); return bw; }
public BytesWritable evaluate(Text value){ if (value == null) { return null; } byte[] bytes = new byte[value.getLength()]; System.arraycopy(value.getBytes(), 0, bytes, 0, value.getLength()); byte[] decoded = Base64.decodeBase64(bytes); result.set(decoded, 0, decoded.length); return result; } }
public BytesWritable readBytes(BytesWritable bw) throws IOException { byte[] bytes = in.readBytes(); if (bw == null) { bw = new BytesWritable(bytes); } else { bw.set(bytes, 0, bytes.length); } return bw; }
@Override public void init(ByteArrayRef bytes, int start, int length) { if (bytes == null) { throw new RuntimeException("bytes cannot be null!"); } isNull = false; byte[] recv = new byte[length]; System.arraycopy(bytes.getData(), start, recv, 0, length); data.set(recv, 0, length); } }
@Override public void init(ByteArrayRef bytes, int start, int length) { assert (length > -1); data.set(bytes.getData(), start, length); } }
@VisibleForTesting public void testPutRow(byte[] currentKey) throws HiveException, IOException { if (testKeyBytesWritable == null) { testKeyBytesWritable = new BytesWritable(); } testKeyBytesWritable.set(currentKey, 0, currentKey.length); putRow(testKeyBytesWritable, null); }
@Override public Object encode(byte[] record) throws SerializationError { try { BytesWritable blob = new BytesWritable(); blob.set(record, 0, record.length); return serde.deserialize(blob); } catch (SerDeException e) { throw new SerializationError("Unable to convert byte[] record into Object", e); } }
@Override public Object encode(byte[] record) throws SerializationError { try { BytesWritable blob = new BytesWritable(); blob.set(record, 0, record.length); return serde.deserialize(blob); } catch (SerDeException e) { throw new SerializationError("Unable to convert byte[] record into Object", e); } }
public static List<Object> deserializeRow(byte[] keyBytes, int keyOffset, int keyLength, BytesWritable bytesWritable, AbstractSerDe serde) throws HiveException { try { bytesWritable.set(keyBytes, keyOffset, keyLength); return (List<Object>) serde.deserialize(bytesWritable); } catch (SerDeException e) { throw new HiveException("Serialization error", e); } } }
@Override public void setField(Block block, int position) { byte[] bytes = VarbinaryType.VARBINARY.getSlice(block, position).getBytes(); value.set(bytes, 0, bytes.length); rowInspector.setStructFieldData(row, field, value); } }
@Override public void init(ByteArrayRef bytes, int start, int length) { super.init(bytes, start, length); byte[] recv = new byte[length]; System.arraycopy(bytes.getData(), start, recv, 0, length); byte[] decoded = decodeIfNeeded(recv); // use the original bytes in case decoding should fail decoded = decoded.length > 0 ? decoded : recv; data.set(decoded, 0, decoded.length); }
public void testHexConversion(){ byte[] bytes = "string".getBytes(); // Let's make sure we only read the relevant part of the writable in case of reuse byte[] longBytes = "longer string".getBytes(); BytesWritable writable = new BytesWritable(longBytes); writable.set(bytes, 0, bytes.length); UDFHex udf = new UDFHex(); Text text = udf.evaluate(writable); String hexString = text.toString(); assertEquals("737472696E67", hexString); } }
public void testBase64Conversion(){ byte[] bytes = "string".getBytes(); // Let's make sure we only read the relevant part of the writable in case of reuse byte[] longBytes = "longer string".getBytes(); BytesWritable writable = new BytesWritable(longBytes); writable.set(bytes, 0, bytes.length); UDFBase64 udf = new UDFBase64(); Text text = udf.evaluate(writable); String base64String = text.toString(); assertEquals("c3RyaW5n", base64String); } }
@Test public void testReuse() { BytesWritable value = new BytesWritable(); byte[] first = "hello world".getBytes(UTF_8); value.set(first, 0, first.length); byte[] second = "bye".getBytes(UTF_8); value.set(second, 0, second.length); Type type = new TypeToken<Map<BytesWritable, Long>>() {}.getType(); ObjectInspector inspector = getInspector(type); Block actual = getBlockObject(mapType(createUnboundedVarcharType(), BIGINT), ImmutableMap.of(value, 0L), inspector); Block expected = mapBlockOf(createUnboundedVarcharType(), BIGINT, "bye", 0L); assertBlockEquals(actual, expected); }
public void next(BytesWritable key, BytesWritable value, boolean dupKey) { if (dupKey) { key.set(lastKey); } else { fillKey(key); } fillValue(value); } }
private void processValue(VectorizedRowBatch batch, int batchIndex) throws HiveException { if (isEmptyValue) return; try { valueLazyBinarySerializeWrite.reset(); valueVectorSerializeRow.serializeWrite(batch, batchIndex); valueBytesWritable.set(valueOutput.getData(), 0, valueOutput.getLength()); } catch (Exception e) { throw new HiveException(e); } }