Configuration conf = UTIL.getConfiguration();
HTableDescriptor htd = new HTableDescriptor("TestIndexPut");
HRegionInfo info = new HRegionInfo(htd.getName(), "A".getBytes(), "B".getBytes(), false);
HLog hlog = UTIL.getMiniHBaseCluster().getRegionServer(0).getWAL();
HRegion region = new HRegion(basedir, hlog, fs, conf, info, htd, null);
IndexSpecification spec = new IndexSpecification("index");
spec.addIndexColumn(new HColumnDescriptor("cf1"), "ql1", ValueType.String, 10);
spec.addIndexColumn(new HColumnDescriptor("cf2"), "ql1", ValueType.String, 10);
// scenario where same indexName but diff colvalues can disturb the order if
// used without pad
byte[] rowKey = "Arow1".getBytes();
Put p1 = new Put(rowKey);
long time = 1234567;
p1.add("cf1".getBytes(), "ql1".getBytes(), time, "testcase".getBytes());
p1.add("cf2".getBytes(), "ql1".getBytes(), time, "value".getBytes());
Put indexPut1 = IndexUtils.prepareIndexPut(p1, spec, region);
Put p2 = new Put(rowKey);
p2.add("cf1".getBytes(), "ql1".getBytes(), time, "test".getBytes());
p2.add("cf2".getBytes(), "ql1".getBytes(), time, "value".getBytes());
Put indexPut2 = IndexUtils.prepareIndexPut(p2, spec, region);
// (spaces just for easier reading...not present in actual)
// Index Row key For p1 = "A index testcase value Arow1"
// Index Row key For p2 = "A index test value Arow1"
// NOW acc. to the lexographical ordering p2 should come second but we need
// it to come 1st datz where pad is needed.
byte[] rowKey1 = indexPut1.getRow();
byte[] rowKey2 = indexPut2.getRow();
int result = Bytes.compareTo(rowKey1, rowKey2);
Assert.assertTrue(result > 0);
// scenario where the index names are diff and padding is needed.
IndexSpecification spec1 = new IndexSpecification("ind");
spec1.addIndexColumn(new HColumnDescriptor("cf3"), "ql1", ValueType.String, 10);
p1 = new Put(rowKey);
p1.add("cf3".getBytes(), "ql1".getBytes(), time, "testcase".getBytes());
indexPut1 = IndexUtils.prepareIndexPut(p1, spec1, region);
// (spaces just for easier reading...not present in actual)
// Index Row key For p1 = "A ind testcase value Arow1"