You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafu.apache.org by mi...@apache.org on 2014/04/26 00:34:59 UTC
git commit: [DATAFU-38] Make the global variable groups into local in
exec and pass it as an argument to addGroup.
Repository: incubator-datafu
Updated Branches:
refs/heads/master 1cbe8c299 -> 83a1dec05
[DATAFU-38] Make the global variable groups into local in exec and pass it as an argument to addGroup.
Project: http://git-wip-us.apache.org/repos/asf/incubator-datafu/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-datafu/commit/83a1dec0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-datafu/tree/83a1dec0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-datafu/diff/83a1dec0
Branch: refs/heads/master
Commit: 83a1dec05d662d97baf1eb3c06639e251711bcf5
Parents: 1cbe8c2
Author: Sam Steingold <sd...@gnu.org>
Authored: Fri Apr 25 15:31:15 2014 -0700
Committer: mitul tiwari <mi...@gmail.com>
Committed: Fri Apr 25 15:31:15 2014 -0700
----------------------------------------------------------------------
datafu-pig/src/main/java/datafu/pig/bags/BagGroup.java | 6 +++---
.../src/test/java/datafu/test/pig/bags/BagTests.java | 10 ++++++----
2 files changed, 9 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-datafu/blob/83a1dec0/datafu-pig/src/main/java/datafu/pig/bags/BagGroup.java
----------------------------------------------------------------------
diff --git a/datafu-pig/src/main/java/datafu/pig/bags/BagGroup.java b/datafu-pig/src/main/java/datafu/pig/bags/BagGroup.java
index 7b6c2e2..2359d6f 100644
--- a/datafu-pig/src/main/java/datafu/pig/bags/BagGroup.java
+++ b/datafu-pig/src/main/java/datafu/pig/bags/BagGroup.java
@@ -128,7 +128,6 @@ public class BagGroup extends AliasableEvalFunc<DataBag>
}
}
- Map<Tuple, List<Tuple>> groups = new HashMap<Tuple, List<Tuple>>();
TupleFactory tupleFactory = TupleFactory.getInstance();
BagFactory bagFactory = BagFactory.getInstance();
@@ -136,13 +135,14 @@ public class BagGroup extends AliasableEvalFunc<DataBag>
@Override
public DataBag exec(Tuple input) throws IOException
{
+ Map<Tuple, List<Tuple>> groups = new HashMap<Tuple, List<Tuple>>();
fieldNames = (List<String>)getInstanceProperties().get(FIELD_NAMES_PROPERTY);
DataBag inputBag = (DataBag)input.get(0);
for (Tuple tuple : inputBag) {
Tuple key = extractKey(tuple);
- addGroup(key, tuple);
+ addGroup(groups, key, tuple);
}
DataBag outputBag = bagFactory.newDefaultBag();
@@ -172,7 +172,7 @@ public class BagGroup extends AliasableEvalFunc<DataBag>
return key;
}
- private void addGroup(Tuple key, Tuple value) {
+ private void addGroup (Map<Tuple, List<Tuple>> groups, Tuple key, Tuple value) {
if (!groups.containsKey(key)) {
groups.put(key, new LinkedList<Tuple>());
}
http://git-wip-us.apache.org/repos/asf/incubator-datafu/blob/83a1dec0/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 f02f0cb..a8e0d32 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
@@ -1187,7 +1187,7 @@ public class BagTests extends PigTests
define BagGroup datafu.pig.bags.BagGroup();
- data = LOAD 'input' AS (input_bag: bag {T: tuple(k: int, v: chararray)});
+ data = LOAD 'input' AS (input_bag: bag {T: tuple(k: chararray, v: chararray)});
describe data;
data2 = FOREACH data GENERATE BagGroup(input_bag, input_bag.k) as grouped;
@@ -1210,10 +1210,12 @@ public class BagTests extends PigTests
public void bagGroupSingleTest() throws Exception
{
PigTest test = createPigTestFromString(bagGroupSingleTest);
- writeLinesToFile("input", "({(1,A),(1,B),(2,A),(2,B),(2,C),(3,A)})");
- test.runScript();
+ writeLinesToFile("input", "({(1,A),(1,B),(2,A),(2,B),(2,C),(3,A)})",
+ "({(A,1),(B,1),(A,2),(B,2),(C,2),(A,3)})");
+ test.runScript();
getLinesForAlias(test, "data2", true);
- assertOutput(test, "data3", "({(1,{(1,A),(1,B)}),(2,{(2,A),(2,B),(2,C)}),(3,{(3,A)})})");
+ assertOutput(test, "data3", "({(1,{(1,A),(1,B)}),(2,{(2,A),(2,B),(2,C)}),(3,{(3,A)})})",
+ "({(A,{(A,1),(A,2),(A,3)}),(B,{(B,1),(B,2)}),(C,{(C,2)})})");
}
/**