| ();
}
list.add(new KeyValue(
this.row, family, qualifier, timestamp, KeyValue.Type.Delete));
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Get.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Get.java
index b3b1adc..0b6636d 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Get.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Get.java
@@ -41,8 +41,7 @@ import java.util.TreeSet;
* Used to perform Get operations on a single row.
*
* To get everything for a row, instantiate a Get object with the row to get.
- * To further define the scope of what to get, perform additional methods as
- * outlined below.
+ * To further narrow the scope of what to Get, use the methods below.
*
* To get all columns from specific families, execute {@link #addFamily(byte[]) addFamily}
* for each family to retrieve.
@@ -59,7 +58,7 @@ import java.util.TreeSet;
* To limit the number of versions of each column to be returned, execute
* {@link #setMaxVersions(int) setMaxVersions}.
*
- * To add a filter, execute {@link #setFilter(Filter) setFilter}.
+ * To add a filter, call {@link #setFilter(Filter) setFilter}.
*/
@InterfaceAudience.Public
@InterfaceStability.Stable
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HTable.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HTable.java
index 9a9128e..236a847 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HTable.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HTable.java
@@ -67,6 +67,7 @@ import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.CompareType;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.hbase.util.Threads;
+import org.apache.hbase.Cell;
import com.google.protobuf.Service;
import com.google.protobuf.ServiceException;
@@ -1099,9 +1100,10 @@ public class HTable implements HTableInterface {
throw new IllegalArgumentException("No columns to insert");
}
if (maxKeyValueSize > 0) {
- for (List list : put.getFamilyMap().values()) {
- for (KeyValue kv : list) {
- if (kv.getLength() > maxKeyValueSize) {
+ for (List extends Cell> list : put.getFamilyMap().values()) {
+ for (Cell cell : list) {
+ // KeyValue v1 expectation. Cast for now.
+ if (((KeyValue)cell).getLength() > maxKeyValueSize) {
throw new IllegalArgumentException("KeyValue size too large");
}
}
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Increment.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Increment.java
index 8e59bd6..690ff72 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Increment.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Increment.java
@@ -19,15 +19,18 @@
package org.apache.hadoop.hbase.client;
import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
import java.util.Map;
-import java.util.NavigableMap;
-import java.util.Set;
-import java.util.TreeMap;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.io.HeapSize;
import org.apache.hadoop.hbase.io.TimeRange;
import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hbase.Cell;
/**
* Used to perform Increment operations on a single row.
@@ -43,15 +46,8 @@ import org.apache.hadoop.hbase.util.Bytes;
*/
@InterfaceAudience.Public
@InterfaceStability.Stable
-public class Increment implements Row {
- private byte [] row = null;
- private boolean writeToWAL = true;
+public class Increment extends Mutation implements HeapSize, Comparable {
private TimeRange tr = new TimeRange();
- private Map> familyMap =
- new TreeMap>(Bytes.BYTES_COMPARATOR);
-
- /** Constructor for Writable. DO NOT USE */
- public Increment() {}
/**
* Create a Increment operation for the specified row, using an existing row
@@ -61,10 +57,10 @@ public class Increment implements Row {
* @param row row key
*/
public Increment(byte [] row) {
- if (row == null) {
- throw new IllegalArgumentException("Cannot increment a null row");
+ if (row == null || row.length > HConstants.MAX_ROW_LENGTH) {
+ throw new IllegalArgumentException("Row key is invalid");
}
- this.row = row;
+ this.row = Arrays.copyOf(row, row.length);
}
/**
@@ -84,40 +80,10 @@ public class Increment implements Row {
if (qualifier == null) {
throw new IllegalArgumentException("qualifier cannot be null");
}
- NavigableMap set = familyMap.get(family);
- if(set == null) {
- set = new TreeMap(Bytes.BYTES_COMPARATOR);
- }
- set.put(qualifier, amount);
- familyMap.put(family, set);
- return this;
- }
-
- /* Accessors */
-
- /**
- * Method for retrieving the increment's row
- * @return row
- */
- public byte [] getRow() {
- return this.row;
- }
-
- /**
- * Method for retrieving whether WAL will be written to or not
- * @return true if WAL should be used, false if not
- */
- public boolean getWriteToWAL() {
- return this.writeToWAL;
- }
-
- /**
- * Sets whether this operation should write to the WAL or not.
- * @param writeToWAL true if WAL should be used, false if not
- * @return this increment operation
- */
- public Increment setWriteToWAL(boolean writeToWAL) {
- this.writeToWAL = writeToWAL;
+ List list = getCellList(family);
+ KeyValue kv = createPutKeyValue(family, qualifier, ts, Bytes.toBytes(amount));
+ list.add(kv);
+ familyMap.put(kv.getFamily(), list);
return this;
}
@@ -150,14 +116,6 @@ public class Increment implements Row {
}
/**
- * Method for retrieving the keys in the familyMap
- * @return keys in the current familyMap
- */
- public Set familySet() {
- return this.familyMap.keySet();
- }
-
- /**
* Method for retrieving the number of families to increment from
* @return number of families
*/
@@ -166,19 +124,6 @@ public class Increment implements Row {
}
/**
- * Method for retrieving the number of columns to increment
- * @return number of columns across all families
- */
- public int numColumns() {
- if (!hasFamilies()) return 0;
- int num = 0;
- for (NavigableMap family : familyMap.values()) {
- num += family.size();
- }
- return num;
- }
-
- /**
* Method for checking if any families have been inserted into this Increment
* @return true if familyMap is non empty false otherwise
*/
@@ -187,14 +132,6 @@ public class Increment implements Row {
}
/**
- * Method for retrieving the increment's familyMap
- * @return familyMap
- */
- public Map> getFamilyMap() {
- return this.familyMap;
- }
-
- /**
* @return String
*/
@Override
@@ -208,8 +145,7 @@ public class Increment implements Row {
}
sb.append(", families=");
boolean moreThanOne = false;
- for(Map.Entry> entry :
- this.familyMap.entrySet()) {
+ for(Map.Entry> entry: this.familyMap.entrySet()) {
if(moreThanOne) {
sb.append("), ");
} else {
@@ -224,13 +160,14 @@ public class Increment implements Row {
} else {
sb.append("{");
boolean moreThanOneB = false;
- for(Map.Entry column : entry.getValue().entrySet()) {
+ for(Cell cell : entry.getValue()) {
if(moreThanOneB) {
sb.append(", ");
} else {
moreThanOneB = true;
}
- sb.append(Bytes.toStringBinary(column.getKey()) + "+=" + column.getValue());
+ KeyValue kv = (KeyValue)cell;
+ sb.append(Bytes.toStringBinary(kv.getKey()) + "+=" + Bytes.toLong(kv.getValue()));
}
sb.append("}");
}
@@ -255,4 +192,10 @@ public class Increment implements Row {
Row other = (Row) obj;
return compareTo(other) == 0;
}
-}
+
+ @Override
+ public long heapSize() {
+ // TODO
+ return 0;
+ }
+}
\ No newline at end of file
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/MultiAction.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/MultiAction.java
index 5605013..eedf0f0 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/MultiAction.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/MultiAction.java
@@ -35,9 +35,11 @@ import org.apache.hadoop.hbase.util.Bytes;
@InterfaceAudience.Public
@InterfaceStability.Evolving
public final class MultiAction {
+ // TODO: This class should not be visible outside of the client package.
// map of regions to lists of puts/gets/deletes for that region.
- public Map>> actions = new TreeMap>>(Bytes.BYTES_COMPARATOR);
+ public Map>> actions =
+ new TreeMap>>(Bytes.BYTES_COMPARATOR);
public MultiAction() {
super();
@@ -87,4 +89,4 @@ public final class MultiAction {
}
return res;
}
-}
+}
\ No newline at end of file
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Mutation.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Mutation.java
index dd883a5..d8dbca7 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Mutation.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Mutation.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.NavigableMap;
import java.util.TreeMap;
import java.util.UUID;
@@ -31,18 +32,52 @@ import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hbase.Cell;
+import org.apache.hbase.CellScannable;
+import org.apache.hbase.CellScanner;
+import org.apache.hbase.CellUtil;
@InterfaceAudience.Public
@InterfaceStability.Evolving
-public abstract class Mutation extends OperationWithAttributes implements Row {
+public abstract class Mutation extends OperationWithAttributes implements Row, CellScannable {
// Attribute used in Mutations to indicate the originating cluster.
private static final String CLUSTER_ID_ATTR = "_c.id_";
protected byte [] row = null;
protected long ts = HConstants.LATEST_TIMESTAMP;
protected boolean writeToWAL = true;
- protected Map> familyMap =
- new TreeMap>(Bytes.BYTES_COMPARATOR);
+ // A Map sorted by column family.
+ protected NavigableMap> familyMap =
+ new TreeMap>(Bytes.BYTES_COMPARATOR);
+
+ @Override
+ public CellScanner cellScanner() {
+ return CellUtil.createCellScanner(getFamilyMap());
+ }
+
+ /**
+ * Creates an empty list if one doesn't exist for the given column family
+ * or else it returns the associated list of Cell objects.
+ *
+ * @param family column family
+ * @return a list of Cell objects, returns an empty list if one doesn't exist.
+ */
+ List getCellList(byte[] family) {
+ List list = (List)this.familyMap.get(family);
+ if (list == null) {
+ list = new ArrayList| (0);
+ }
+ return list;
+ }
+
+ /*
+ * Create a KeyValue with this objects row key and the Put identifier.
+ *
+ * @return a KeyValue with this objects row key and the Put identifier.
+ */
+ KeyValue createPutKeyValue(byte[] family, byte[] qualifier, long ts, byte[] value) {
+ return new KeyValue(this.row, family, qualifier, ts, KeyValue.Type.Put, value);
+ }
/**
* Compile the column family (i.e. schema) information
@@ -57,7 +92,7 @@ public abstract class Mutation extends OperationWithAttributes implements Row {
// ideally, we would also include table information, but that information
// is not stored in each Operation instance.
map.put("families", families);
- for (Map.Entry> entry : this.familyMap.entrySet()) {
+ for (Map.Entry> entry : this.familyMap.entrySet()) {
families.add(Bytes.toStringBinary(entry.getKey()));
}
return map;
@@ -82,21 +117,21 @@ public abstract class Mutation extends OperationWithAttributes implements Row {
map.put("row", Bytes.toStringBinary(this.row));
int colCount = 0;
// iterate through all column families affected
- for (Map.Entry> entry : this.familyMap.entrySet()) {
- // map from this family to details for each kv affected within the family
- List | | | | | |