From 18884b1864648131d5418a91844b46e18a5a4b0b Mon Sep 17 00:00:00 2001 From: gwang3 Date: Thu, 21 Dec 2017 14:58:42 +0800 Subject: [PATCH] KYLIN-2956:building trie dictionary blocked on value of length over 4095 --- .../org/apache/kylin/common/util/BytesUtil.java | 2 +- .../org/apache/kylin/dict/TrieDictionaryTest.java | 30 +++++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/core-common/src/main/java/org/apache/kylin/common/util/BytesUtil.java b/core-common/src/main/java/org/apache/kylin/common/util/BytesUtil.java index d41c6b44e..6b64bbeb9 100644 --- a/core-common/src/main/java/org/apache/kylin/common/util/BytesUtil.java +++ b/core-common/src/main/java/org/apache/kylin/common/util/BytesUtil.java @@ -178,7 +178,7 @@ public class BytesUtil { } public static boolean isPositiveShort(int i) { - return (i & 0xFFFF7000) == 0; + return (i & 0xFFFF8000) == 0; } // from WritableUtils diff --git a/core-dictionary/src/test/java/org/apache/kylin/dict/TrieDictionaryTest.java b/core-dictionary/src/test/java/org/apache/kylin/dict/TrieDictionaryTest.java index 13c83ac39..600b0723a 100644 --- a/core-dictionary/src/test/java/org/apache/kylin/dict/TrieDictionaryTest.java +++ b/core-dictionary/src/test/java/org/apache/kylin/dict/TrieDictionaryTest.java @@ -39,6 +39,7 @@ import java.util.NoSuchElementException; import java.util.Random; import java.util.TreeSet; +import org.junit.Assert; import org.junit.Test; public class TrieDictionaryTest { @@ -408,13 +409,34 @@ public class TrieDictionaryTest { String longPrefix = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" + "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"; TrieDictionaryBuilder b = new TrieDictionaryBuilder(new StringBytesConverter()); - String v1 = longPrefix + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"; - String v2 = longPrefix + "xyz"; - + String v1 = longPrefix + "xyz"; b.addValue(v1); - b.addValue(v2); + + String strLen200 = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghid"; + b.addValue(strLen200); + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < 25; i++) { + sb.append(strLen200); + } + String strLen5000 = sb.toString(); + b.addValue(strLen5000); TrieDictionary dict = b.build(0); dict.dump(System.out); + + sb.setLength(0); + for (int j = 0; j < 7; j++) { + sb.append(strLen5000); + } + String strLen35000 = sb.toString(); + b.addValue(strLen35000); + Exception ex = null; + try { + b.build(0); + } catch (Exception e) { + ex = e; + } + Assert.assertNotNull(ex); } @Test -- 2.14.3 (Apple Git-98)