Skip to content
Browse files

ACCUMULO-851 added public put methods to Mutation that accept byte ar…

…rays

git-svn-id: https://svn.apache.org/repos/asf/accumulo/trunk@1409033 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent e97eb8a commit 3132b2bf3cbdd088f156fcbc3d1a1c77fc36ae1d @keith-turner keith-turner committed Nov 13, 2012
View
77 core/src/main/java/org/apache/accumulo/core/data/Mutation.java
@@ -27,7 +27,6 @@
import org.apache.accumulo.core.data.thrift.TMutation;
import org.apache.accumulo.core.security.ColumnVisibility;
import org.apache.accumulo.core.util.ByteBufferUtil;
-import org.apache.accumulo.core.util.TextUtil;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableUtils;
@@ -261,17 +260,17 @@ private void put(long l) {
}
private void put(byte[] cf, byte[] cq, byte[] cv, boolean hasts, long ts, boolean deleted, byte[] val) {
- put(cf, cf.length, cq, cq.length, cv, hasts, ts, deleted, val);
+ put(cf, cf.length, cq, cq.length, cv, hasts, ts, deleted, val, val.length);
}
/*
* When dealing with Text object the length must be gotten from the object, not from the byte array.
*/
private void put(Text cf, Text cq, byte[] cv, boolean hasts, long ts, boolean deleted, byte[] val) {
- put(cf.getBytes(), cf.getLength(), cq.getBytes(), cq.getLength(), cv, hasts, ts, deleted, val);
+ put(cf.getBytes(), cf.getLength(), cq.getBytes(), cq.getLength(), cv, hasts, ts, deleted, val, val.length);
}
- private void put(byte[] cf, int cfLength, byte[] cq, int cqLength, byte[] cv, boolean hasts, long ts, boolean deleted, byte[] val) {
+ private void put(byte[] cf, int cfLength, byte[] cq, int cqLength, byte[] cv, boolean hasts, long ts, boolean deleted, byte[] val, int valLength) {
if (buffer == null) {
throw new IllegalStateException("Can not add to mutation after serializing it");
}
@@ -284,14 +283,14 @@ private void put(byte[] cf, int cfLength, byte[] cq, int cqLength, byte[] cv, bo
}
put(deleted);
- if (val.length < VALUE_SIZE_COPY_CUTOFF) {
- put(val);
+ if (valLength < VALUE_SIZE_COPY_CUTOFF) {
+ put(val, valLength);
} else {
if (values == null) {
values = new ArrayList<byte[]>();
}
- byte copy[] = new byte[val.length];
- System.arraycopy(val, 0, copy, 0, val.length);
+ byte copy[] = new byte[valLength];
+ System.arraycopy(val, 0, copy, 0, valLength);
values.add(copy);
put(-1 * values.size());
}
@@ -303,8 +302,12 @@ private void put(CharSequence cf, CharSequence cq, byte[] cv, boolean hasts, lon
put(new Text(cf.toString()), new Text(cq.toString()), cv, hasts, ts, deleted, val);
}
+ private void put(Text cf, Text cq, byte[] cv, boolean hasts, long ts, boolean deleted, Text val) {
+ put(cf.getBytes(), cf.getLength(), cq.getBytes(), cq.getLength(), cv, hasts, ts, deleted, val.getBytes(), val.getLength());
+ }
+
private void put(CharSequence cf, CharSequence cq, byte[] cv, boolean hasts, long ts, boolean deleted, CharSequence val) {
- put(cf, cq, cv, hasts, ts, deleted, TextUtil.getBytes(new Text(val.toString())));
+ put(new Text(cf.toString()), new Text(cq.toString()), cv, hasts, ts, deleted, new Text(val.toString()));
}
public void put(Text columnFamily, Text columnQualifier, Value value) {
@@ -340,53 +343,85 @@ public void putDelete(Text columnFamily, Text columnQualifier, ColumnVisibility
}
public void put(CharSequence columnFamily, CharSequence columnQualifier, Value value) {
- put(columnFamily.toString(), columnQualifier.toString(), EMPTY_BYTES, false, 0l, false, value.get());
+ put(columnFamily, columnQualifier, EMPTY_BYTES, false, 0l, false, value.get());
}
public void put(CharSequence columnFamily, CharSequence columnQualifier, ColumnVisibility columnVisibility, Value value) {
- put(columnFamily.toString(), columnQualifier.toString(), columnVisibility.getExpression(), false, 0l, false, value.get());
+ put(columnFamily, columnQualifier, columnVisibility.getExpression(), false, 0l, false, value.get());
}
public void put(CharSequence columnFamily, CharSequence columnQualifier, long timestamp, Value value) {
- put(columnFamily.toString(), columnQualifier.toString(), EMPTY_BYTES, true, timestamp, false, value.get());
+ put(columnFamily, columnQualifier, EMPTY_BYTES, true, timestamp, false, value.get());
}
public void put(CharSequence columnFamily, CharSequence columnQualifier, ColumnVisibility columnVisibility, long timestamp, Value value) {
- put(columnFamily.toString(), columnQualifier.toString(), columnVisibility.getExpression(), true, timestamp, false, value.get());
+ put(columnFamily, columnQualifier, columnVisibility.getExpression(), true, timestamp, false, value.get());
}
public void putDelete(CharSequence columnFamily, CharSequence columnQualifier) {
- put(columnFamily.toString(), columnQualifier.toString(), EMPTY_BYTES, false, 0l, true, EMPTY_BYTES);
+ put(columnFamily, columnQualifier, EMPTY_BYTES, false, 0l, true, EMPTY_BYTES);
}
public void putDelete(CharSequence columnFamily, CharSequence columnQualifier, ColumnVisibility columnVisibility) {
- put(columnFamily.toString(), columnQualifier.toString(), columnVisibility.getExpression(), false, 0l, true, EMPTY_BYTES);
+ put(columnFamily, columnQualifier, columnVisibility.getExpression(), false, 0l, true, EMPTY_BYTES);
}
public void putDelete(CharSequence columnFamily, CharSequence columnQualifier, long timestamp) {
- put(columnFamily.toString(), columnQualifier.toString(), EMPTY_BYTES, true, timestamp, true, EMPTY_BYTES);
+ put(columnFamily, columnQualifier, EMPTY_BYTES, true, timestamp, true, EMPTY_BYTES);
}
public void putDelete(CharSequence columnFamily, CharSequence columnQualifier, ColumnVisibility columnVisibility, long timestamp) {
- put(columnFamily.toString(), columnQualifier.toString(), columnVisibility.getExpression(), true, timestamp, true, EMPTY_BYTES);
+ put(columnFamily, columnQualifier, columnVisibility.getExpression(), true, timestamp, true, EMPTY_BYTES);
}
public void put(CharSequence columnFamily, CharSequence columnQualifier, CharSequence value) {
- put(columnFamily.toString(), columnQualifier.toString(), EMPTY_BYTES, false, 0l, false, value.toString());
+ put(columnFamily, columnQualifier, EMPTY_BYTES, false, 0l, false, value);
}
public void put(CharSequence columnFamily, CharSequence columnQualifier, ColumnVisibility columnVisibility, CharSequence value) {
- put(columnFamily.toString(), columnQualifier.toString(), columnVisibility.getExpression(), false, 0l, false, value.toString());
+ put(columnFamily, columnQualifier, columnVisibility.getExpression(), false, 0l, false, value);
}
public void put(CharSequence columnFamily, CharSequence columnQualifier, long timestamp, CharSequence value) {
- put(columnFamily.toString(), columnQualifier.toString(), EMPTY_BYTES, true, timestamp, false, value.toString());
+ put(columnFamily, columnQualifier, EMPTY_BYTES, true, timestamp, false, value);
}
public void put(CharSequence columnFamily, CharSequence columnQualifier, ColumnVisibility columnVisibility, long timestamp, CharSequence value) {
- put(columnFamily.toString(), columnQualifier.toString(), columnVisibility.getExpression(), true, timestamp, false, value.toString());
+ put(columnFamily, columnQualifier, columnVisibility.getExpression(), true, timestamp, false, value);
+ }
+
+ public void put(byte[] columnFamily, byte[] columnQualifier, byte[] value) {
+ put(columnFamily, columnQualifier, EMPTY_BYTES, false, 0l, false, value);
+ }
+
+ public void put(byte[] columnFamily, byte[] columnQualifier, ColumnVisibility columnVisibility, byte[] value) {
+ put(columnFamily, columnQualifier, columnVisibility.getExpression(), false, 0l, false, value);
+ }
+
+ public void put(byte[] columnFamily, byte[] columnQualifier, long timestamp, byte[] value) {
+ put(columnFamily, columnQualifier, EMPTY_BYTES, true, timestamp, false, value);
+ }
+
+ public void put(byte[] columnFamily, byte[] columnQualifier, ColumnVisibility columnVisibility, long timestamp, byte[] value) {
+ put(columnFamily, columnQualifier, columnVisibility.getExpression(), true, timestamp, false, value);
+ }
+
+ public void putDelete(byte[] columnFamily, byte[] columnQualifier) {
+ put(columnFamily, columnQualifier, EMPTY_BYTES, false, 0l, true, EMPTY_BYTES);
}
+ public void putDelete(byte[] columnFamily, byte[] columnQualifier, ColumnVisibility columnVisibility) {
+ put(columnFamily, columnQualifier, columnVisibility.getExpression(), false, 0l, true, EMPTY_BYTES);
+ }
+
+ public void putDelete(byte[] columnFamily, byte[] columnQualifier, long timestamp) {
+ put(columnFamily, columnQualifier, EMPTY_BYTES, true, timestamp, true, EMPTY_BYTES);
+ }
+
+ public void putDelete(byte[] columnFamily, byte[] columnQualifier, ColumnVisibility columnVisibility, long timestamp) {
+ put(columnFamily, columnQualifier, columnVisibility.getExpression(), true, timestamp, true, EMPTY_BYTES);
+ }
+
private byte[] oldReadBytes(SimpleReader in) {
int len = in.readInt();
if (len == 0)
View
36 core/src/test/java/org/apache/accumulo/core/data/MutationTest.java
@@ -208,7 +208,7 @@ public void testPuts() {
}
public void testPutsString() {
- Mutation m = new Mutation(new Text("r1"));
+ Mutation m = new Mutation("r1");
m.put("cf1", "cq1", nv("v1"));
m.put("cf2", "cq2", new ColumnVisibility("cv2"), nv("v2"));
@@ -239,7 +239,7 @@ public void testPutsString() {
}
public void testPutsStringString() {
- Mutation m = new Mutation(new Text("r1"));
+ Mutation m = new Mutation("r1");
m.put("cf1", "cq1", "v1");
m.put("cf2", "cq2", new ColumnVisibility("cv2"), "v2");
@@ -252,6 +252,7 @@ public void testPutsStringString() {
m.putDelete("cf8", "cq8", new ColumnVisibility("cv8"), 8l);
assertEquals(8, m.size());
+ assertEquals("r1", new String(m.getRow()));
List<ColumnUpdate> updates = m.getUpdates();
@@ -269,6 +270,37 @@ public void testPutsStringString() {
assertEquals(updates.get(7), "cf8", "cq8", "cv8", 8l, true, true, "");
}
+ public void testByteArrays() {
+ Mutation m = new Mutation("r1".getBytes());
+
+ m.put("cf1".getBytes(), "cq1".getBytes(), "v1".getBytes());
+ m.put("cf2".getBytes(), "cq2".getBytes(), new ColumnVisibility("cv2"), "v2".getBytes());
+ m.put("cf3".getBytes(), "cq3".getBytes(), 3l, "v3".getBytes());
+ m.put("cf4".getBytes(), "cq4".getBytes(), new ColumnVisibility("cv4"), 4l, "v4".getBytes());
+
+ m.putDelete("cf5".getBytes(), "cq5".getBytes());
+ m.putDelete("cf6".getBytes(), "cq6".getBytes(), new ColumnVisibility("cv6"));
+ m.putDelete("cf7".getBytes(), "cq7".getBytes(), 7l);
+ m.putDelete("cf8".getBytes(), "cq8".getBytes(), new ColumnVisibility("cv8"), 8l);
+
+ assertEquals(8, m.size());
+
+ List<ColumnUpdate> updates = m.getUpdates();
+
+ assertEquals(8, m.size());
+ assertEquals(8, updates.size());
+
+ assertEquals(updates.get(0), "cf1", "cq1", "", 0l, false, false, "v1");
+ assertEquals(updates.get(1), "cf2", "cq2", "cv2", 0l, false, false, "v2");
+ assertEquals(updates.get(2), "cf3", "cq3", "", 3l, true, false, "v3");
+ assertEquals(updates.get(3), "cf4", "cq4", "cv4", 4l, true, false, "v4");
+
+ assertEquals(updates.get(4), "cf5", "cq5", "", 0l, false, true, "");
+ assertEquals(updates.get(5), "cf6", "cq6", "cv6", 0l, false, true, "");
+ assertEquals(updates.get(6), "cf7", "cq7", "", 7l, true, true, "");
+ assertEquals(updates.get(7), "cf8", "cq8", "cv8", 8l, true, true, "");
+ }
+
/**
* Test for regression on bug 3422. If a {@link Mutation} object is reused for multiple calls to readFields, the mutation would previously be "locked in" to
* the first set of column updates (and value lengths). Hadoop input formats reuse objects when reading, so if Mutations are used with an input format (or as

0 comments on commit 3132b2b

Please sign in to comment.
Something went wrong with that request. Please try again.