diff --git a/CHANGES.txt b/CHANGES.txt index cf4d5b0b693..d2612b8e83f 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -261,6 +261,8 @@ Trunk (unreleased changes) HBASE-536 Remove MiniDFS startup from MiniHBaseCluster HBASE-521 Improve client scanner interface HBASE-562 Move Exceptions to subpackages (Jean-Daniel Cryans via Stack) + HBASE-631 HTable.getRow() for only a column family + (Jean-Daniel Cryans via Stack) NEW FEATURES HBASE-47 Option to set TTL for columns in hbase diff --git a/src/java/org/apache/hadoop/hbase/client/HTable.java b/src/java/org/apache/hadoop/hbase/client/HTable.java index 0edd19974ad..c1aada09eba 100644 --- a/src/java/org/apache/hadoop/hbase/client/HTable.java +++ b/src/java/org/apache/hadoop/hbase/client/HTable.java @@ -544,7 +544,7 @@ public class HTable { * Get selected columns for the specified row at the latest timestamp * * @param row row key - * @param columns Array of column names you want to retrieve. + * @param columns Array of column names and families you want to retrieve. * @return RowResult is empty if row does not exist. * @throws IOException */ @@ -557,7 +557,7 @@ public class HTable { * Get selected columns for the specified row at the latest timestamp * * @param row row key - * @param columns Array of column names you want to retrieve. + * @param columns Array of column names and families you want to retrieve. * @return RowResult is empty if row does not exist. * @throws IOException */ @@ -570,7 +570,7 @@ public class HTable { * Get selected columns for the specified row at the latest timestamp * * @param row row key - * @param columns Array of column names you want to retrieve. + * @param columns Array of column names and families you want to retrieve. * @return RowResult is empty if row does not exist. * @throws IOException */ @@ -583,7 +583,7 @@ public class HTable { * Get selected columns for the specified row at a specified timestamp * * @param row row key - * @param columns Array of column names you want to retrieve. + * @param columns Array of column names and families you want to retrieve. * @param ts timestamp * @return RowResult is empty if row does not exist. * @throws IOException @@ -598,7 +598,7 @@ public class HTable { * Get selected columns for the specified row at a specified timestamp * * @param row row key - * @param columns Array of column names you want to retrieve. + * @param columns Array of column names and families you want to retrieve. * @param ts timestamp * @return RowResult is empty if row does not exist. * @throws IOException @@ -613,7 +613,7 @@ public class HTable { * Get selected columns for the specified row at a specified timestamp * * @param row row key - * @param columns Array of column names you want to retrieve. + * @param columns Array of column names and families you want to retrieve. * @param ts timestamp * @return RowResult is empty if row does not exist. * @throws IOException diff --git a/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java index 70ea6ee3abf..cf4f197e8e5 100644 --- a/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -1160,6 +1160,17 @@ public class HRegion implements HConstants { for (HStore targetStore: stores.values()) { targetStore.getFull(key, columns, result); } + // Previous step won't fetch whole families: HBASE-631. + // For each column name that is just a column family, open the store + // related to it and fetch everything for that row. + if (columns != null) { + for (byte[] bs : columns) { + if (HStoreKey.getFamilyDelimiterIndex(bs) == (bs.length - 1)) { + HStore store = stores.get(Bytes.mapKey(HStoreKey.getFamily(bs))); + store.getFull(key, null, result); + } + } + } return result; } finally { releaseRowLock(lid); diff --git a/src/test/org/apache/hadoop/hbase/client/TestHTable.java b/src/test/org/apache/hadoop/hbase/client/TestHTable.java index 1bee1061343..ba24d2b2c4d 100644 --- a/src/test/org/apache/hadoop/hbase/client/TestHTable.java +++ b/src/test/org/apache/hadoop/hbase/client/TestHTable.java @@ -21,7 +21,6 @@ package org.apache.hadoop.hbase.client; import java.io.IOException; import java.util.Map; - import org.apache.hadoop.hbase.HBaseClusterTestCase; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; @@ -148,8 +147,6 @@ public class TestHTable extends HBaseClusterTestCase implements HConstants { */ public void testTableNotFoundExceptionWithATable() { try { - HColumnDescriptor column = - new HColumnDescriptor(COLUMN_FAMILY); HBaseAdmin admin = new HBaseAdmin(conf); HTableDescriptor testTableADesc = new HTableDescriptor("table"); @@ -169,4 +166,50 @@ public class TestHTable extends HBaseClusterTestCase implements HConstants { } } + public void testGetRow() { + HTable table = null; + try { + 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); + + table = new HTable(conf, tableAname); + BatchUpdate batchUpdate = new BatchUpdate(row); + + for(int i = 0; i < 5; i++) + batchUpdate.put(COLUMN_FAMILY_STR+i, Bytes.toBytes(i)); + + table.commit(batchUpdate); + + RowResult result = null; + result = table.getRow(row, new byte[][] {COLUMN_FAMILY}); + for(int i = 0; i < 5; i++) + assertTrue(result.containsKey(Bytes.toBytes(COLUMN_FAMILY_STR+i))); + + result = table.getRow(row); + for(int i = 0; i < 5; i++) + assertTrue(result.containsKey(Bytes.toBytes(COLUMN_FAMILY_STR+i))); + + batchUpdate = new BatchUpdate(row); + batchUpdate.put("info2:a", Bytes.toBytes("a")); + table.commit(batchUpdate); + + result = table.getRow(row, new byte[][] { COLUMN_FAMILY, + Bytes.toBytes("info2:a") }); + for(int i = 0; i < 5; i++) + assertTrue(result.containsKey(Bytes.toBytes(COLUMN_FAMILY_STR+i))); + assertTrue(result.containsKey(Bytes.toBytes("info2:a"))); + + } catch (IOException e) { + e.printStackTrace(); + fail("Should not have any exception " + + e.getClass()); + } + } + }