From 0a1f404686df2eeba1d77d269a19fbf472235c05 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Thu, 17 Aug 2017 00:39:35 +0800 Subject: [PATCH] HBASE-18573 Update Append and Delete to use Mutation#getCellList(family) --- .../org/apache/hadoop/hbase/client/Append.java | 9 +++---- .../org/apache/hadoop/hbase/client/Delete.java | 31 +++++----------------- 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Append.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Append.java index 2bd08608f3..694731318f 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Append.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Append.java @@ -134,11 +134,10 @@ public class Append extends Mutation { public Append add(final Cell cell) { // Presume it is KeyValue for now. byte [] family = CellUtil.cloneFamily(cell); - List list = this.familyMap.get(family); - if (list == null) { - list = new ArrayList<>(1); - this.familyMap.put(family, list); - } + + // Get cell list for the family + List list = getCellList(family); + // find where the new entry should be placed in the List list.add(cell); return this; diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Delete.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Delete.java index bf5241c5d9..66b6cfc793 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Delete.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Delete.java @@ -180,11 +180,7 @@ public class Delete extends Mutation implements Comparable { " doesn't match the original one " + Bytes.toStringBinary(this.row)); } byte [] family = CellUtil.cloneFamily(kv); - List list = familyMap.get(family); - if (list == null) { - list = new ArrayList<>(1); - familyMap.put(family, list); - } + List list = getCellList(family); list.add(kv); return this; } @@ -216,11 +212,8 @@ public class Delete extends Mutation implements Comparable { if (timestamp < 0) { throw new IllegalArgumentException("Timestamp cannot be negative. ts=" + timestamp); } - List list = familyMap.get(family); - if(list == null) { - list = new ArrayList<>(1); - familyMap.put(family, list); - } else if(!list.isEmpty()) { + List list = getCellList(family); + if(!list.isEmpty()) { list.clear(); } KeyValue kv = new KeyValue(row, family, null, timestamp, KeyValue.Type.DeleteFamily); @@ -236,11 +229,7 @@ public class Delete extends Mutation implements Comparable { * @return this for invocation chaining */ public Delete addFamilyVersion(final byte [] family, final long timestamp) { - List list = familyMap.get(family); - if(list == null) { - list = new ArrayList<>(1); - familyMap.put(family, list); - } + List list = getCellList(family); list.add(new KeyValue(row, family, null, timestamp, KeyValue.Type.DeleteFamilyVersion)); return this; @@ -269,11 +258,7 @@ public class Delete extends Mutation implements Comparable { if (timestamp < 0) { throw new IllegalArgumentException("Timestamp cannot be negative. ts=" + timestamp); } - List list = familyMap.get(family); - if (list == null) { - list = new ArrayList<>(1); - familyMap.put(family, list); - } + List list = getCellList(family); list.add(new KeyValue(this.row, family, qualifier, timestamp, KeyValue.Type.DeleteColumn)); return this; @@ -304,11 +289,7 @@ public class Delete extends Mutation implements Comparable { if (timestamp < 0) { throw new IllegalArgumentException("Timestamp cannot be negative. ts=" + timestamp); } - List list = familyMap.get(family); - if(list == null) { - list = new ArrayList<>(1); - familyMap.put(family, list); - } + List list = getCellList(family); KeyValue kv = new KeyValue(this.row, family, qualifier, timestamp, KeyValue.Type.Delete); list.add(kv); return this; -- 2.11.0 (Apple Git-81)