Esempio n. 1
0
 /** Assert CellUtil makes Cell toStrings same way we do KeyValue toStrings. */
 @Test
 public void testToString() {
   byte[] row = Bytes.toBytes("row");
   long ts = 123l;
   // Make a KeyValue and a Cell and see if same toString result.
   KeyValue kv =
       new KeyValue(
           row,
           HConstants.EMPTY_BYTE_ARRAY,
           HConstants.EMPTY_BYTE_ARRAY,
           ts,
           KeyValue.Type.Minimum,
           HConstants.EMPTY_BYTE_ARRAY);
   Cell cell =
       CellUtil.createCell(
           row,
           HConstants.EMPTY_BYTE_ARRAY,
           HConstants.EMPTY_BYTE_ARRAY,
           ts,
           KeyValue.Type.Minimum.getCode(),
           HConstants.EMPTY_BYTE_ARRAY);
   String cellToString = CellUtil.getCellKeyAsString(cell);
   assertEquals(kv.toString(), cellToString);
   // Do another w/ non-null family.
   byte[] f = new byte[] {'f'};
   byte[] q = new byte[] {'q'};
   kv = new KeyValue(row, f, q, ts, KeyValue.Type.Minimum, HConstants.EMPTY_BYTE_ARRAY);
   cell =
       CellUtil.createCell(
           row, f, q, ts, KeyValue.Type.Minimum.getCode(), HConstants.EMPTY_BYTE_ARRAY);
   cellToString = CellUtil.getCellKeyAsString(cell);
   assertEquals(kv.toString(), cellToString);
 }
Esempio n. 2
0
 static int insertData(Configuration conf, TableName tableName, String column, double prob)
     throws IOException {
   Random rng = new Random();
   int count = 0;
   HTable table = new HTable(conf, tableName);
   byte[] k = new byte[3];
   byte[][] famAndQf = KeyValue.parseColumn(Bytes.toBytes(column));
   for (byte b1 = 'a'; b1 < 'z'; b1++) {
     for (byte b2 = 'a'; b2 < 'z'; b2++) {
       for (byte b3 = 'a'; b3 < 'z'; b3++) {
         if (rng.nextDouble() < prob) {
           k[0] = b1;
           k[1] = b2;
           k[2] = b3;
           Put put = new Put(k);
           put.setDurability(Durability.SKIP_WAL);
           put.add(famAndQf[0], famAndQf[1], k);
           table.put(put);
           count++;
         }
       }
     }
   }
   table.flushCommits();
   table.close();
   return count;
 }
Esempio n. 3
0
 @Test
 public void testFindCommonPrefixInFlatKey() {
   // The whole key matching case
   KeyValue kv1 = new KeyValue("r1".getBytes(), "f1".getBytes(), "q1".getBytes(), null);
   Assert.assertEquals(
       kv1.getKeyLength(), CellUtil.findCommonPrefixInFlatKey(kv1, kv1, true, true));
   Assert.assertEquals(
       kv1.getKeyLength(), CellUtil.findCommonPrefixInFlatKey(kv1, kv1, false, true));
   Assert.assertEquals(
       kv1.getKeyLength() - KeyValue.TIMESTAMP_TYPE_SIZE,
       CellUtil.findCommonPrefixInFlatKey(kv1, kv1, true, false));
   // The rk length itself mismatch
   KeyValue kv2 = new KeyValue("r12".getBytes(), "f1".getBytes(), "q1".getBytes(), null);
   Assert.assertEquals(1, CellUtil.findCommonPrefixInFlatKey(kv1, kv2, true, true));
   // part of rk is same
   KeyValue kv3 = new KeyValue("r14".getBytes(), "f1".getBytes(), "q1".getBytes(), null);
   Assert.assertEquals(
       KeyValue.ROW_LENGTH_SIZE + "r1".getBytes().length,
       CellUtil.findCommonPrefixInFlatKey(kv2, kv3, true, true));
   // entire rk is same but different cf name
   KeyValue kv4 = new KeyValue("r14".getBytes(), "f2".getBytes(), "q1".getBytes(), null);
   Assert.assertEquals(
       KeyValue.ROW_LENGTH_SIZE
           + kv3.getRowLength()
           + KeyValue.FAMILY_LENGTH_SIZE
           + "f".getBytes().length,
       CellUtil.findCommonPrefixInFlatKey(kv3, kv4, false, true));
   // rk and family are same and part of qualifier
   KeyValue kv5 = new KeyValue("r14".getBytes(), "f2".getBytes(), "q123".getBytes(), null);
   Assert.assertEquals(
       KeyValue.ROW_LENGTH_SIZE
           + kv3.getRowLength()
           + KeyValue.FAMILY_LENGTH_SIZE
           + kv4.getFamilyLength()
           + kv4.getQualifierLength(),
       CellUtil.findCommonPrefixInFlatKey(kv4, kv5, true, true));
   // rk, cf and q are same. ts differs
   KeyValue kv6 = new KeyValue("rk".getBytes(), 1234L);
   KeyValue kv7 = new KeyValue("rk".getBytes(), 1235L);
   // only last byte out of 8 ts bytes in ts part differs
   Assert.assertEquals(
       KeyValue.ROW_LENGTH_SIZE
           + kv6.getRowLength()
           + KeyValue.FAMILY_LENGTH_SIZE
           + kv6.getFamilyLength()
           + kv6.getQualifierLength()
           + 7,
       CellUtil.findCommonPrefixInFlatKey(kv6, kv7, true, true));
   // rk, cf, q and ts are same. Only type differs
   KeyValue kv8 = new KeyValue("rk".getBytes(), 1234L, Type.Delete);
   Assert.assertEquals(
       KeyValue.ROW_LENGTH_SIZE
           + kv6.getRowLength()
           + KeyValue.FAMILY_LENGTH_SIZE
           + kv6.getFamilyLength()
           + kv6.getQualifierLength()
           + KeyValue.TIMESTAMP_SIZE,
       CellUtil.findCommonPrefixInFlatKey(kv6, kv8, true, true));
   // With out TS_TYPE check
   Assert.assertEquals(
       KeyValue.ROW_LENGTH_SIZE
           + kv6.getRowLength()
           + KeyValue.FAMILY_LENGTH_SIZE
           + kv6.getFamilyLength()
           + kv6.getQualifierLength(),
       CellUtil.findCommonPrefixInFlatKey(kv6, kv8, true, false));
 }