commit 46a730848c82e7615ac73bc0325f127511574f60 Author: Ryan Rawson Date: Tue Aug 10 13:51:04 2010 -0700 performance speedup for thrift serialization of results diff --git a/src/java/org/apache/hadoop/hbase/thrift/ThriftServer.java b/src/java/org/apache/hadoop/hbase/thrift/ThriftServer.java index 2a5bbf0..bf71e17 100644 --- a/src/java/org/apache/hadoop/hbase/thrift/ThriftServer.java +++ b/src/java/org/apache/hadoop/hbase/thrift/ThriftServer.java @@ -481,7 +481,7 @@ public class ThriftServer { Get get = new Get(row); get.setTimeRange(Long.MIN_VALUE, timestamp); Result result = table.get(get); - return ThriftUtilities.rowResultFromHBase(result.getRowResult()); + return ThriftUtilities.rowResultFromHBase(result); } byte[][] columnArr = columns.toArray(new byte[columns.size()][]); Get get = new Get(row); @@ -495,7 +495,7 @@ public class ThriftServer { } get.setTimeRange(Long.MIN_VALUE, timestamp); Result result = table.get(get); - return ThriftUtilities.rowResultFromHBase(result.getRowResult()); + return ThriftUtilities.rowResultFromHBase(result); } catch (IOException e) { throw new IOError(e.getMessage()); } diff --git a/src/java/org/apache/hadoop/hbase/thrift/ThriftUtilities.java b/src/java/org/apache/hadoop/hbase/thrift/ThriftUtilities.java index f285d70..f6ace5a 100644 --- a/src/java/org/apache/hadoop/hbase/thrift/ThriftUtilities.java +++ b/src/java/org/apache/hadoop/hbase/thrift/ThriftUtilities.java @@ -19,11 +19,13 @@ package org.apache.hadoop.hbase.thrift; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.TreeMap; import org.apache.hadoop.hbase.HColumnDescriptor; +import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.io.Cell; import org.apache.hadoop.hbase.io.RowResult; @@ -35,11 +37,11 @@ import org.apache.hadoop.hbase.thrift.generated.TRowResult; import org.apache.hadoop.hbase.util.Bytes; public class ThriftUtilities { - + /** * This utility method creates a new Hbase HColumnDescriptor object based on a * Thrift ColumnDescriptor "struct". - * + * * @param in * Thrift ColumnDescriptor object * @return HColumnDescriptor @@ -53,7 +55,7 @@ public class ThriftUtilities { if (in.bloomFilterType.compareTo("NONE") != 0) { bloom = true; } - + if (in.name == null || in.name.length <= 0) { throw new IllegalArgument("column name is empty"); } @@ -62,11 +64,11 @@ public class ThriftUtilities { in.timeToLive, bloom); return col; } - + /** * This utility method creates a new Thrift ColumnDescriptor "struct" based on * an Hbase HColumnDescriptor object. - * + * * @param in * Hbase HColumnDescriptor object * @return Thrift ColumnDescriptor @@ -81,11 +83,11 @@ public class ThriftUtilities { col.bloomFilterType = Boolean.toString(in.isBloomfilter()); return col; } - + /** * This utility method creates a list of Thrift TCell "struct" based on * an Hbase Cell object. The empty list is returned if the input is null. - * + * * @param in * Hbase Cell object * @return Thrift TCell array @@ -121,7 +123,7 @@ public class ThriftUtilities { * This utility method creates a list of Thrift TRowResult "struct" based on * an Hbase RowResult object. The empty list is returned if the input is * null. - * + * * @param in * Hbase RowResult object * @return Thrift TRowResult array @@ -154,28 +156,24 @@ public class ThriftUtilities { * This utility method creates a list of Thrift TRowResult "struct" based on * an Hbase RowResult object. The empty list is returned if the input is * null. - * + * * @param in * Hbase RowResult object * @return Thrift TRowResult array */ static public List rowResultFromHBase(Result[] in) { - List results = new ArrayList(); - for ( Result result_ : in) { - if(null == result_) { - continue; - } - RowResult rowResult_ = result_.getRowResult(); - TRowResult result = new TRowResult(); - result.row = rowResult_.getRow(); - result.columns = new TreeMap(Bytes.BYTES_COMPARATOR); - for (Map.Entry entry : rowResult_.entrySet()){ - Cell cell = entry.getValue(); - result.columns.put(entry.getKey(), - new TCell(cell.getValue(), cell.getTimestamp())); + List results = new ArrayList(in.length); + for (Result row : in) { + KeyValue [] kvs = row.raw(); + if (kvs.length == 0) { + continue; + } - } - results.add(result); + Map cols = new TreeMap(Bytes.BYTES_COMPARATOR); + for (KeyValue kv : kvs) { + cols.put(kv.getColumn(), new TCell(kv.getValue(), kv.getTimestamp())); + } + results.add( new TRowResult(kvs[0].getRow(), cols)); } return results; } @@ -187,7 +185,7 @@ public class ThriftUtilities { new TCell(c.getValue(), c.getTimestamp())); return result; } - + static public List rowResultFromHBase(Result in) { Result [] result = { in }; return rowResultFromHBase(result);