protected byte[] toBytes(String str) { if (str == null) { return new byte[] { DimensionEncoding.NULL }; } return Bytes.toBytes(str); }
/** * @param t operands * @return Array of byte arrays made from passed array of Text */ public static byte[][] toByteArrays(final String[] t) { byte[][] result = new byte[t.length][]; for (int i = 0; i < t.length; i++) { result[i] = Bytes.toBytes(t[i]); } return result; }
@Override public byte[] convertToBytes(String v) { return Bytes.toBytes(v); }
/** * @param f float value * @return the float represented as byte [] */ public static byte[] toBytes(final float f) { // Encode it as int return Bytes.toBytes(Float.floatToRawIntBits(f)); }
/** * Serialize a double as the IEEE 754 double format output. The resultant * array will be 8 bytes long. * * @param d value * @return the double represented as byte [] */ public static byte[] toBytes(final double d) { // Encode it as a long return Bytes.toBytes(Double.doubleToRawLongBits(d)); }
private ObjectIdentityImpl getParentDomainObjectInfoFromRs(Result result) throws IOException { ObjectIdentityImpl parentInfo = domainObjSerializer.deserialize(result.getValue( Bytes.toBytes(AclConstant.ACL_INFO_FAMILY), Bytes.toBytes(AclConstant.ACL_INFO_FAMILY_PARENT_COLUMN))); return parentInfo; }
private ObjectIdentityImpl getDomainObjectInfoFromRs(Result result) { String type = new String(result.getValue(Bytes.toBytes(AclConstant.ACL_INFO_FAMILY), Bytes.toBytes(AclConstant.ACL_INFO_FAMILY_TYPE_COLUMN)), StandardCharsets.UTF_8); String id = new String(result.getRow(), StandardCharsets.UTF_8); ObjectIdentityImpl newInfo = new ObjectIdentityImpl(type, id); return newInfo; }
/** * @param column operand * @return A byte array of a byte array where first and only entry is * <code>column</code> */ public static byte[][] toByteArrays(final String column) { return toByteArrays(toBytes(column)); }
@Override public void doMap(NullWritable key, Text value, Context context) throws IOException, InterruptedException { tmpBuf.clear(); int size = value.getLength()+ 1; if (size >= tmpBuf.capacity()) { tmpBuf = ByteBuffer.allocate(countNewSize(tmpBuf.capacity(), size)); } tmpBuf.put(Bytes.toBytes(index)[3]); tmpBuf.put(value.getBytes(), 0, value.getLength()); outputKey.set(tmpBuf.array(), 0, tmpBuf.position()); sortableKey.init(outputKey, type); context.write(sortableKey, NullWritable.get()); }
/** * Writes a string as a fixed-size field, padded with zeros. */ public static void writeStringFixedSize(final DataOutput out, String s, int size) throws IOException { byte[] b = toBytes(s); if (b.length > size) { throw new IOException("Trying to write " + b.length + " bytes (" + toStringBinary(b) + ") into a field of length " + size); } out.writeBytes(s); for (int i = 0; i < size - s.length(); ++i) out.writeByte(0); }
public RowValueDecoder(HBaseColumnDesc hbaseColumn) { this.hbaseColumn = hbaseColumn; this.hbaseColumnFamily = Bytes.toBytes(hbaseColumn.getColumnFamilyName()); this.hbaseColumnQualifier = Bytes.toBytes(hbaseColumn.getQualifier()); this.projectionIndex = new BitSet(); this.measures = hbaseColumn.getMeasures(); this.codec = new MeasureCodec(measures); this.values = new Object[measures.length]; }
@Override public void doMap(LongWritable key, BytesWritable value, Context context) throws IOException, InterruptedException { ByteBuffer buffer = ByteBuffer.wrap(value.getBytes(), 0, value.getLength()); StreamingMessageRow row = streamingParser.parse(buffer).get(0); if (row == null) { throw new IllegalArgumentException(""); } data = StringUtil.join(row.getData(), delimiter); // output this row to value outValue.set(Bytes.toBytes(data)); context.write(outKey, outValue); } }
/** Should be more private. For test only. */ public Cuboid(CubeDesc cubeDesc, long originalID, long validID) { this.cubeDesc = cubeDesc; this.inputID = originalID; this.id = validID; this.idBytes = Bytes.toBytes(id); this.dimensionColumns = translateIdToColumns(this.id); this.requirePostAggregation = calcExtraAggregation(this.inputID, this.id) != 0; }
@Override public byte[] convertToBytes(String v) { v = normalizeNumber(v); NumberBytesCodec codec = getCodec(this.maxDigitsBeforeDecimalPoint); byte[] num = Bytes.toBytes(v); codec.encodeNumber(num, 0, num.length); return Bytes.copy(codec.buf, codec.bufOffset, codec.bufLen); }
private String decodeNumber(String code) { byte[] buf = Bytes.toBytes(code); System.arraycopy(buf, 0, codec.buf, 0, buf.length); codec.bufOffset = 0; codec.bufLen = buf.length; int len = codec.decodeNumber(buf, 0); return Bytes.toString(buf, 0, len); }
private String encodeNumber(String number) { byte[] num1 = Bytes.toBytes(number); codec.encodeNumber(num1, 0, num1.length); return Bytes.toString(codec.buf, codec.bufOffset, codec.bufLen); }
@Test public void testEnDeCodeWithMultiKeys() { HBaseLookupRowEncoder lookupRowEncoder = new HBaseLookupRowEncoder(tableDesc, new String[] { "COUNTRY", "NAME" }, 1); String[] row = new String[] { "AD", "42.546245", "1.601554", "Andorra" }; HBaseRow hBaseRow = lookupRowEncoder.encode(row); assertEquals(2, hBaseRow.getQualifierValMap().size()); NavigableMap<byte[], byte[]> qualifierMap = hBaseRow.getQualifierValMap(); assertEquals("42.546245", Bytes.toString(qualifierMap.get(Bytes.toBytes("1")))); assertEquals("1.601554", Bytes.toString(qualifierMap.get(Bytes.toBytes("2")))); String[] decodeRow = lookupRowEncoder.decode(hBaseRow); assertArrayEquals(row, decodeRow); }
@Test public void testEnDeCode() { HBaseLookupRowEncoder lookupRowEncoder = new HBaseLookupRowEncoder(tableDesc, new String[] { "COUNTRY" }, 1); String[] row = new String[] { "AD", "42.546245", "1.601554", "Andorra" }; HBaseRow hBaseRow = lookupRowEncoder.encode(row); assertEquals(6, hBaseRow.getRowKey().length); assertEquals(3, hBaseRow.getQualifierValMap().size()); NavigableMap<byte[], byte[]> qualifierMap = hBaseRow.getQualifierValMap(); assertEquals("42.546245", Bytes.toString(qualifierMap.get(Bytes.toBytes("1")))); assertEquals("1.601554", Bytes.toString(qualifierMap.get(Bytes.toBytes("2")))); String[] decodeRow = lookupRowEncoder.decode(hBaseRow); assertArrayEquals(row, decodeRow); }