Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fix joins

  • Loading branch information...
commit 36b9fea0d8bc023dd07524a64b99b18489262712 1 parent 34ae39f
Nathan Marz authored
2  src/jvm/storm/trident/operation/GroupedMultiReducer.java
@@ -7,7 +7,7 @@
7 7
8 8 public interface GroupedMultiReducer<T> extends Serializable {
9 9 void prepare(Map conf, TridentMultiReducerContext context);
10   - T init(TridentCollector collector);
  10 + T init(TridentCollector collector, TridentTuple group);
11 11 void execute(T state, int streamIndex, TridentTuple group, TridentTuple input, TridentCollector collector);
12 12 void complete(T state, TridentTuple group, TridentCollector collector);
13 13 void cleanup();
5 src/jvm/storm/trident/operation/impl/GroupedMultiReducerExecutor.java
@@ -26,6 +26,7 @@ public GroupedMultiReducerExecutor(GroupedMultiReducer reducer, List<Fields> gro
26 26 }
27 27 _groupFields = groupFields;
28 28 _inputFields = inputFields;
  29 + _reducer = reducer;
29 30 }
30 31
31 32 @Override
@@ -48,11 +49,11 @@ public void execute(Map<TridentTuple, Object> state, int streamIndex, TridentTup
48 49 ProjectionFactory inputFactory = _inputFactories.get(streamIndex);
49 50
50 51 TridentTuple group = groupFactory.create(full);
51   - TridentTuple input = groupFactory.create(full);
  52 + TridentTuple input = inputFactory.create(full);
52 53
53 54 Object curr;
54 55 if(!state.containsKey(group)) {
55   - curr = _reducer.init(collector);
  56 + curr = _reducer.init(collector, group);
56 57 state.put(group, curr);
57 58 } else {
58 59 curr = state.get(group);
18 src/jvm/storm/trident/operation/impl/JoinerMultiReducer.java
@@ -30,15 +30,15 @@ public JoinerMultiReducer(List<JoinType> types, int numGroupFields, List<Fields>
30 30 public void prepare(Map conf, TridentMultiReducerContext context) {
31 31 int[] sizes = new int[_sideFields.size() + 1];
32 32 sizes[0] = _numGroupFields;
33   - for(int i=0; i<_sideFields.size()-1; i++) {
  33 + for(int i=0; i<_sideFields.size(); i++) {
34 34 sizes[i+1] = _sideFields.get(i).size();
35 35 }
36 36 _factory = new ComboList.Factory(sizes);
37 37 }
38 38
39 39 @Override
40   - public JoinState init(TridentCollector collector) {
41   - return new JoinState(_types.size());
  40 + public JoinState init(TridentCollector collector, TridentTuple group) {
  41 + return new JoinState(_types.size(), group);
42 42 }
43 43
44 44 @Override
@@ -49,6 +49,7 @@ public void execute(JoinState state, int streamIndex, TridentTuple group, Triden
49 49 if(side.isEmpty()) {
50 50 state.numSidesReceived++;
51 51 }
  52 +
52 53 side.add(input);
53 54 if(state.numSidesReceived == state.sides.length) {
54 55 emitCrossJoin(state, collector, streamIndex, input);
@@ -92,12 +93,13 @@ private void emitCrossJoin(JoinState state, TridentCollector collector, int over
92 93 boolean keepGoing = true;
93 94 //emit cross-join of all emitted tuples
94 95 while(keepGoing) {
95   - List[] combined = new List[sides.length];
  96 + List[] combined = new List[sides.length+1];
  97 + combined[0] = state.group;
96 98 for(int i=0; i<sides.length; i++) {
97 99 if(i==overrideIndex) {
98   - combined[i] = overrideTuple;
  100 + combined[i+1] = overrideTuple;
99 101 } else {
100   - combined[i] = sides[i].get(indices[i]);
  102 + combined[i+1] = sides[i].get(indices[i]);
101 103 }
102 104 }
103 105 collector.emit(_factory.create(combined));
@@ -125,10 +127,12 @@ private boolean increment(List[] lengths, int[] indices, int j, int overrideInde
125 127 List<List>[] sides;
126 128 int numSidesReceived = 0;
127 129 int[] indices;
  130 + TridentTuple group;
128 131
129   - public JoinState(int numSides) {
  132 + public JoinState(int numSides, TridentTuple group) {
130 133 sides = new List[numSides];
131 134 indices = new int[numSides];
  135 + this.group = group;
132 136 for(int i=0; i<numSides; i++) {
133 137 sides[i] = new ArrayList<List>();
134 138 }

0 comments on commit 36b9fea

Please sign in to comment.
Something went wrong with that request. Please try again.