HBASE-631 HTable.getRow() for only a column family

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@674724 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2008-07-08 05:24:36 +00:00
parent 20f56cc97d
commit e157ffc9c6
4 changed files with 65 additions and 9 deletions

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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());
}
}
}