Skip to content

Commit 0cb5032

Browse files
xiefan46binmahone
authored andcommitted
KYLIN-2384 backward compatible
Signed-off-by: Hongbin Ma <[email protected]>
1 parent f38d871 commit 0cb5032

File tree

4 files changed

+44
-27
lines changed

4 files changed

+44
-27
lines changed

core-dictionary/src/main/java/org/apache/kylin/dict/Number2BytesConverter.java

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public Number2BytesConverter(int maxDigitsBeforeDecimalPoint) {
5353
this.maxDigitsBeforeDecimalPoint = maxDigitsBeforeDecimalPoint;
5454
}
5555

56+
public void setMaxDigitsBeforeDecimalPoint(int maxDigitsBeforeDecimalPoint) {
57+
this.maxDigitsBeforeDecimalPoint = maxDigitsBeforeDecimalPoint;
58+
}
59+
5660
@Override
5761
public byte[] convertToBytes(String v) {
5862
NumberBytesCodec codec = getCodec(this.maxDigitsBeforeDecimalPoint);

core-dictionary/src/main/java/org/apache/kylin/dict/NumberDictionary.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
package org.apache.kylin.dict;
2020

2121

22+
import org.apache.kylin.common.util.ClassUtil;
23+
2224
/**
2325
* @author yangli9
2426
*
@@ -32,6 +34,7 @@ public class NumberDictionary<T> extends TrieDictionary<T> {
3234

3335
public NumberDictionary() { // default constructor for Writable interface
3436
super();
37+
3538
}
3639

3740
public NumberDictionary(byte[] trieBytes) {
@@ -42,6 +45,13 @@ public NumberDictionary(byte[] trieBytes) {
4245
protected boolean isNullObjectForm(T value) {
4346
return value == null || value.equals("");
4447
}
45-
48+
49+
@Override
50+
protected void setConverterByName(String converterName) throws Exception {
51+
converterName = "org.apache.kylin.dict.Number2BytesConverter";
52+
this.bytesConvert = ClassUtil.forName(converterName, BytesConverter.class).newInstance();
53+
((Number2BytesConverter)this.bytesConvert).setMaxDigitsBeforeDecimalPoint(Number2BytesConverter.MAX_DIGITS_BEFORE_DECIMAL_POINT_LEGACY);
54+
}
55+
4656

4757
}

core-dictionary/src/main/java/org/apache/kylin/dict/NumberDictionary2.java

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
package org.apache.kylin.dict;
2020

21+
import org.apache.kylin.common.util.ClassUtil;
22+
2123
/**
2224
* This class uses MAX_DIGITS_BEFORE_DECIMAL_POINT (=19) instead of legacy (=16).
2325
*/
@@ -35,5 +37,10 @@ public NumberDictionary2(byte[] trieBytes) {
3537
super(trieBytes);
3638
}
3739

40+
@Override
41+
protected void setConverterByName(String converterName) throws Exception {
42+
converterName = "org.apache.kylin.dict.Number2BytesConverter";
43+
this.bytesConvert = ClassUtil.forName(converterName, BytesConverter.class).newInstance();
44+
}
3845

3946
}

core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionary.java

+22-26
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@
4242
/**
4343
* A dictionary based on Trie data structure that maps enumerations of byte[] to
4444
* int IDs.
45-
*
45+
* <p>
4646
* With Trie the memory footprint of the mapping is kinda minimized at the cost
4747
* CPU, if compared to HashMap of ID Arrays. Performance test shows Trie is
4848
* roughly 10 times slower, so there's a cache layer overlays on top of Trie and
4949
* gracefully fall back to Trie using a weak reference.
50-
*
50+
* <p>
5151
* The implementation is thread-safe.
52-
*
52+
*
5353
* @author yangli9
5454
*/
55-
@SuppressWarnings({ "rawtypes", "unchecked" })
55+
@SuppressWarnings({"rawtypes", "unchecked"})
5656
public class TrieDictionary<T> extends CacheDictionary<T> {
5757
private static final long serialVersionUID = 1L;
5858

59-
public static final byte[] MAGIC = new byte[] { 0x54, 0x72, 0x69, 0x65, 0x44, 0x69, 0x63, 0x74 }; // "TrieDict"
59+
public static final byte[] MAGIC = new byte[]{0x54, 0x72, 0x69, 0x65, 0x44, 0x69, 0x63, 0x74}; // "TrieDict"
6060
public static final int MAGIC_SIZE_I = MAGIC.length;
6161

6262
public static final int BIT_IS_LAST_CHILD = 0x80;
@@ -104,7 +104,7 @@ private void init(byte[] trieBytes) {
104104

105105
String converterName = headIn.readUTF();
106106
if (converterName.isEmpty() == false)
107-
this.bytesConvert = ClassUtil.forName(converterName, BytesConverter.class).newInstance();
107+
setConverterByName(converterName);
108108

109109
this.nValues = BytesUtil.readUnsigned(trieBytes, headSize + sizeChildOffset, sizeNoValuesBeneath);
110110
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 @@ private void init(byte[] trieBytes) {
119119
}
120120
}
121121

122+
protected void setConverterByName(String converterName) throws Exception {
123+
this.bytesConvert = ClassUtil.forName(converterName, BytesConverter.class).newInstance();
124+
}
125+
122126
@Override
123127
public int getMinId() {
124128
return baseId;
@@ -151,19 +155,14 @@ protected int getIdFromValueBytesWithoutCache(byte[] value, int offset, int len,
151155

152156
/**
153157
* returns a code point from [0, nValues), preserving order of value
154-
*
155-
* @param n
156-
* -- the offset of current node
157-
* @param inp
158-
* -- input value bytes to lookup
159-
* @param o
160-
* -- offset in the input value bytes matched so far
161-
* @param inpEnd
162-
* -- end of input
163-
* @param roundingFlag
164-
* -- =0: return -1 if not found
165-
* -- <0: return closest smaller if not found, return -1
166-
* -- >0: return closest bigger if not found, return nValues
158+
*
159+
* @param n -- the offset of current node
160+
* @param inp -- input value bytes to lookup
161+
* @param o -- offset in the input value bytes matched so far
162+
* @param inpEnd -- end of input
163+
* @param roundingFlag -- =0: return -1 if not found
164+
* -- <0: return closest smaller if not found, return -1
165+
* -- >0: return closest bigger if not found, return nValues
167166
*/
168167
private int lookupSeqNoFromValue(int n, byte[] inp, int o, int inpEnd, int roundingFlag) {
169168
if (o == inpEnd) // special 'empty' value
@@ -257,13 +256,10 @@ protected int getValueBytesFromIdImpl(int id, byte[] returnValue, int offset) {
257256
/**
258257
* returns a code point from [0, nValues), preserving order of value, or -1
259258
* if not found
260-
*
261-
* @param n
262-
* -- the offset of current node
263-
* @param seq
264-
* -- the code point under track
265-
* @param returnValue
266-
* -- where return value is written to
259+
*
260+
* @param n -- the offset of current node
261+
* @param seq -- the code point under track
262+
* @param returnValue -- where return value is written to
267263
*/
268264
private int lookupValueFromSeqNo(int n, int seq, byte[] returnValue, int offset) {
269265
int o = offset;

0 commit comments

Comments
 (0)