From 0f253212b70d0dcf67bd0b02d011d2ab8bd547b5 Mon Sep 17 00:00:00 2001 From: Changgeng Li Date: Mon, 1 Jun 2015 10:27:44 -0700 Subject: [PATCH] Deep copy the cell list --- .../java/org/apache/hadoop/hbase/client/Put.java | 2 +- .../hbase/client/TestPutCopyConstructor.java | 43 ++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestPutCopyConstructor.java diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Put.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Put.java index 364783f..c895eb4 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Put.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Put.java @@ -123,7 +123,7 @@ public class Put extends Mutation implements HeapSize, Comparable { this(putToCopy.getRow(), putToCopy.ts); this.familyMap = new TreeMap>(Bytes.BYTES_COMPARATOR); for(Map.Entry> entry: putToCopy.getFamilyCellMap().entrySet()) { - this.familyMap.put(entry.getKey(), entry.getValue()); + this.familyMap.put(entry.getKey(), new ArrayList(entry.getValue())); } this.durability = putToCopy.durability; for (Map.Entry entry : putToCopy.getAttributesMap().entrySet()) { diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestPutCopyConstructor.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestPutCopyConstructor.java new file mode 100644 index 0000000..7649afd --- /dev/null +++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestPutCopyConstructor.java @@ -0,0 +1,43 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hbase.client; + +import org.apache.hadoop.hbase.util.Bytes; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +public class TestPutCopyConstructor { + @Test + public void testCopyConstructor() { + Put origin = new Put(Bytes.toBytes("ROW-01")); + byte[] family = Bytes.toBytes("CF-01"); + byte[] qualifier = Bytes.toBytes("Q-01"); + + origin.addColumn(family, qualifier, Bytes.toBytes("V-01")); + Put clone = new Put(origin); + + assertEquals(origin.getCellList(family), clone.getCellList(family)); + origin.addColumn(family, qualifier, Bytes.toBytes("V-02")); + + //They should have different cell lists + assertNotEquals(origin.getCellList(family), clone.getCellList(family)); + + } +} -- 1.9.5