@Override public Long getValue(byte[] colFamily, byte[] colQualifier, Cell kv) throws IOException { if (kv == null || kv.getValueLength() != Bytes.SIZEOF_LONG) return null; return PrivateCellUtil.getValueAsLong(kv); }
/** * @return Get the long out of the passed in Cell */ private static long getLongValue(final Cell cell) throws DoNotRetryIOException { int len = cell.getValueLength(); if (len != Bytes.SIZEOF_LONG) { // throw DoNotRetryIOException instead of IllegalArgumentException throw new DoNotRetryIOException("Field is not a long, it's " + len + " bytes wide"); } return PrivateCellUtil.getValueAsLong(cell); }
@Test public void testCellFieldsAsPrimitiveTypesFromByteBufferedCell() { int ri = 123; byte[] r = Bytes.toBytes(ri); byte[] f = Bytes.toBytes("cf1"); byte[] q = Bytes.toBytes("qual1"); long vl = 10981L; byte[] v = Bytes.toBytes(vl); KeyValue kv = new KeyValue(r, f, q, v); ByteBuffer buffer = ByteBuffer.wrap(kv.getBuffer()); Cell bbCell = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); assertEquals(ri, PrivateCellUtil.getRowAsInt(bbCell)); assertEquals(vl, PrivateCellUtil.getValueAsLong(bbCell)); double vd = 3005.5; v = Bytes.toBytes(vd); kv = new KeyValue(r, f, q, v); buffer = ByteBuffer.wrap(kv.getBuffer()); bbCell = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); assertEquals(vd, PrivateCellUtil.getValueAsDouble(bbCell), 0.0); BigDecimal bd = new BigDecimal(9999); v = Bytes.toBytes(bd); kv = new KeyValue(r, f, q, v); buffer = ByteBuffer.wrap(kv.getBuffer()); bbCell = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); assertEquals(bd, PrivateCellUtil.getValueAsBigDecimal(bbCell)); }
@Override public Long getValue(byte[] colFamily, byte[] colQualifier, Cell kv) throws IOException { if (kv == null || kv.getValueLength() != Bytes.SIZEOF_LONG) return null; return PrivateCellUtil.getValueAsLong(kv); }
@Override public Long getValue(byte[] colFamily, byte[] colQualifier, Cell kv) throws IOException { if (kv == null || kv.getValueLength() != Bytes.SIZEOF_LONG) return null; return PrivateCellUtil.getValueAsLong(kv); }
@Test public void testCellFieldsAsPrimitiveTypesFromByteBufferedCell() { int ri = 123; byte[] r = Bytes.toBytes(ri); byte[] f = Bytes.toBytes("cf1"); byte[] q = Bytes.toBytes("qual1"); long vl = 10981L; byte[] v = Bytes.toBytes(vl); KeyValue kv = new KeyValue(r, f, q, v); ByteBuffer buffer = ByteBuffer.wrap(kv.getBuffer()); Cell bbCell = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); assertEquals(ri, PrivateCellUtil.getRowAsInt(bbCell)); assertEquals(vl, PrivateCellUtil.getValueAsLong(bbCell)); double vd = 3005.5; v = Bytes.toBytes(vd); kv = new KeyValue(r, f, q, v); buffer = ByteBuffer.wrap(kv.getBuffer()); bbCell = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); assertEquals(vd, PrivateCellUtil.getValueAsDouble(bbCell), 0.0); BigDecimal bd = new BigDecimal(9999); v = Bytes.toBytes(bd); kv = new KeyValue(r, f, q, v); buffer = ByteBuffer.wrap(kv.getBuffer()); bbCell = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); assertEquals(bd, PrivateCellUtil.getValueAsBigDecimal(bbCell)); }
@Test public void testCellFieldsAsPrimitiveTypesFromByteBufferedCell() { int ri = 123; byte[] r = Bytes.toBytes(ri); byte[] f = Bytes.toBytes("cf1"); byte[] q = Bytes.toBytes("qual1"); long vl = 10981L; byte[] v = Bytes.toBytes(vl); KeyValue kv = new KeyValue(r, f, q, v); ByteBuffer buffer = ByteBuffer.wrap(kv.getBuffer()); Cell bbCell = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); assertEquals(ri, PrivateCellUtil.getRowAsInt(bbCell)); assertEquals(vl, PrivateCellUtil.getValueAsLong(bbCell)); double vd = 3005.5; v = Bytes.toBytes(vd); kv = new KeyValue(r, f, q, v); buffer = ByteBuffer.wrap(kv.getBuffer()); bbCell = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); assertEquals(vd, PrivateCellUtil.getValueAsDouble(bbCell), 0.0); BigDecimal bd = new BigDecimal(9999); v = Bytes.toBytes(bd); kv = new KeyValue(r, f, q, v); buffer = ByteBuffer.wrap(kv.getBuffer()); bbCell = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); assertEquals(bd, PrivateCellUtil.getValueAsBigDecimal(bbCell)); }