datafu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mha...@apache.org
Subject [2/2] incubator-datafu git commit: DATAFU-114: Add accumulator test for FirstTupleFromBag
Date Tue, 16 Feb 2016 19:32:58 GMT
DATAFU-114: Add accumulator test for FirstTupleFromBag


Project: http://git-wip-us.apache.org/repos/asf/incubator-datafu/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-datafu/commit/a15a15c5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-datafu/tree/a15a15c5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-datafu/diff/a15a15c5

Branch: refs/heads/master
Commit: a15a15c58164cc39c62235c0da6a7b1d8d7db9e2
Parents: f7c9b23
Author: Matthew Hayes <matthew.terence.hayes@gmail.com>
Authored: Thu Feb 4 16:05:02 2016 -0800
Committer: Matthew Hayes <matthew.terence.hayes@gmail.com>
Committed: Thu Feb 4 16:05:02 2016 -0800

----------------------------------------------------------------------
 .../java/datafu/test/pig/bags/BagTests.java     | 30 ++++++++++++++++++++
 1 file changed, 30 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-datafu/blob/a15a15c5/datafu-pig/src/test/java/datafu/test/pig/bags/BagTests.java
----------------------------------------------------------------------
diff --git a/datafu-pig/src/test/java/datafu/test/pig/bags/BagTests.java b/datafu-pig/src/test/java/datafu/test/pig/bags/BagTests.java
index a5851e4..9fdb250 100644
--- a/datafu-pig/src/test/java/datafu/test/pig/bags/BagTests.java
+++ b/datafu-pig/src/test/java/datafu/test/pig/bags/BagTests.java
@@ -22,6 +22,7 @@ package datafu.test.pig.bags;
 import datafu.pig.bags.CountEach;
 import datafu.pig.bags.DistinctBy;
 import datafu.pig.bags.Enumerate;
+import datafu.pig.bags.FirstTupleFromBag;
 import datafu.test.pig.PigTests;
 import junit.framework.Assert;
 
@@ -34,6 +35,7 @@ import org.apache.pig.data.TupleFactory;
 import org.apache.pig.pigunit.PigTest;
 import org.testng.annotations.Test;
 
+import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -45,6 +47,8 @@ import org.apache.pig.impl.util.Utils;
 import org.apache.pig.builtin.Utf8StorageConverter;
 import org.apache.pig.ResourceSchema.ResourceFieldSchema;
 
+import com.beust.jcommander.internal.Lists;
+
 public class BagTests extends PigTests
 {
   /**
@@ -278,6 +282,32 @@ result4 = FOREACH grouped GENERATE group AS a,TupleFromBag(data,0,$emptyTuple).b
 
     assertOutput(test, "data2", "(1,(4))");
   }
+   
+  @Test
+  public void firstTupleFromBagAccumulateTest() throws Exception
+  {
+    TupleFactory tf = TupleFactory.getInstance();
+    BagFactory bf = BagFactory.getInstance();
+ 
+    FirstTupleFromBag op = new FirstTupleFromBag();
+    
+    Tuple defaultValue = tf.newTuple(1000);
+    op.accumulate(tf.newTuple(Arrays.asList(bf.newDefaultBag(Arrays.asList(tf.newTuple(4))),
defaultValue)));
+    op.accumulate(tf.newTuple(Arrays.asList(bf.newDefaultBag(Arrays.asList(tf.newTuple(9))),
defaultValue)));
+    op.accumulate(tf.newTuple(Arrays.asList(bf.newDefaultBag(Arrays.asList(tf.newTuple(16))),
defaultValue)));
+    assertEquals(op.getValue(), tf.newTuple(4));
+    op.cleanup();
+    
+    op.accumulate(tf.newTuple(Arrays.asList(bf.newDefaultBag(Arrays.asList(tf.newTuple(11))),
defaultValue)));
+    op.accumulate(tf.newTuple(Arrays.asList(bf.newDefaultBag(Arrays.asList(tf.newTuple(17))),
defaultValue)));
+    op.accumulate(tf.newTuple(Arrays.asList(bf.newDefaultBag(Arrays.asList(tf.newTuple(5))),
defaultValue)));
+    assertEquals(op.getValue(), tf.newTuple(11));
+    op.cleanup();
+    
+    op.accumulate(tf.newTuple(Arrays.asList(bf.newDefaultBag(), defaultValue)));
+    assertEquals(op.getValue(), defaultValue);
+    op.cleanup();
+  }
 
   /**
 


Mime
View raw message