HBASE-1106 Expose getClosestRowBefore in HTable
git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@731178 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
491991061e
commit
fe345b23bc
|
@ -202,6 +202,8 @@ Release 0.19.0 - Unreleased
|
||||||
HBASE-1062 Compactions at (re)start on a large table can overwhelm DFS
|
HBASE-1062 Compactions at (re)start on a large table can overwhelm DFS
|
||||||
HBASE-1102 boolean HTable.exists()
|
HBASE-1102 boolean HTable.exists()
|
||||||
HBASE-1105 Remove duplicated code in HCM, add javadoc to RegionState, etc.
|
HBASE-1105 Remove duplicated code in HCM, add javadoc to RegionState, etc.
|
||||||
|
HBASE-1106 Expose getClosestRowBefore in HTable
|
||||||
|
(Michael Gottesman via Stack)
|
||||||
|
|
||||||
NEW FEATURES
|
NEW FEATURES
|
||||||
HBASE-875 Use MurmurHash instead of JenkinsHash [in bloomfilters]
|
HBASE-875 Use MurmurHash instead of JenkinsHash [in bloomfilters]
|
||||||
|
|
|
@ -618,6 +618,19 @@ public class HTable {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RowResult getClosestRowBefore(final byte[] row, final byte[] columnFamily)
|
||||||
|
throws IOException {
|
||||||
|
return connection.getRegionServerWithRetries(
|
||||||
|
new ServerCallable<RowResult>(connection,tableName,row) {
|
||||||
|
public RowResult call() throws IOException {
|
||||||
|
return server.getClosestRowBefore(
|
||||||
|
location.getRegionInfo().getRegionName(), row, columnFamily
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a scanner on the current table starting at first row.
|
* Get a scanner on the current table starting at first row.
|
||||||
* Return the specified columns.
|
* Return the specified columns.
|
||||||
|
|
|
@ -259,4 +259,57 @@ public class TestHTable extends HBaseClusterTestCase implements HConstants {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testGetClosestRowBefore() throws IOException {
|
||||||
|
HColumnDescriptor column2 =
|
||||||
|
new HColumnDescriptor(Bytes.toBytes("info2:"));
|
||||||
|
HBaseAdmin admin = new HBaseAdmin(conf);
|
||||||
|
HTableDescriptor testTableADesc =
|
||||||
|
new HTableDescriptor(tableAname);
|
||||||
|
testTableADesc.addFamily(column);
|
||||||
|
testTableADesc.addFamily(column2);
|
||||||
|
admin.createTable(testTableADesc);
|
||||||
|
|
||||||
|
byte[] firstRow = Bytes.toBytes("ro");
|
||||||
|
byte[] beforeFirstRow = Bytes.toBytes("rn");
|
||||||
|
byte[] beforeSecondRow = Bytes.toBytes("rov");
|
||||||
|
|
||||||
|
HTable table = new HTable(conf, tableAname);
|
||||||
|
BatchUpdate batchUpdate = new BatchUpdate(firstRow);
|
||||||
|
BatchUpdate batchUpdate2 = new BatchUpdate(row);
|
||||||
|
byte[] zero = new byte[]{0};
|
||||||
|
byte[] one = new byte[]{1};
|
||||||
|
byte[] columnFamilyBytes = Bytes.toBytes(COLUMN_FAMILY_STR);
|
||||||
|
|
||||||
|
batchUpdate.put(COLUMN_FAMILY_STR,zero);
|
||||||
|
batchUpdate2.put(COLUMN_FAMILY_STR,one);
|
||||||
|
|
||||||
|
table.commit(batchUpdate);
|
||||||
|
table.commit(batchUpdate2);
|
||||||
|
|
||||||
|
RowResult result = null;
|
||||||
|
|
||||||
|
// Test before first that null is returned
|
||||||
|
result = table.getClosestRowBefore(beforeFirstRow, columnFamilyBytes);
|
||||||
|
assertTrue(result == null);
|
||||||
|
|
||||||
|
// Test at first that first is returned
|
||||||
|
result = table.getClosestRowBefore(firstRow, columnFamilyBytes);
|
||||||
|
assertTrue(result.containsKey(COLUMN_FAMILY_STR));
|
||||||
|
assertTrue(Bytes.equals(result.get(COLUMN_FAMILY_STR).getValue(), zero));
|
||||||
|
|
||||||
|
// Test inbetween first and second that first is returned
|
||||||
|
result = table.getClosestRowBefore(beforeSecondRow, columnFamilyBytes);
|
||||||
|
assertTrue(result.containsKey(COLUMN_FAMILY_STR));
|
||||||
|
assertTrue(Bytes.equals(result.get(COLUMN_FAMILY_STR).getValue(), zero));
|
||||||
|
|
||||||
|
// Test at second make sure second is returned
|
||||||
|
result = table.getClosestRowBefore(row, columnFamilyBytes);
|
||||||
|
assertTrue(result.containsKey(COLUMN_FAMILY_STR));
|
||||||
|
assertTrue(Bytes.equals(result.get(COLUMN_FAMILY_STR).getValue(), one));
|
||||||
|
|
||||||
|
// Test after second, make sure second is returned
|
||||||
|
result = table.getClosestRowBefore(Bytes.add(row,one), columnFamilyBytes);
|
||||||
|
assertTrue(result.containsKey(COLUMN_FAMILY_STR));
|
||||||
|
assertTrue(Bytes.equals(result.get(COLUMN_FAMILY_STR).getValue(), one));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue