You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by sh...@apache.org on 2015/10/21 03:55:18 UTC
[2/2] incubator-kylin git commit: KYLIN-1068 update topN merge method,
not change the to-be merged object
KYLIN-1068 update topN merge method, not change the to-be merged object
Project: http://git-wip-us.apache.org/repos/asf/incubator-kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kylin/commit/a5200d1b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kylin/tree/a5200d1b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kylin/diff/a5200d1b
Branch: refs/heads/KYLIN-1068
Commit: a5200d1bdbbdb0d798a51c0fed8e5a755ca7b35d
Parents: e6fe122
Author: shaofengshi <sh...@apache.org>
Authored: Wed Oct 21 09:55:07 2015 +0800
Committer: shaofengshi <sh...@apache.org>
Committed: Wed Oct 21 09:55:07 2015 +0800
----------------------------------------------------------------------
.../org/apache/kylin/common/topn/TopNCounter.java | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/a5200d1b/core-common/src/main/java/org/apache/kylin/common/topn/TopNCounter.java
----------------------------------------------------------------------
diff --git a/core-common/src/main/java/org/apache/kylin/common/topn/TopNCounter.java b/core-common/src/main/java/org/apache/kylin/common/topn/TopNCounter.java
index 1856010..0196be7 100644
--- a/core-common/src/main/java/org/apache/kylin/common/topn/TopNCounter.java
+++ b/core-common/src/main/java/org/apache/kylin/common/topn/TopNCounter.java
@@ -19,6 +19,7 @@
package org.apache.kylin.common.topn;
import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
import org.apache.kylin.common.util.Pair;
import java.util.*;
@@ -202,7 +203,7 @@ public class TopNCounter<T> implements ITopK<T>, Iterable<Counter<T>> {
}
/**
- * Merge another counter into this counter; Note, the other counter will be changed in this method; please make a copy and passed in here;
+ * Merge another counter into this counter;
* @param another
* @return
*/
@@ -216,13 +217,15 @@ public class TopNCounter<T> implements ITopK<T>, Iterable<Counter<T>> {
m2 = another.counterList.tail().getValue().count;
}
+ Set<T> duplicateItems = Sets.newHashSet();
+
for (Map.Entry<T, ListNode2<Counter<T>>> entry : this.counterMap.entrySet()) {
T item = entry.getKey();
ListNode2<Counter<T>> existing = another.counterMap.get(item);
if (existing != null) {
this.offer(item, another.counterMap.get(item).getValue().count);
- another.counterMap.remove(item);
+ duplicateItems.add(item);
} else {
this.offer(item, m2);
}
@@ -230,8 +233,10 @@ public class TopNCounter<T> implements ITopK<T>, Iterable<Counter<T>> {
for (Map.Entry<T, ListNode2<Counter<T>>> entry : another.counterMap.entrySet()) {
T item = entry.getKey();
- double counter = entry.getValue().getValue().count;
- this.offer(item, counter + m1);
+ if (duplicateItems.contains(item) == false) {
+ double counter = entry.getValue().getValue().count;
+ this.offer(item, counter + m1);
+ }
}
return this;
@@ -324,4 +329,5 @@ public class TopNCounter<T> implements ITopK<T>, Iterable<Counter<T>> {
throw new UnsupportedOperationException();
}
}
+
}