I think the changes for adding byte arrays to mutation are great and
appreciate them.
I do not want to start another dicussion about encoding. The javadoc
for mutation states the following:
Convenience methods which takes columns
and value as CharSequence (String implements
CharSequence) are provided. CharSequence is
converted to UTF-8 by constructing a new Text
object.
This is the documented behavior of Mutation in released code. Whether
its good or bad is a seperate issue I do not want to discuss :)
Changing the behavior could break existing code that relies on the
documented behavior. I will commit a change in a bit for the
CharSequence related methods. Just want to point why I am doing this.
Keith
On Tue, Nov 13, 2012 at 2:20 PM, <[EMAIL PROTECTED]> wrote:
> Author: medined
> Date: Tue Nov 13 19:19:59 2012
> New Revision: 1408900
>
> URL:
http://svn.apache.org/viewvc?rev=1408900&view=rev> Log:
> ACCUMULO-851: Add Mutation Constructor Accepting Byte Array. Followup to have put() use byte arrays too.
>
> Modified:
> accumulo/trunk/core/src/main/java/org/apache/accumulo/core/data/Mutation.java
>
> Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/data/Mutation.java
> URL:
http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/data/Mutation.java?rev=1408900&r1=1408899&r2=1408900&view=diff> =============================================================================> --- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/data/Mutation.java (original)
> +++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/data/Mutation.java Tue Nov 13 19:19:59 2012
> @@ -27,7 +27,6 @@ import java.util.List;
> 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;
> @@ -87,12 +86,6 @@ public class Mutation implements Writabl
>
> }
>
> - void add(byte[] b) {
> - reserve(b.length);
> - System.arraycopy(b, 0, data, offset, b.length);
> - offset += b.length;
> - }
> -
> public void add(byte[] bytes, int off, int length) {
> reserve(length);
> System.arraycopy(bytes, off, data, offset, length);
> @@ -238,14 +231,20 @@ public class Mutation implements Writabl
> return row;
> }
>
> + public static String toHexString(byte[] ba) {
> + StringBuilder str = new StringBuilder();
> + for (int i = 0; i < ba.length; i++)
> + str.append(String.format("%x", ba[i]));
> + return str.toString();
> + }
> +
> private void put(byte b[]) {
> - buffer.writeVLong(b.length);
> - buffer.add(b);
> + put(b, b.length);
> }
>
> - private void put(Text t) {
> - buffer.writeVLong(t.getLength());
> - buffer.add(t.getBytes(), 0, t.getLength());
> + private void put(byte b[], int length) {
> + buffer.writeVLong(length);
> + buffer.add(b, 0, length);
> }
>
> private void put(boolean b) {
> @@ -260,24 +259,36 @@ public class Mutation implements Writabl
> buffer.writeVLong(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);
> + }
> +
> + /*
> + * 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) {
> -
> - if (buffer == null)
> + put(cf.getBytes(), cf.getLength(), cq.getBytes(), cq.getLength(), cv, hasts, ts, deleted, val);
> + }
> +
> + private void put(byte[] cf, int cfLength, byte[] cq, int cqLength, byte[] cv, boolean hasts, long ts, boolean deleted, byte[] val) {