Skip to content

Commit

Permalink
Avoid needless conversion to/from Bytes in HBase benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
toddlipcon authored and brianfrankcooper committed Apr 26, 2010
1 parent ed39c11 commit e62af2c
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/com/yahoo/ycsb/db/HBaseClient.java
Expand Up @@ -47,6 +47,7 @@ public class HBaseClient extends com.yahoo.ycsb.DB
public String _table="";
public HTable _hTable=null;
public String _columnFamily="";
public byte _columnFamilyBytes[];

public static final int Ok=0;
public static final int ServerError=-1;
Expand All @@ -73,7 +74,7 @@ public void init() throws DBException
System.err.println("Error, must specify a columnfamily for HBase table");
throw new DBException("No columnfamily specified");
}

_columnFamilyBytes = Bytes.toBytes(_columnFamily);

}

Expand Down Expand Up @@ -155,7 +156,7 @@ public int read(String table, String key, Set<String> fields, HashMap<String,Str
//now parse out all desired fields
if (fields != null) {
for (String field : fields) {
byte[] value = r.getValue(Bytes.toBytes(_columnFamily),Bytes.toBytes(field));
byte[] value = r.getValue(_columnFamilyBytes, Bytes.toBytes(field));
result.put(field,Bytes.toString(value));
if (_debug) {
System.out.println("Result for field: "+field+" is: "+Bytes.toString(value));
Expand Down Expand Up @@ -200,13 +201,13 @@ public int scan(String table, String startkey, int recordcount, Set<String> fiel
//add specified fields or else all fields
if (fields == null)
{
s.addFamily(Bytes.toBytes(_columnFamily));
s.addFamily(_columnFamilyBytes);
}
else
{
for (String field : fields)
{
s.addColumn(Bytes.toBytes(_columnFamily),Bytes.toBytes(field));
s.addColumn(_columnFamilyBytes,Bytes.toBytes(field));
}
}

Expand All @@ -230,7 +231,7 @@ public int scan(String table, String startkey, int recordcount, Set<String> fiel
if (fields != null) //parse specified field list
{
for (String field : fields) {
byte[] value = rr.getValue(Bytes.toBytes(_columnFamily),Bytes.toBytes(field));
byte[] value = rr.getValue(_columnFamilyBytes,Bytes.toBytes(field));
rowResult.put(field,Bytes.toString(value));
if (_debug)
{
Expand All @@ -241,7 +242,7 @@ public int scan(String table, String startkey, int recordcount, Set<String> fiel
else //get all fields
{
//HBase can return a mapping for all columns in a column family
NavigableMap<byte[], byte[]> scanMap = rr.getFamilyMap(Bytes.toBytes(_columnFamily));
NavigableMap<byte[], byte[]> scanMap = rr.getFamilyMap(_columnFamilyBytes);
for (byte[] fieldkey : scanMap.keySet())
{
String value = Bytes.toString(scanMap.get(fieldkey));
Expand Down Expand Up @@ -311,13 +312,13 @@ public int update(String table, String key, HashMap<String,String> values)
System.out.println("Setting up put for key: "+key);
}
Put p = new Put(Bytes.toBytes(key));
for (String fieldkey : values.keySet())
for (Map.Entry<String, String> entry : values.entrySet())
{
String value = values.get(fieldkey);
if (_debug) {
System.out.println("Adding field/value " + fieldkey + "/"+value+" to put request");
System.out.println("Adding field/value " + entry.getKey() + "/"+
entry.getValue() + " to put request");
}
p.add(Bytes.toBytes(_columnFamily),Bytes.toBytes(fieldkey),Bytes.toBytes(value));
p.add(_columnFamilyBytes,Bytes.toBytes(entry.getKey()),Bytes.toBytes(entry.getValue()));
}

try
Expand Down

0 comments on commit e62af2c

Please sign in to comment.