From 748b21e94a7ae3f8a18f94f8aa0bc3d33f3223ec Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Wed, 10 Sep 2008 21:13:21 +0000 Subject: [PATCH] HBASE-882 The BatchUpdate class provides, put(col, cell) and delete(col) but no get(). git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@693987 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ .../apache/hadoop/hbase/io/BatchUpdate.java | 26 +++++++++++++++++++ .../hadoop/hbase/client/TestBatchUpdate.java | 3 +++ 3 files changed, 31 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 992fd422895..9f25b33daa4 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -64,6 +64,8 @@ Release 0.18.0 - Unreleased splits (Jonathan Gray via Stack) HBASE-877 HCM is unable to find table with multiple regions which contains binary (Jonathan Gray via Stack) + HBASE-822 The BatchUpdate class provides, put(col, cell) and delete(col) + but no get() (Ryan Smith via Stack) IMPROVEMENTS HBASE-801 When a table haven't disable, shell could response in a "user diff --git a/src/java/org/apache/hadoop/hbase/io/BatchUpdate.java b/src/java/org/apache/hadoop/hbase/io/BatchUpdate.java index 9bd3ff46c63..66bc7e90a3a 100644 --- a/src/java/org/apache/hadoop/hbase/io/BatchUpdate.java +++ b/src/java/org/apache/hadoop/hbase/io/BatchUpdate.java @@ -23,6 +23,7 @@ import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Iterator; import org.apache.hadoop.hbase.HConstants; @@ -116,6 +117,31 @@ public class BatchUpdate implements Writable, Iterable { public void setTimestamp(long timestamp) { this.timestamp = timestamp; } + + /** + * Get the current value of the specified column + * + * @param column column name + * @return byte[] the cell value, returns null if the column does not exist. + */ + public synchronized byte[] get(final String column) { + return get(Bytes.toBytes(column)); + } + + /** + * Get the current value of the specified column + * + * @param column column name + * @return byte[] the cell value, returns null if the column does not exist. + */ + public synchronized byte[] get(final byte[] column) { + for (BatchOperation operation: operations) { + if (Arrays.equals(column, operation.getColumn())) { + return operation.getValue(); + } + } + return null; + } /** * Change a value for the specified column diff --git a/src/test/org/apache/hadoop/hbase/client/TestBatchUpdate.java b/src/test/org/apache/hadoop/hbase/client/TestBatchUpdate.java index 28759cc77b3..8a214ddcfa4 100644 --- a/src/test/org/apache/hadoop/hbase/client/TestBatchUpdate.java +++ b/src/test/org/apache/hadoop/hbase/client/TestBatchUpdate.java @@ -22,6 +22,7 @@ package org.apache.hadoop.hbase.client; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Map; import org.apache.hadoop.hbase.HBaseClusterTestCase; @@ -85,6 +86,8 @@ public class TestBatchUpdate extends HBaseClusterTestCase { bu = new BatchUpdate("row2"); bu.put(CONTENTS, value); + byte[] getValue = bu.get(CONTENTS); + assertTrue(Arrays.equals(getValue, value)); table.commit(bu); byte [][] columns = { CONTENTS };