diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Mutation.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Mutation.java index b02ecf6271d..50282846cbe 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Mutation.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Mutation.java @@ -39,6 +39,7 @@ import org.apache.hadoop.hbase.io.HeapSize; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.ClassSize; +import com.google.common.collect.Lists; import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; @@ -195,12 +196,25 @@ public abstract class Mutation extends OperationWithAttributes implements Row, C /** * Method for setting the put's familyMap */ - public void setFamilyMap(NavigableMap> map) { + public void setFamilyCellMap(NavigableMap> map) { // TODO: Shut this down or move it up to be a Constructor. Get new object rather than change // this internal data member. this.familyMap = map; } + /** + * Method for setting the put's familyMap that is deprecated and inefficient. + * @deprecated use {@link #setFamilyCellMap(NavigableMap)} instead. + */ + @Deprecated + public void setFamilyMap(NavigableMap> map) { + TreeMap> fm = new TreeMap>(Bytes.BYTES_COMPARATOR); + for (Map.Entry> e : map.entrySet()) { + fm.put(e.getKey(), Lists.newArrayList(e.getValue())); + } + this.familyMap = fm; + } + /** * Method to check if the familyMap is empty * @return true if empty, false otherwise diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Result.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Result.java index 6a3fb97f0bc..3612220ebc6 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Result.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Result.java @@ -29,6 +29,8 @@ import java.util.Map; import java.util.NavigableMap; import java.util.TreeMap; +import javax.annotation.Nullable; + import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.hbase.Cell; @@ -95,26 +97,45 @@ public class Result implements CellScannable { } /** - * Instantiate a Result with the specified array of KeyValues. - *
Note: You must ensure that the keyvalues - * are already sorted - * @param cells array of KeyValues + * @deprecated Use {@link #create(List)} instead. */ - public Result(Cell [] cells) { + @Deprecated + public Result(KeyValue [] cells) { this.cells = cells; } /** - * Instantiate a Result with the specified List of KeyValues. - *
Note: You must ensure that the keyvalues - * are already sorted - * @param kvs List of KeyValues + * @deprecated Use {@link #create(List)} instead. */ - public Result(List kvs) { + @Deprecated + public Result(List kvs) { // TODO: Here we presume the passed in Cells are KVs. One day this won't always be so. this(kvs.toArray(new Cell[kvs.size()])); } + /** + * Instantiate a Result with the specified List of KeyValues. + *
Note: You must ensure that the keyvalues are already sorted. + * @param cells List of cells + */ + public static Result create(List cells) { + return new Result(cells.toArray(new Cell[cells.size()])); + } + + /** + * Instantiate a Result with the specified array of KeyValues. + *
Note: You must ensure that the keyvalues are already sorted. + * @param cells array of cells + */ + public static Result create(Cell[] cells) { + return new Result(cells); + } + + /** Private ctor. Use {@link #create(Cell[])}. */ + private Result(Cell[] cells) { + this.cells = cells; + } + /** * Method for retrieving the row key that corresponds to * the row from which this Result was created. @@ -196,6 +217,13 @@ public class Result implements CellScannable { return isEmpty() ? null : Arrays.asList(raw()); } + /** + * @deprecated Use {@link #getColumnCells(byte[], byte[])} instead. + */ + @Deprecated + public List getColumn(byte [] family, byte [] qualifier) { + return KeyValueUtil.ensureKeyValues(getColumnCells(family, qualifier)); + } /** * Return the Cells for the specific column. The Cells are sorted in @@ -212,7 +240,7 @@ public class Result implements CellScannable { * @return a list of Cells for this column or empty list if the column * did not exist in the result set */ - public List getColumn(byte [] family, byte [] qualifier) { + public List getColumnCells(byte [] family, byte [] qualifier) { List result = new ArrayList(); Cell [] kvs = rawCells(); @@ -300,6 +328,14 @@ public class Result implements CellScannable { return pos; } + /** + * @deprecated Use {@link #getColumnLatestCell(byte[], byte[])} instead. + */ + @Deprecated + public KeyValue getColumnLatest(byte [] family, byte [] qualifier) { + return KeyValueUtil.ensureKeyValue(getColumnLatestCell(family, qualifier)); + } + /** * The Cell for the most recent timestamp for a given column. * @@ -309,7 +345,7 @@ public class Result implements CellScannable { * @return the Cell for the column, or null if no value exists in the row or none have been * selected in the query (Get/Scan) */ - public Cell getColumnLatest(byte [] family, byte [] qualifier) { + public Cell getColumnLatestCell(byte [] family, byte [] qualifier) { Cell [] kvs = rawCells(); // side effect possibly. if (kvs == null || kvs.length == 0) { return null; @@ -325,6 +361,16 @@ public class Result implements CellScannable { return null; } + /** + * @deprecated Use {@link #getColumnLatestCell(byte[], int, int, byte[], int, int)} instead. + */ + @Deprecated + public KeyValue getColumnLatest(byte [] family, int foffset, int flength, + byte [] qualifier, int qoffset, int qlength) { + return KeyValueUtil.ensureKeyValue( + getColumnLatestCell(family, foffset, flength, qualifier, qoffset, qlength)); + } + /** * The Cell for the most recent timestamp for a given column. * @@ -338,7 +384,7 @@ public class Result implements CellScannable { * @return the Cell for the column, or null if no value exists in the row or none have been * selected in the query (Get/Scan) */ - public Cell getColumnLatest(byte [] family, int foffset, int flength, + public Cell getColumnLatestCell(byte [] family, int foffset, int flength, byte [] qualifier, int qoffset, int qlength) { Cell [] kvs = rawCells(); // side effect possibly. @@ -363,7 +409,7 @@ public class Result implements CellScannable { * @return value of latest version of column, null if none found */ public byte[] getValue(byte [] family, byte [] qualifier) { - Cell kv = getColumnLatest(family, qualifier); + Cell kv = getColumnLatestCell(family, qualifier); if (kv == null) { return null; } @@ -380,7 +426,7 @@ public class Result implements CellScannable { */ public ByteBuffer getValueAsByteBuffer(byte [] family, byte [] qualifier) { - Cell kv = getColumnLatest(family, 0, family.length, qualifier, 0, qualifier.length); + Cell kv = getColumnLatestCell(family, 0, family.length, qualifier, 0, qualifier.length); if (kv == null) { return null; @@ -403,7 +449,7 @@ public class Result implements CellScannable { public ByteBuffer getValueAsByteBuffer(byte [] family, int foffset, int flength, byte [] qualifier, int qoffset, int qlength) { - Cell kv = getColumnLatest(family, foffset, flength, qualifier, qoffset, qlength); + Cell kv = getColumnLatestCell(family, foffset, flength, qualifier, qoffset, qlength); if (kv == null) { return null; @@ -449,7 +495,7 @@ public class Result implements CellScannable { public boolean loadValue(byte [] family, int foffset, int flength, byte [] qualifier, int qoffset, int qlength, ByteBuffer dst) throws BufferOverflowException { - Cell kv = getColumnLatest(family, foffset, flength, qualifier, qoffset, qlength); + Cell kv = getColumnLatestCell(family, foffset, flength, qualifier, qoffset, qlength); if (kv == null) { return false; @@ -486,7 +532,7 @@ public class Result implements CellScannable { public boolean containsNonEmptyColumn(byte [] family, int foffset, int flength, byte [] qualifier, int qoffset, int qlength) { - Cell kv = getColumnLatest(family, foffset, flength, qualifier, qoffset, qlength); + Cell kv = getColumnLatestCell(family, foffset, flength, qualifier, qoffset, qlength); return (kv != null) && (kv.getValueLength() > 0); } @@ -518,7 +564,7 @@ public class Result implements CellScannable { */ public boolean containsEmptyColumn(byte [] family, int foffset, int flength, byte [] qualifier, int qoffset, int qlength) { - Cell kv = getColumnLatest(family, foffset, flength, qualifier, qoffset, qlength); + Cell kv = getColumnLatestCell(family, foffset, flength, qualifier, qoffset, qlength); return (kv != null) && (kv.getValueLength() == 0); } @@ -532,7 +578,7 @@ public class Result implements CellScannable { * @return true if at least one value exists in the result, false if not */ public boolean containsColumn(byte [] family, byte [] qualifier) { - Cell kv = getColumnLatest(family, qualifier); + Cell kv = getColumnLatestCell(family, qualifier); return kv != null; } @@ -551,7 +597,7 @@ public class Result implements CellScannable { public boolean containsColumn(byte [] family, int foffset, int flength, byte [] qualifier, int qoffset, int qlength) { - return getColumnLatest(family, foffset, flength, qualifier, qoffset, qlength) != null; + return getColumnLatestCell(family, foffset, flength, qualifier, qoffset, qlength) != null; } /** diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java index 9e5735d7c95..1c30b0c6e52 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java @@ -1060,7 +1060,7 @@ public final class ProtobufUtil { for (CellProtos.Cell c: values) { cells.add(toCell(c)); } - return new Result(cells); + return Result.create(cells); } /** @@ -1088,7 +1088,7 @@ public final class ProtobufUtil { for (CellProtos.Cell c: values) { cells.add(toCell(c)); } - return new Result(cells); + return Result.create(cells); } /** diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ResponseConverter.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ResponseConverter.java index 3a2823fe78a..29faf1a65f0 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ResponseConverter.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ResponseConverter.java @@ -309,7 +309,7 @@ public final class ResponseConverter { } cells.add(cellScanner.current()); } - results[i] = new Result(cells); + results[i] = Result.create(cells); } else { // Result is pure pb. results[i] = ProtobufUtil.toResult(response.getResults(i)); diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java index e7b88d5a6b8..90aef087320 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java @@ -19,6 +19,8 @@ package org.apache.hadoop.hbase; import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.hbase.util.ByteBufferUtils; @@ -27,6 +29,9 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.IterableUtils; import org.apache.hadoop.io.WritableUtils; +import com.google.common.base.Function; +import com.google.common.collect.Lists; + /** * static convenience methods for dealing with KeyValues and collections of KeyValues */ @@ -203,4 +208,13 @@ public class KeyValueUtil { if (cell == null) return null; return cell instanceof KeyValue? (KeyValue)cell: copyToNewKeyValue(cell); } + + public static List ensureKeyValues(List cells) { + List lazyList = Lists.transform(cells, new Function() { + public KeyValue apply(Cell arg0) { + return KeyValueUtil.ensureKeyValue(arg0); + } + }); + return new ArrayList(lazyList); + } } diff --git a/hbase-examples/src/test/java/org/apache/hadoop/hbase/coprocessor/example/TestBulkDeleteProtocol.java b/hbase-examples/src/test/java/org/apache/hadoop/hbase/coprocessor/example/TestBulkDeleteProtocol.java index 4aecb7d7a7e..8dbb16c9531 100644 --- a/hbase-examples/src/test/java/org/apache/hadoop/hbase/coprocessor/example/TestBulkDeleteProtocol.java +++ b/hbase-examples/src/test/java/org/apache/hadoop/hbase/coprocessor/example/TestBulkDeleteProtocol.java @@ -202,9 +202,9 @@ public class TestBulkDeleteProtocol { int rows = 0; for (Result result : ht.getScanner(new Scan())) { assertEquals(2, result.getFamilyMap(FAMILY1).size()); - assertTrue(result.getColumn(FAMILY1, QUALIFIER2).isEmpty()); - assertEquals(1, result.getColumn(FAMILY1, QUALIFIER1).size()); - assertEquals(1, result.getColumn(FAMILY1, QUALIFIER3).size()); + assertTrue(result.getColumnCells(FAMILY1, QUALIFIER2).isEmpty()); + assertEquals(1, result.getColumnCells(FAMILY1, QUALIFIER1).size()); + assertEquals(1, result.getColumnCells(FAMILY1, QUALIFIER3).size()); rows++; } assertEquals(100, rows); @@ -235,7 +235,7 @@ public class TestBulkDeleteProtocol { int rows = 0; for (Result result : ht.getScanner(new Scan())) { assertTrue(result.getFamilyMap(FAMILY1).isEmpty()); - assertEquals(1, result.getColumn(FAMILY2, QUALIFIER2).size()); + assertEquals(1, result.getColumnCells(FAMILY2, QUALIFIER2).size()); rows++; } assertEquals(100, rows); @@ -273,15 +273,15 @@ public class TestBulkDeleteProtocol { scan.setMaxVersions(); for (Result result : ht.getScanner(scan)) { assertEquals(3, result.getFamilyMap(FAMILY1).size()); - List column = result.getColumn(FAMILY1, QUALIFIER1); + List column = result.getColumnCells(FAMILY1, QUALIFIER1); assertEquals(1, column.size()); assertTrue(CellUtil.matchingValue(column.get(0), "v1".getBytes())); - column = result.getColumn(FAMILY1, QUALIFIER2); + column = result.getColumnCells(FAMILY1, QUALIFIER2); assertEquals(1, column.size()); assertTrue(CellUtil.matchingValue(column.get(0), "v1".getBytes())); - column = result.getColumn(FAMILY1, QUALIFIER3); + column = result.getColumnCells(FAMILY1, QUALIFIER3); assertEquals(1, column.size()); assertTrue(CellUtil.matchingValue(column.get(0), "v1".getBytes())); rows++; @@ -325,9 +325,9 @@ public class TestBulkDeleteProtocol { scan.setMaxVersions(); for (Result result : ht.getScanner(scan)) { assertEquals(3, result.getFamilyMap(FAMILY1).size()); - assertEquals(3, result.getColumn(FAMILY1, QUALIFIER1).size()); - assertEquals(3, result.getColumn(FAMILY1, QUALIFIER2).size()); - List column = result.getColumn(FAMILY1, QUALIFIER3); + assertEquals(3, result.getColumnCells(FAMILY1, QUALIFIER1).size()); + assertEquals(3, result.getColumnCells(FAMILY1, QUALIFIER2).size()); + List column = result.getColumnCells(FAMILY1, QUALIFIER3); assertEquals(2, column.size()); assertTrue(CellUtil.matchingValue(column.get(0), "v3".getBytes())); assertTrue(CellUtil.matchingValue(column.get(1), "v1".getBytes())); @@ -407,15 +407,15 @@ public class TestBulkDeleteProtocol { scan1.setMaxVersions(); for (Result res : ht.getScanner(scan1)) { assertEquals(3, res.getFamilyMap(FAMILY1).size()); - List column = res.getColumn(FAMILY1, QUALIFIER1); + List column = res.getColumnCells(FAMILY1, QUALIFIER1); assertEquals(2, column.size()); assertTrue(CellUtil.matchingValue(column.get(0), "v4".getBytes())); assertTrue(CellUtil.matchingValue(column.get(1), "v3".getBytes())); - column = res.getColumn(FAMILY1, QUALIFIER2); + column = res.getColumnCells(FAMILY1, QUALIFIER2); assertEquals(2, column.size()); assertTrue(CellUtil.matchingValue(column.get(0), "v4".getBytes())); assertTrue(CellUtil.matchingValue(column.get(1), "v3".getBytes())); - assertEquals(4, res.getColumn(FAMILY1, QUALIFIER3).size()); + assertEquals(4, res.getColumnCells(FAMILY1, QUALIFIER3).size()); rows++; } assertEquals(100, rows); diff --git a/hbase-it/src/test/java/org/apache/hadoop/hbase/mapreduce/IntegrationTestBulkLoad.java b/hbase-it/src/test/java/org/apache/hadoop/hbase/mapreduce/IntegrationTestBulkLoad.java index f9d1bcac311..5aad5ec3db0 100644 --- a/hbase-it/src/test/java/org/apache/hadoop/hbase/mapreduce/IntegrationTestBulkLoad.java +++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/mapreduce/IntegrationTestBulkLoad.java @@ -470,7 +470,7 @@ public class IntegrationTestBulkLoad extends IntegrationTestBase { for (Map.Entry entry : value.getFamilyMap(CHAIN_FAM).entrySet()) { long chainId = Bytes.toLong(entry.getKey()); long next = Bytes.toLong(entry.getValue()); - Cell c = value.getColumn(SORT_FAM, entry.getKey()).get(0); + Cell c = value.getColumnCells(SORT_FAM, entry.getKey()).get(0); long order = Bytes.toLong(CellUtil.cloneValue(c)); context.write(new LinkKey(chainId, order), new LinkChain(longRk, next)); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/TableNamespaceManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/TableNamespaceManager.java index 5f31258bd93..975f0602cac 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/TableNamespaceManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/TableNamespaceManager.java @@ -170,8 +170,8 @@ public class TableNamespaceManager { if (res.isEmpty()) { return null; } - byte[] val = CellUtil.cloneValue(res.getColumnLatest(HTableDescriptor.NAMESPACE_FAMILY_INFO_BYTES, - HTableDescriptor.NAMESPACE_COL_DESC_BYTES)); + byte[] val = CellUtil.cloneValue(res.getColumnLatestCell( + HTableDescriptor.NAMESPACE_FAMILY_INFO_BYTES, HTableDescriptor.NAMESPACE_COL_DESC_BYTES)); return ProtobufUtil.toNamespaceDescriptor( HBaseProtos.NamespaceDescriptor.parseFrom(val)); @@ -241,7 +241,8 @@ public class TableNamespaceManager { ResultScanner scanner = getNamespaceTable().getScanner(HTableDescriptor.NAMESPACE_FAMILY_INFO_BYTES); try { for(Result r : scanner) { - byte[] val = CellUtil.cloneValue(r.getColumnLatest(HTableDescriptor.NAMESPACE_FAMILY_INFO_BYTES, + byte[] val = CellUtil.cloneValue(r.getColumnLatestCell( + HTableDescriptor.NAMESPACE_FAMILY_INFO_BYTES, HTableDescriptor.NAMESPACE_COL_DESC_BYTES)); ret.add(ProtobufUtil.toNamespaceDescriptor( HBaseProtos.NamespaceDescriptor.parseFrom(val))); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index e6830efaa9c..87d6d26e605 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -1787,7 +1787,7 @@ public class HRegion implements HeapSize { // , Writable{ void delete(NavigableMap> familyMap, Durability durability) throws IOException { Delete delete = new Delete(FOR_UNIT_TESTS_ONLY); - delete.setFamilyMap(familyMap); + delete.setFamilyCellMap(familyMap); delete.setDurability(durability); doBatchMutate(delete); } @@ -2598,7 +2598,7 @@ public class HRegion implements HeapSize { // , Writable{ familyMap.put(family, edits); Put p = new Put(row); - p.setFamilyMap(familyMap); + p.setFamilyCellMap(familyMap); doBatchMutate(p); } @@ -4372,7 +4372,7 @@ public class HRegion implements HeapSize { // , Writable{ } } List results = get(get, true); - return new Result(results); + return Result.create(results); } /* @@ -4810,7 +4810,7 @@ public class HRegion implements HeapSize { // , Writable{ } - return append.isReturnResults() ? new Result(allKVs) : null; + return append.isReturnResults() ? Result.create(allKVs) : null; } /** @@ -4955,7 +4955,7 @@ public class HRegion implements HeapSize { // , Writable{ requestFlush(); } - return new Result(allKVs); + return Result.create(allKVs); } // diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index b447f72e0ed..917e867093a 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -3136,7 +3136,7 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa currentScanResultSize += KeyValueUtil.ensureKeyValue(kv).heapSize(); } } - results.add(new Result(values)); + results.add(Result.create(values)); } if (!moreRows) { break; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java index 019e80cb52b..236026bdd57 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java @@ -176,7 +176,7 @@ public class RemoteHTable implements HTableInterface { kvs.add(new KeyValue(row.getKey(), column, qualifier, cell.getTimestamp(), cell.getValue())); } - results.add(new Result(kvs)); + results.add(Result.create(kvs)); } return results.toArray(new Result[results.size()]); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestSerialization.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestSerialization.java index d39c3fe8919..7bd499d62a6 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestSerialization.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestSerialization.java @@ -345,7 +345,7 @@ public class TestSerialization { * TODO @Test public void testResultEmpty() throws Exception { List keys = new ArrayList(); - Result r = new Result(keys); + Result r = Result.newResult(keys); assertTrue(r.isEmpty()); byte [] rb = Writables.getBytes(r); Result deserializedR = (Result)Writables.getWritable(rb, new Result()); @@ -367,7 +367,7 @@ public class TestSerialization { KeyValue kvA = new KeyValue(rowA, famA, qfA, valueA); KeyValue kvB = new KeyValue(rowB, famB, qfB, valueB); - Result result = new Result(new KeyValue[]{kvA, kvB}); + Result result = Result.newResult(new KeyValue[]{kvA, kvB}); byte [] rb = Writables.getBytes(result); Result deResult = (Result)Writables.getWritable(rb, new Result()); @@ -399,7 +399,7 @@ public class TestSerialization { KeyValue kvA = new KeyValue(rowA, famA, qfA, valueA); KeyValue kvB = new KeyValue(rowB, famB, qfB, valueB); - Result result = new Result(new KeyValue[]{kvA, kvB}); + Result result = Result.newResult(new KeyValue[]{kvA, kvB}); byte [] rb = Writables.getBytes(result); @@ -441,9 +441,9 @@ public class TestSerialization { KeyValue kvB = new KeyValue(rowB, famB, qfB, valueB); - Result result1 = new Result(new KeyValue[]{kvA, kvB}); - Result result2 = new Result(new KeyValue[]{kvB}); - Result result3 = new Result(new KeyValue[]{kvB}); + Result result1 = Result.newResult(new KeyValue[]{kvA, kvB}); + Result result2 = Result.newResult(new KeyValue[]{kvB}); + Result result3 = Result.newResult(new KeyValue[]{kvB}); Result [] results = new Result [] {result1, result2, result3}; @@ -477,7 +477,7 @@ public class TestSerialization { @Test public void testResultArrayEmpty() throws Exception { List keys = new ArrayList(); - Result r = new Result(keys); + Result r = Result.newResult(keys); Result [] results = new Result [] {r}; ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/catalog/MetaMockingUtil.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/catalog/MetaMockingUtil.java index 3f4544ed761..9177073602f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/catalog/MetaMockingUtil.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/catalog/MetaMockingUtil.java @@ -107,7 +107,7 @@ public class MetaMockingUtil { //important: sort the kvs so that binary search work Collections.sort(kvs, KeyValue.META_COMPARATOR); - return new Result(kvs); + return Result.create(kvs); } /** diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/catalog/TestMetaReaderEditorNoCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/catalog/TestMetaReaderEditorNoCluster.java index 7f1927b27e3..3261052525c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/catalog/TestMetaReaderEditorNoCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/catalog/TestMetaReaderEditorNoCluster.java @@ -99,26 +99,26 @@ public class TestMetaReaderEditorNoCluster { assertNull(HRegionInfo.getHRegionInfo(new Result())); List kvs = new ArrayList(); - Result r = new Result(kvs); + Result r = Result.create(kvs); assertNull(HRegionInfo.getHRegionInfo(r)); byte [] f = HConstants.CATALOG_FAMILY; // Make a key value that doesn't have the expected qualifier. kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY, f, HConstants.SERVER_QUALIFIER, f)); - r = new Result(kvs); + r = Result.create(kvs); assertNull(HRegionInfo.getHRegionInfo(r)); // Make a key that does not have a regioninfo value. kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY, f, HConstants.REGIONINFO_QUALIFIER, f)); - HRegionInfo hri = HRegionInfo.getHRegionInfo(new Result(kvs)); + HRegionInfo hri = HRegionInfo.getHRegionInfo(Result.create(kvs)); assertTrue(hri == null); // OK, give it what it expects kvs.clear(); kvs.add(new KeyValue(HConstants.EMPTY_BYTE_ARRAY, f, HConstants.REGIONINFO_QUALIFIER, HRegionInfo.FIRST_META_REGIONINFO.toByteArray())); - hri = HRegionInfo.getHRegionInfo(new Result(kvs)); + hri = HRegionInfo.getHRegionInfo(Result.create(kvs)); assertNotNull(hri); assertTrue(hri.equals(HRegionInfo.FIRST_META_REGIONINFO)); } @@ -165,7 +165,7 @@ public class TestMetaReaderEditorNoCluster { HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER, Bytes.toBytes(sn.getStartcode()))); final List cellScannables = new ArrayList(1); - cellScannables.add(new Result(kvs)); + cellScannables.add(Result.create(kvs)); final ScanResponse.Builder builder = ScanResponse.newBuilder(); for (CellScannable result : cellScannables) { builder.addCellsPerResult(((Result)result).size()); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestIntraRowPagination.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestIntraRowPagination.java index cedefbc071c..0fb190a43be 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestIntraRowPagination.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestIntraRowPagination.java @@ -96,7 +96,7 @@ public class TestIntraRowPagination { kvListScan.addAll(results); results.clear(); } - result = new Result(kvListScan); + result = Result.create(kvListScan); TestScannersFromClientSide.verifyResult(result, kvListExp, toLog, "Testing scan with storeOffset and storeLimit"); } finally { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestPutDeleteEtcCellIteration.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestPutDeleteEtcCellIteration.java index 54f78539511..bc0bc585a55 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestPutDeleteEtcCellIteration.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestPutDeleteEtcCellIteration.java @@ -138,7 +138,7 @@ public class TestPutDeleteEtcCellIteration { byte [] bytes = Bytes.toBytes(i); cells[i] = new KeyValue(ROW, bytes, bytes, TIMESTAMP, bytes); } - Result r = new Result(Arrays.asList(cells)); + Result r = Result.create(Arrays.asList(cells)); int index = 0; for (CellScanner cellScanner = r.cellScanner(); cellScanner.advance();) { Cell cell = cellScanner.current(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestResult.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestResult.java index 989b4d1041c..74563f0f17b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestResult.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestResult.java @@ -65,15 +65,15 @@ public class TestResult extends TestCase { Arrays.sort(kvs, KeyValue.COMPARATOR); - Result r = new Result(kvs); + Result r = Result.create(kvs); for (int i = 0; i < 100; ++i) { final byte[] qf = Bytes.toBytes(i); - List ks = r.getColumn(family, qf); + List ks = r.getColumnCells(family, qf); assertEquals(1, ks.size()); assertTrue(CellUtil.matchingQualifier(ks.get(0), qf)); - assertEquals(ks.get(0), r.getColumnLatest(family, qf)); + assertEquals(ks.get(0), r.getColumnLatestCell(family, qf)); } } @@ -87,15 +87,15 @@ public class TestResult extends TestCase { Arrays.sort(kvs, KeyValue.COMPARATOR); - Result r = new Result(kvs); + Result r = Result.create(kvs); for (int i = 0; i < 100; ++i) { final byte[] qf = Bytes.toBytes(i); - List ks = r.getColumn(family, qf); + List ks = r.getColumnCells(family, qf); assertEquals(2, ks.size()); assertTrue(CellUtil.matchingQualifier(ks.get(0), qf)); assertEquals(200, ks.get(0).getTimestamp()); - assertEquals(ks.get(0), r.getColumnLatest(family, qf)); + assertEquals(ks.get(0), r.getColumnLatestCell(family, qf)); } } @@ -104,7 +104,7 @@ public class TestResult extends TestCase { Arrays.sort(kvs, KeyValue.COMPARATOR); - Result r = new Result(kvs); + Result r = Result.create(kvs); for (int i = 0; i < 100; ++i) { final byte[] qf = Bytes.toBytes(i); @@ -124,7 +124,7 @@ public class TestResult extends TestCase { Arrays.sort(kvs, KeyValue.COMPARATOR); - Result r = new Result(kvs); + Result r = Result.create(kvs); for (int i = 0; i < 100; ++i) { final byte[] qf = Bytes.toBytes(i); @@ -138,7 +138,7 @@ public class TestResult extends TestCase { Arrays.sort(kvs, KeyValue.COMPARATOR); - Result r = new Result(kvs); + Result r = Result.create(kvs); ByteBuffer loadValueBuffer = ByteBuffer.allocate(1024); for (int i = 0; i < 100; ++i) { @@ -165,7 +165,7 @@ public class TestResult extends TestCase { ByteBuffer loadValueBuffer = ByteBuffer.allocate(1024); - Result r = new Result(kvs); + Result r = Result.create(kvs); for (int i = 0; i < 100; ++i) { final byte[] qf = Bytes.toBytes(i); @@ -188,8 +188,8 @@ public class TestResult extends TestCase { KeyValue kv1 = new KeyValue(row, family, qual, value); KeyValue kv2 = new KeyValue(row, family, qual, value1); - Result r1 = new Result(new KeyValue[] {kv1}); - Result r2 = new Result(new KeyValue[] {kv2}); + Result r1 = Result.create(new KeyValue[] {kv1}); + Result r2 = Result.create(new KeyValue[] {kv2}); // no exception thrown Result.compareResults(r1, r1); try { @@ -226,7 +226,7 @@ public class TestResult extends TestCase { Bytes.toBytes(valueSB.toString()), 1, n); Arrays.sort(kvs, KeyValue.COMPARATOR); ByteBuffer loadValueBuffer = ByteBuffer.allocate(1024); - Result r = new Result(kvs); + Result r = Result.create(kvs); byte[][] qfs = new byte[n][Bytes.SIZEOF_INT]; for (int i = 0; i < n; ++i) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannersFromClientSide.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannersFromClientSide.java index 1289b4ea1c3..edfa4ac277e 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannersFromClientSide.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestScannersFromClientSide.java @@ -324,7 +324,7 @@ public class TestScannersFromClientSide { kvListScan.add(kv); } } - result = new Result(kvListScan); + result = Result.create(kvListScan); verifyResult(result, kvListExp, toLog, "Testing scan with maxResults"); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestChangingEncoding.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestChangingEncoding.java index 5873709a845..8b173f82626 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestChangingEncoding.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestChangingEncoding.java @@ -156,7 +156,7 @@ public class TestChangingEncoding { Get get = new Get(getRowKey(batchId, i)); Result result = table.get(get); for (int j = 0; j < NUM_COLS_PER_ROW; ++j) { - Cell kv = result.getColumnLatest(CF_BYTES, getQualifier(j)); + Cell kv = result.getColumnLatestCell(CF_BYTES, getQualifier(j)); assertTrue(CellUtil.matchingValue(kv, getValue(batchId, i, j))); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java index 7afcf13e9f7..7a09c3a20a1 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java @@ -294,7 +294,7 @@ public class TestHRegion extends HBaseTestCase { Get get = new Get(row); Result result = region.get(get); for (long i = minSeqId; i <= maxSeqId; i += 10) { - List kvs = result.getColumn(family, Bytes.toBytes(i)); + List kvs = result.getColumnCells(family, Bytes.toBytes(i)); assertEquals(1, kvs.size()); assertEquals(Bytes.toBytes(i), CellUtil.cloneValue(kvs.get(0))); } @@ -347,7 +347,7 @@ public class TestHRegion extends HBaseTestCase { Get get = new Get(row); Result result = region.get(get); for (long i = minSeqId; i <= maxSeqId; i += 10) { - List kvs = result.getColumn(family, Bytes.toBytes(i)); + List kvs = result.getColumnCells(family, Bytes.toBytes(i)); if (i < recoverSeqId) { assertEquals(0, kvs.size()); } else { @@ -3609,7 +3609,7 @@ public class TestHRegion extends HBaseTestCase { get.addColumn(Incrementer.family, Incrementer.qualifier); get.setMaxVersions(1); Result res = this.region.get(get); - List kvs = res.getColumn(Incrementer.family, + List kvs = res.getColumnCells(Incrementer.family, Incrementer.qualifier); //we just got the latest version @@ -3703,7 +3703,7 @@ public class TestHRegion extends HBaseTestCase { get.addColumn(Appender.family, Appender.qualifier); get.setMaxVersions(1); Result res = this.region.get(get); - List kvs = res.getColumn(Appender.family, + List kvs = res.getColumnCells(Appender.family, Appender.qualifier); //we just got the latest version @@ -3740,7 +3740,7 @@ public class TestHRegion extends HBaseTestCase { get.addColumn(family, qualifier); get.setMaxVersions(); res = this.region.get(get); - kvs = res.getColumn(family, qualifier); + kvs = res.getColumnCells(family, qualifier); assertEquals(1, kvs.size()); assertEquals(Bytes.toBytes("value0"), CellUtil.cloneValue(kvs.get(0))); @@ -3749,7 +3749,7 @@ public class TestHRegion extends HBaseTestCase { get.addColumn(family, qualifier); get.setMaxVersions(); res = this.region.get(get); - kvs = res.getColumn(family, qualifier); + kvs = res.getColumnCells(family, qualifier); assertEquals(1, kvs.size()); assertEquals(Bytes.toBytes("value0"), CellUtil.cloneValue(kvs.get(0))); @@ -3761,7 +3761,7 @@ public class TestHRegion extends HBaseTestCase { get.addColumn(family, qualifier); get.setMaxVersions(); res = this.region.get(get); - kvs = res.getColumn(family, qualifier); + kvs = res.getColumnCells(family, qualifier); assertEquals(1, kvs.size()); assertEquals(Bytes.toBytes("value1"), CellUtil.cloneValue(kvs.get(0))); @@ -3770,7 +3770,7 @@ public class TestHRegion extends HBaseTestCase { get.addColumn(family, qualifier); get.setMaxVersions(); res = this.region.get(get); - kvs = res.getColumn(family, qualifier); + kvs = res.getColumnCells(family, qualifier); assertEquals(1, kvs.size()); assertEquals(Bytes.toBytes("value1"), CellUtil.cloneValue(kvs.get(0))); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestKeepDeletes.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestKeepDeletes.java index bbc9057f472..4f8794c29c7 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestKeepDeletes.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestKeepDeletes.java @@ -832,7 +832,7 @@ public class TestKeepDeletes { private void checkResult(Result r, byte[] fam, byte[] col, byte[] ... vals) { assertEquals(r.size(), vals.length); - List kvs = r.getColumn(fam, col); + List kvs = r.getColumnCells(fam, col); assertEquals(kvs.size(), vals.length); for (int i=0;i kvs = r.getColumn(col, col); + List kvs = r.getColumnCells(col, col); assertEquals(kvs.size(), vals.length); for (int i=0;i