You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2016/11/19 12:02:40 UTC

kylin git commit: KYLIN-1851 fix empty dict bug

Repository: kylin
Updated Branches:
  refs/heads/master a6e3ccd7b -> 2b2eb3405


KYLIN-1851 fix empty dict bug

Signed-off-by: Yang Li <li...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/2b2eb340
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/2b2eb340
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/2b2eb340

Branch: refs/heads/master
Commit: 2b2eb3405fce57307496ba809e3da25c0bd9849d
Parents: a6e3ccd
Author: xiefan46 <95...@qq.com>
Authored: Sat Nov 19 18:33:29 2016 +0800
Committer: Yang Li <li...@apache.org>
Committed: Sat Nov 19 20:01:57 2016 +0800

----------------------------------------------------------------------
 .../apache/kylin/dict/TrieDictionaryForest.java   | 12 +++++++++---
 .../kylin/dict/TrieDictionaryForestTest.java      | 18 ++++++++++++++++++
 2 files changed, 27 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/2b2eb340/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionaryForest.java
----------------------------------------------------------------------
diff --git a/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionaryForest.java b/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionaryForest.java
index eb33a5a..6525fe5 100755
--- a/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionaryForest.java
+++ b/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionaryForest.java
@@ -32,6 +32,8 @@ import org.apache.kylin.common.util.Bytes;
 import org.apache.kylin.common.util.BytesUtil;
 import org.apache.kylin.common.util.ClassUtil;
 import org.apache.kylin.common.util.Dictionary;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Use trie forest to optimize trie dictionary
@@ -55,11 +57,13 @@ public class TrieDictionaryForest<T> extends Dictionary<T> {
 
     private ArrayList<ByteArray> maxValue;
 
+    private static final Logger logger = LoggerFactory.getLogger(TrieDictionaryForest.class);
+
     public TrieDictionaryForest() { // default constructor for Writable interface
     }
 
     public TrieDictionaryForest(ArrayList<TrieDictionary<T>> trees, ArrayList<ByteArray> valueDivide, //
-                                ArrayList<Integer> accuOffset, BytesConverter<T> bytesConverter, int baseId) {
+            ArrayList<Integer> accuOffset, BytesConverter<T> bytesConverter, int baseId) {
         this.trees = trees;
         this.valueDivide = valueDivide;
         this.accuOffset = accuOffset;
@@ -372,8 +376,10 @@ public class TrieDictionaryForest<T> extends Dictionary<T> {
 
     private void initMaxValue() throws IllegalStateException {
         this.maxValue = new ArrayList<>();
-        if (this.trees == null || trees.isEmpty())
-            throw new IllegalStateException("Trees not init yet. Could not init max value of each tree");
+        if (this.trees == null || trees.isEmpty()) {
+            logger.info("Trees not init yet or trees size is zero. Could not init max value of each tree");
+            return;
+        }
         for (int i = 0; i < trees.size(); i++) {
             T curTreeMax = trees.get(i).getValueFromId(trees.get(i).getMaxId());
             byte[] b1 = bytesConvert.convertToBytes(curTreeMax);

http://git-wip-us.apache.org/repos/asf/kylin/blob/2b2eb340/core-dictionary/src/test/java/org/apache/kylin/dict/TrieDictionaryForestTest.java
----------------------------------------------------------------------
diff --git a/core-dictionary/src/test/java/org/apache/kylin/dict/TrieDictionaryForestTest.java b/core-dictionary/src/test/java/org/apache/kylin/dict/TrieDictionaryForestTest.java
index c4c0fd8..acd6894 100755
--- a/core-dictionary/src/test/java/org/apache/kylin/dict/TrieDictionaryForestTest.java
+++ b/core-dictionary/src/test/java/org/apache/kylin/dict/TrieDictionaryForestTest.java
@@ -274,6 +274,24 @@ public class TrieDictionaryForestTest {
     }
 
     @Test
+    public void emptyDictTest() throws Exception{
+        TrieDictionaryForestBuilder<String> b = new TrieDictionaryForestBuilder<String>(new StringBytesConverter());
+        TrieDictionaryForest<String> dict = b.build();
+        try{
+            int id = dict.getIdFromValue("123",0);
+            fail("id should not exist");
+        }catch (IllegalArgumentException e){
+            //right
+        }
+        try{
+            String value = dict.getValueFromIdImpl(123);
+            fail("value should not exist");
+        }catch (IllegalArgumentException e){
+            //right
+        }
+    }
+
+    @Test
     public void roundingFlagTest() {
         ArrayList<String> testData = new ArrayList<>();
         testData.add("b");