You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2009/01/04 06:07:12 UTC
svn commit: r731178 - in /hadoop/hbase/trunk: CHANGES.txt
src/java/org/apache/hadoop/hbase/client/HTable.java
src/test/org/apache/hadoop/hbase/client/TestHTable.java
Author: stack
Date: Sat Jan 3 21:07:11 2009
New Revision: 731178
URL: http://svn.apache.org/viewvc?rev=731178&view=rev
Log:
HBASE-1106 Expose getClosestRowBefore in HTable
Modified:
hadoop/hbase/trunk/CHANGES.txt
hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HTable.java
hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/client/TestHTable.java
Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=731178&r1=731177&r2=731178&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Sat Jan 3 21:07:11 2009
@@ -202,6 +202,8 @@
HBASE-1062 Compactions at (re)start on a large table can overwhelm DFS
HBASE-1102 boolean HTable.exists()
HBASE-1105 Remove duplicated code in HCM, add javadoc to RegionState, etc.
+ HBASE-1106 Expose getClosestRowBefore in HTable
+ (Michael Gottesman via Stack)
NEW FEATURES
HBASE-875 Use MurmurHash instead of JenkinsHash [in bloomfilters]
Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HTable.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HTable.java?rev=731178&r1=731177&r2=731178&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HTable.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HTable.java Sat Jan 3 21:07:11 2009
@@ -618,6 +618,19 @@
);
}
+ 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.
* Return the specified columns.
Modified: hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/client/TestHTable.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/client/TestHTable.java?rev=731178&r1=731177&r2=731178&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/client/TestHTable.java (original)
+++ hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/client/TestHTable.java Sat Jan 3 21:07:11 2009
@@ -259,4 +259,57 @@
}
}
+ 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));
+ }
}