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 2016/10/20 08:00:36 UTC
kylin git commit: KYLIN-1917 cleanup and rename
Repository: kylin
Updated Branches:
refs/heads/master d1bc6e3de -> 24f26dbd6
KYLIN-1917 cleanup and rename
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/24f26dbd
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/24f26dbd
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/24f26dbd
Branch: refs/heads/master
Commit: 24f26dbd6cb5b950cf5f3139caacc984ae67f909
Parents: d1bc6e3
Author: shaofengshi <sh...@apache.org>
Authored: Thu Oct 20 16:00:16 2016 +0800
Committer: shaofengshi <sh...@apache.org>
Committed: Thu Oct 20 16:00:31 2016 +0800
----------------------------------------------------------------------
.../org/apache/kylin/measure/topn/Counter.java | 5 -
.../kylin/measure/topn/DoublyLinkedList.java | 138 -------------------
.../apache/kylin/measure/topn/ListNode2.java | 51 -------
.../apache/kylin/measure/topn/TopNCounter.java | 15 +-
.../topn/TopNCounterSerializerTest.java | 2 +-
5 files changed, 8 insertions(+), 203 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/24f26dbd/core-metadata/src/main/java/org/apache/kylin/measure/topn/Counter.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/main/java/org/apache/kylin/measure/topn/Counter.java b/core-metadata/src/main/java/org/apache/kylin/measure/topn/Counter.java
index cd5b825..2f625af 100644
--- a/core-metadata/src/main/java/org/apache/kylin/measure/topn/Counter.java
+++ b/core-metadata/src/main/java/org/apache/kylin/measure/topn/Counter.java
@@ -31,10 +31,7 @@ import java.io.ObjectOutput;
public class Counter<T> implements Externalizable {
protected T item;
-
-
protected double count;
- // protected double error;
/**
* For de-serialization
@@ -74,13 +71,11 @@ public class Counter<T> implements Externalizable {
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
item = (T) in.readObject();
count = in.readDouble();
- //error = in.readDouble();
}
@Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(item);
out.writeDouble(count);
- //out.writeDouble(error);
}
}
http://git-wip-us.apache.org/repos/asf/kylin/blob/24f26dbd/core-metadata/src/main/java/org/apache/kylin/measure/topn/DoublyLinkedList.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/main/java/org/apache/kylin/measure/topn/DoublyLinkedList.java b/core-metadata/src/main/java/org/apache/kylin/measure/topn/DoublyLinkedList.java
deleted file mode 100644
index bb4fa6d..0000000
--- a/core-metadata/src/main/java/org/apache/kylin/measure/topn/DoublyLinkedList.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
-*/
-
-package org.apache.kylin.measure.topn;
-
-/**
- * Modified from DoublyLinkedList.java in https://github.com/addthis/stream-lib
- *
- * @param <T>
- */
-public class DoublyLinkedList<T> {
-
- private int size = 0;
- private ListNode2<T> tail;
- private ListNode2<T> head;
-
- /**
- * Append to head of list
- */
- public ListNode2<T> add(T value) {
- ListNode2<T> node = new ListNode2<T>(value);
- add(node);
-
- return node;
- }
-
- /**
- * Prepend to tail of list
- */
- public ListNode2<T> enqueue(T value) {
- ListNode2<T> node = new ListNode2<T>(value);
-
- return enqueue(node);
- }
-
- public ListNode2<T> enqueue(ListNode2<T> node) {
- if (size++ == 0) {
- head = node;
- } else {
- node.next = tail;
- tail.prev = node;
- }
-
- tail = node;
-
- return node;
- }
-
- public void add(ListNode2<T> node) {
- node.prev = head;
- node.next = null;
-
- if (size++ == 0) {
- tail = node;
- } else {
- head.next = node;
- }
-
- head = node;
- }
-
- public ListNode2<T> addAfter(ListNode2<T> node, T value) {
- ListNode2<T> newNode = new ListNode2<T>(value);
- addAfter(node, newNode);
- return newNode;
- }
-
- public void addAfter(ListNode2<T> node, ListNode2<T> newNode) {
- newNode.next = node.next;
- newNode.prev = node;
- node.next = newNode;
- if (newNode.next == null) {
- head = newNode;
- } else {
- newNode.next.prev = newNode;
- }
- size++;
- }
-
- public void addBefore(ListNode2<T> node, ListNode2<T> newNode) {
- newNode.prev = node.prev;
- newNode.next = node;
- node.prev = newNode;
- if (newNode.prev == null) {
- tail = newNode;
- } else {
- newNode.prev.next = newNode;
- }
- size++;
- }
-
- public void remove(ListNode2<T> node) {
- if (node == tail) {
- tail = node.next;
- } else {
- node.prev.next = node.next;
- }
-
- if (node == head) {
- head = node.prev;
- } else {
- node.next.prev = node.prev;
- }
- size--;
- }
-
- public int size() {
- return size;
- }
-
- public ListNode2<T> head() {
- return head;
- }
-
- public ListNode2<T> tail() {
- return tail;
- }
-
- public boolean isEmpty() {
- return size == 0;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/24f26dbd/core-metadata/src/main/java/org/apache/kylin/measure/topn/ListNode2.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/main/java/org/apache/kylin/measure/topn/ListNode2.java b/core-metadata/src/main/java/org/apache/kylin/measure/topn/ListNode2.java
deleted file mode 100644
index b2f47c9..0000000
--- a/core-metadata/src/main/java/org/apache/kylin/measure/topn/ListNode2.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
-*/
-
-package org.apache.kylin.measure.topn;
-
-/**
- * Modified from ListNode2.java in https://github.com/addthis/stream-lib
- *
- * @param <T>
- */
-public class ListNode2<T> {
-
- protected T value;
- protected ListNode2<T> prev;
- protected ListNode2<T> next;
-
- public ListNode2(T value) {
- this.value = value;
- }
-
- public ListNode2<T> getPrev() {
- return prev;
- }
-
- public ListNode2<T> getNext() {
- return next;
- }
-
- public T getValue() {
- return value;
- }
-
- public void setValue(T value) {
- this.value = value;
- }
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/24f26dbd/core-metadata/src/main/java/org/apache/kylin/measure/topn/TopNCounter.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/main/java/org/apache/kylin/measure/topn/TopNCounter.java b/core-metadata/src/main/java/org/apache/kylin/measure/topn/TopNCounter.java
index cf9978a..968e694 100644
--- a/core-metadata/src/main/java/org/apache/kylin/measure/topn/TopNCounter.java
+++ b/core-metadata/src/main/java/org/apache/kylin/measure/topn/TopNCounter.java
@@ -92,17 +92,17 @@ public class TopNCounter<T> implements Iterable<Counter<T>> {
}
/**
- * Resort and keep the expected size
+ * Sort and keep the expected size;
*/
- public void consolidate() {
- Collections.sort(counterList, this.descending ? DESC_Comparator : ASC_Comparator);
+ public void sortAndRetain() {
+ Collections.sort(counterList, this.descending ? DESC_COMPARATOR : ASC_COMPARATOR);
retain(capacity);
ordered = true;
}
public List<Counter<T>> topK(int k) {
if (ordered == false) {
- consolidate();
+ sortAndRetain();
}
List<Counter<T>> topK = new ArrayList<>(k);
Iterator<Counter<T>> iterator = counterList.iterator();
@@ -195,7 +195,7 @@ public class TopNCounter<T> implements Iterable<Counter<T>> {
}
}
- this.consolidate();
+ this.sortAndRetain();
return this;
}
@@ -204,7 +204,6 @@ public class TopNCounter<T> implements Iterable<Counter<T>> {
* @param newCapacity
*/
public void retain(int newCapacity) {
- assert newCapacity > 0;
this.capacity = newCapacity;
if (this.size() > newCapacity) {
Counter<T> toRemoved;
@@ -248,7 +247,7 @@ public class TopNCounter<T> implements Iterable<Counter<T>> {
}
}
- private static final Comparator ASC_Comparator = new Comparator<Counter>() {
+ private static final Comparator ASC_COMPARATOR = new Comparator<Counter>() {
@Override
public int compare(Counter o1, Counter o2) {
return o1.getCount() > o2.getCount() ? 1 : o1.getCount() == o2.getCount() ? 0 : -1;
@@ -256,7 +255,7 @@ public class TopNCounter<T> implements Iterable<Counter<T>> {
};
- private static final Comparator DESC_Comparator = new Comparator<Counter>() {
+ private static final Comparator DESC_COMPARATOR = new Comparator<Counter>() {
@Override
public int compare(Counter o1, Counter o2) {
return o1.getCount() > o2.getCount() ? -1 : o1.getCount() == o2.getCount() ? 0 : 1;
http://git-wip-us.apache.org/repos/asf/kylin/blob/24f26dbd/core-metadata/src/test/java/org/apache/kylin/aggregation/topn/TopNCounterSerializerTest.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/test/java/org/apache/kylin/aggregation/topn/TopNCounterSerializerTest.java b/core-metadata/src/test/java/org/apache/kylin/aggregation/topn/TopNCounterSerializerTest.java
index dedb4f5..1ce17fe 100644
--- a/core-metadata/src/test/java/org/apache/kylin/aggregation/topn/TopNCounterSerializerTest.java
+++ b/core-metadata/src/test/java/org/apache/kylin/aggregation/topn/TopNCounterSerializerTest.java
@@ -55,7 +55,7 @@ public class TopNCounterSerializerTest extends LocalFileMetadataTestCase {
for (Integer i : stream) {
vs.offer(new ByteArray(Bytes.toBytes(i)));
}
- vs.consolidate();
+ vs.sortAndRetain();
ByteBuffer out = ByteBuffer.allocate(1024);
serializer.serialize(vs, out);