accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ktur...@apache.org
Subject svn commit: r1409033 - in /accumulo/trunk/core/src: main/java/org/apache/accumulo/core/data/Mutation.java test/java/org/apache/accumulo/core/data/MutationTest.java
Date Tue, 13 Nov 2012 23:48:19 GMT
Author: kturner
Date: Tue Nov 13 23:48:18 2012
New Revision: 1409033

URL: http://svn.apache.org/viewvc?rev=1409033&view=rev
Log:
ACCUMULO-851 added public put methods to Mutation that accept byte arrays

Modified:
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/data/Mutation.java
    accumulo/trunk/core/src/test/java/org/apache/accumulo/core/data/MutationTest.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=1409033&r1=1409032&r2=1409033&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 23:48:18 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;
@@ -261,17 +260,17 @@ public class Mutation implements Writabl
   }
   
   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 @@ public class Mutation implements Writabl
     }
     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 @@ public class Mutation implements Writabl
     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 class Mutation implements Writabl
   }
   
   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)

Modified: accumulo/trunk/core/src/test/java/org/apache/accumulo/core/data/MutationTest.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/test/java/org/apache/accumulo/core/data/MutationTest.java?rev=1409033&r1=1409032&r2=1409033&view=diff
==============================================================================
--- accumulo/trunk/core/src/test/java/org/apache/accumulo/core/data/MutationTest.java (original)
+++ accumulo/trunk/core/src/test/java/org/apache/accumulo/core/data/MutationTest.java Tue
Nov 13 23:48:18 2012
@@ -208,7 +208,7 @@ public class MutationTest extends TestCa
   }
   
   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 class MutationTest extends TestCa
   }
   
   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 class MutationTest extends TestCa
     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 class MutationTest extends TestCa
     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



Mime
View raw message