KYLIN-2384 backward compatible Signed-off-by: Hongbin Ma <mahong...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/0cb5032e Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/0cb5032e Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/0cb5032e Branch: refs/heads/master-hbase0.98 Commit: 0cb5032ee8da30a91f5ef8914138852daead558d Parents: f38d871 Author: xiefan46 <958034...@qq.com> Authored: Sat Mar 11 16:46:54 2017 +0800 Committer: Hongbin Ma <mahong...@apache.org> Committed: Sat Mar 11 22:09:55 2017 +0800 ---------------------------------------------------------------------- .../kylin/dict/Number2BytesConverter.java | 4 ++ .../org/apache/kylin/dict/NumberDictionary.java | 12 ++++- .../apache/kylin/dict/NumberDictionary2.java | 7 +++ .../org/apache/kylin/dict/TrieDictionary.java | 48 +++++++++----------- 4 files changed, 44 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/0cb5032e/core-dictionary/src/main/java/org/apache/kylin/dict/Number2BytesConverter.java ---------------------------------------------------------------------- diff --git a/core-dictionary/src/main/java/org/apache/kylin/dict/Number2BytesConverter.java b/core-dictionary/src/main/java/org/apache/kylin/dict/Number2BytesConverter.java index 4e40527..814c95a 100644 --- a/core-dictionary/src/main/java/org/apache/kylin/dict/Number2BytesConverter.java +++ b/core-dictionary/src/main/java/org/apache/kylin/dict/Number2BytesConverter.java @@ -53,6 +53,10 @@ public class Number2BytesConverter implements BytesConverter<String>, Serializab this.maxDigitsBeforeDecimalPoint = maxDigitsBeforeDecimalPoint; } + public void setMaxDigitsBeforeDecimalPoint(int maxDigitsBeforeDecimalPoint) { + this.maxDigitsBeforeDecimalPoint = maxDigitsBeforeDecimalPoint; + } + @Override public byte[] convertToBytes(String v) { NumberBytesCodec codec = getCodec(this.maxDigitsBeforeDecimalPoint); http://git-wip-us.apache.org/repos/asf/kylin/blob/0cb5032e/core-dictionary/src/main/java/org/apache/kylin/dict/NumberDictionary.java ---------------------------------------------------------------------- diff --git a/core-dictionary/src/main/java/org/apache/kylin/dict/NumberDictionary.java b/core-dictionary/src/main/java/org/apache/kylin/dict/NumberDictionary.java index b987eda..1377e8e 100644 --- a/core-dictionary/src/main/java/org/apache/kylin/dict/NumberDictionary.java +++ b/core-dictionary/src/main/java/org/apache/kylin/dict/NumberDictionary.java @@ -19,6 +19,8 @@ package org.apache.kylin.dict; +import org.apache.kylin.common.util.ClassUtil; + /** * @author yangli9 * @@ -32,6 +34,7 @@ public class NumberDictionary<T> extends TrieDictionary<T> { public NumberDictionary() { // default constructor for Writable interface super(); + } public NumberDictionary(byte[] trieBytes) { @@ -42,6 +45,13 @@ public class NumberDictionary<T> extends TrieDictionary<T> { protected boolean isNullObjectForm(T value) { return value == null || value.equals(""); } - + + @Override + protected void setConverterByName(String converterName) throws Exception { + converterName = "org.apache.kylin.dict.Number2BytesConverter"; + this.bytesConvert = ClassUtil.forName(converterName, BytesConverter.class).newInstance(); + ((Number2BytesConverter)this.bytesConvert).setMaxDigitsBeforeDecimalPoint(Number2BytesConverter.MAX_DIGITS_BEFORE_DECIMAL_POINT_LEGACY); + } + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/kylin/blob/0cb5032e/core-dictionary/src/main/java/org/apache/kylin/dict/NumberDictionary2.java ---------------------------------------------------------------------- diff --git a/core-dictionary/src/main/java/org/apache/kylin/dict/NumberDictionary2.java b/core-dictionary/src/main/java/org/apache/kylin/dict/NumberDictionary2.java index 3879d33..0efe936 100644 --- a/core-dictionary/src/main/java/org/apache/kylin/dict/NumberDictionary2.java +++ b/core-dictionary/src/main/java/org/apache/kylin/dict/NumberDictionary2.java @@ -18,6 +18,8 @@ package org.apache.kylin.dict; +import org.apache.kylin.common.util.ClassUtil; + /** * This class uses MAX_DIGITS_BEFORE_DECIMAL_POINT (=19) instead of legacy (=16). */ @@ -35,5 +37,10 @@ public class NumberDictionary2<T> extends NumberDictionary<T> { super(trieBytes); } + @Override + protected void setConverterByName(String converterName) throws Exception { + converterName = "org.apache.kylin.dict.Number2BytesConverter"; + this.bytesConvert = ClassUtil.forName(converterName, BytesConverter.class).newInstance(); + } } http://git-wip-us.apache.org/repos/asf/kylin/blob/0cb5032e/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionary.java ---------------------------------------------------------------------- diff --git a/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionary.java b/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionary.java index 9b84734..8849015 100644 --- a/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionary.java +++ b/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionary.java @@ -42,21 +42,21 @@ import com.google.common.base.Preconditions; /** * A dictionary based on Trie data structure that maps enumerations of byte[] to * int IDs. - * + * <p> * With Trie the memory footprint of the mapping is kinda minimized at the cost * CPU, if compared to HashMap of ID Arrays. Performance test shows Trie is * roughly 10 times slower, so there's a cache layer overlays on top of Trie and * gracefully fall back to Trie using a weak reference. - * + * <p> * The implementation is thread-safe. - * + * * @author yangli9 */ -@SuppressWarnings({ "rawtypes", "unchecked" }) +@SuppressWarnings({"rawtypes", "unchecked"}) public class TrieDictionary<T> extends CacheDictionary<T> { private static final long serialVersionUID = 1L; - public static final byte[] MAGIC = new byte[] { 0x54, 0x72, 0x69, 0x65, 0x44, 0x69, 0x63, 0x74 }; // "TrieDict" + public static final byte[] MAGIC = new byte[]{0x54, 0x72, 0x69, 0x65, 0x44, 0x69, 0x63, 0x74}; // "TrieDict" public static final int MAGIC_SIZE_I = MAGIC.length; public static final int BIT_IS_LAST_CHILD = 0x80; @@ -104,7 +104,7 @@ public class TrieDictionary<T> extends CacheDictionary<T> { String converterName = headIn.readUTF(); if (converterName.isEmpty() == false) - this.bytesConvert = ClassUtil.forName(converterName, BytesConverter.class).newInstance(); + setConverterByName(converterName); this.nValues = BytesUtil.readUnsigned(trieBytes, headSize + sizeChildOffset, sizeNoValuesBeneath); this.sizeOfId = BytesUtil.sizeForValue(baseId + nValues + 1L); // note baseId could raise 1 byte in ID space, +1 to reserve all 0xFF for NULL case @@ -119,6 +119,10 @@ public class TrieDictionary<T> extends CacheDictionary<T> { } } + protected void setConverterByName(String converterName) throws Exception { + this.bytesConvert = ClassUtil.forName(converterName, BytesConverter.class).newInstance(); + } + @Override public int getMinId() { return baseId; @@ -151,19 +155,14 @@ public class TrieDictionary<T> extends CacheDictionary<T> { /** * returns a code point from [0, nValues), preserving order of value - * - * @param n - * -- the offset of current node - * @param inp - * -- input value bytes to lookup - * @param o - * -- offset in the input value bytes matched so far - * @param inpEnd - * -- end of input - * @param roundingFlag - * -- =0: return -1 if not found - * -- <0: return closest smaller if not found, return -1 - * -- >0: return closest bigger if not found, return nValues + * + * @param n -- the offset of current node + * @param inp -- input value bytes to lookup + * @param o -- offset in the input value bytes matched so far + * @param inpEnd -- end of input + * @param roundingFlag -- =0: return -1 if not found + * -- <0: return closest smaller if not found, return -1 + * -- >0: return closest bigger if not found, return nValues */ private int lookupSeqNoFromValue(int n, byte[] inp, int o, int inpEnd, int roundingFlag) { if (o == inpEnd) // special 'empty' value @@ -257,13 +256,10 @@ public class TrieDictionary<T> extends CacheDictionary<T> { /** * returns a code point from [0, nValues), preserving order of value, or -1 * if not found - * - * @param n - * -- the offset of current node - * @param seq - * -- the code point under track - * @param returnValue - * -- where return value is written to + * + * @param n -- the offset of current node + * @param seq -- the code point under track + * @param returnValue -- where return value is written to */ private int lookupValueFromSeqNo(int n, int seq, byte[] returnValue, int offset) { int o = offset;