You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by el...@apache.org on 2013/10/31 04:25:22 UTC

[10/10] git commit: ACCUMULO-1783 Ensure that no colqual doesn't add an extra colon

ACCUMULO-1783 Ensure that no colqual doesn't add an extra colon


Project: http://git-wip-us.apache.org/repos/asf/accumulo-pig/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo-pig/commit/30fd9aa6
Tree: http://git-wip-us.apache.org/repos/asf/accumulo-pig/tree/30fd9aa6
Diff: http://git-wip-us.apache.org/repos/asf/accumulo-pig/diff/30fd9aa6

Branch: refs/heads/ACCUMULO-1783
Commit: 30fd9aa6c81f41f6d126b01a7e37c9f98f92e338
Parents: 9279c77
Author: Josh Elser <el...@apache.org>
Authored: Wed Oct 30 23:18:16 2013 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Wed Oct 30 23:24:28 2013 -0400

----------------------------------------------------------------------
 .../apache/accumulo/pig/AccumuloStorage.java    | 18 +++++++++++++----
 .../accumulo/pig/AccumuloStorageTest.java       | 21 +++++++++++++++++---
 2 files changed, 32 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo-pig/blob/30fd9aa6/src/main/java/org/apache/accumulo/pig/AccumuloStorage.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/accumulo/pig/AccumuloStorage.java b/src/main/java/org/apache/accumulo/pig/AccumuloStorage.java
index 1788997..dcfd888 100644
--- a/src/main/java/org/apache/accumulo/pig/AccumuloStorage.java
+++ b/src/main/java/org/apache/accumulo/pig/AccumuloStorage.java
@@ -121,11 +121,21 @@ public class AccumuloStorage extends AbstractAccumuloStorage {
     return tuple;
   }
   
-  private Map<String,Object> aggregate(List<Entry<Key,Value>> columns) {
-    Map<String,Object> map = new HashMap<String,Object>();
+  protected Map<String,Object> aggregate(List<Entry<Key,Value>> columns) {
+    final Map<String,Object> map = new HashMap<String,Object>();
+    final StringBuilder sb = new StringBuilder(128);
+    
     for (Entry<Key,Value> column : columns) {
-      map.put(column.getKey().getColumnFamily().toString() + COLON + column.getKey().getColumnQualifier().toString(),
-          new DataByteArray(column.getValue().get()));
+      String cf = column.getKey().getColumnFamily().toString(), cq = column.getKey().getColumnQualifier().toString();
+      
+      sb.append(cf);
+      if (!cq.isEmpty()) {
+        sb.append(COLON).append(cq);
+      }
+      
+      map.put(sb.toString(), new DataByteArray(column.getValue().get()));
+      
+      sb.setLength(0);
     }
     
     return map;

http://git-wip-us.apache.org/repos/asf/accumulo-pig/blob/30fd9aa6/src/test/java/org/apache/accumulo/pig/AccumuloStorageTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/accumulo/pig/AccumuloStorageTest.java b/src/test/java/org/apache/accumulo/pig/AccumuloStorageTest.java
index a02ad7c..aa88191 100644
--- a/src/test/java/org/apache/accumulo/pig/AccumuloStorageTest.java
+++ b/src/test/java/org/apache/accumulo/pig/AccumuloStorageTest.java
@@ -204,7 +204,7 @@ public class AccumuloStorageTest {
       Entry<String,String> key = Maps.immutableEntry(new String(update.getColumnFamily()), new String(update.getColumnQualifier()));
       String value = new String(update.getValue());
       Assert.assertTrue(expectations.containsKey(key));
-     
+      
       String actual = expectations.remove(key);
       Assert.assertEquals(value, actual);
     }
@@ -248,7 +248,7 @@ public class AccumuloStorageTest {
       Entry<String,String> key = Maps.immutableEntry(new String(update.getColumnFamily()), new String(update.getColumnQualifier()));
       String value = new String(update.getValue());
       Assert.assertTrue(expectations.containsKey(key));
-     
+      
       String actual = expectations.remove(key);
       Assert.assertEquals(value, actual);
     }
@@ -292,7 +292,7 @@ public class AccumuloStorageTest {
       Entry<String,String> key = Maps.immutableEntry(new String(update.getColumnFamily()), new String(update.getColumnQualifier()));
       String value = new String(update.getValue());
       Assert.assertTrue(expectations.containsKey(key));
-     
+      
       String actual = expectations.remove(key);
       Assert.assertEquals(value, actual);
     }
@@ -447,4 +447,19 @@ public class AccumuloStorageTest {
     Assert.assertEquals(map, t.get(1));
   }
   
+  @Test
+  public void testNoExtraCharsOnAggregate() throws Exception {
+    List<Entry<Key,Value>> input = Arrays.asList(Maps.immutableEntry(new Key("1", "cf1"), new Value("foo".getBytes())),
+        Maps.immutableEntry(new Key("1", "cf2"), new Value("bar".getBytes())));
+    
+    AccumuloStorage storage = new AccumuloStorage();
+    
+    Map<String,Object> aggregate = storage.aggregate(input);
+    
+    Assert.assertTrue(aggregate.containsKey("cf1"));
+    Assert.assertTrue(aggregate.containsKey("cf2"));
+    Assert.assertEquals("foo", aggregate.get("cf1").toString());
+    Assert.assertEquals("bar", aggregate.get("cf2").toString());
+  }
+  
 }