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 2017/02/04 06:17:01 UTC

[39/39] kylin git commit: KYLIN-2422 NumberDictionary support for decimal with extra 0 after "."

KYLIN-2422 NumberDictionary support for decimal with extra 0 after "."


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

Branch: refs/heads/spark-it
Commit: b0a3a28eb7f5f4708790bee188071a9cec94e925
Parents: fac9f35
Author: shaofengshi <sh...@apache.org>
Authored: Sat Feb 4 14:16:11 2017 +0800
Committer: shaofengshi <sh...@apache.org>
Committed: Sat Feb 4 14:16:11 2017 +0800

----------------------------------------------------------------------
 .../org/apache/kylin/dict/NumberDictionary.java | 25 ++++++++++++++++++++
 .../apache/kylin/dict/NumberDictionaryTest.java |  5 +++-
 2 files changed, 29 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/b0a3a28e/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 c55937d..de28440 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
@@ -53,6 +53,7 @@ public class NumberDictionary<T> extends TrieDictionary<T> {
                 return;
             }
 
+
             if (len > buf.length) {
                 throw new IllegalArgumentException("Too many digits for NumberDictionary: " + Bytes.toString(value, offset, len) + ". Internal buffer is only " + buf.length + " bytes");
             }
@@ -104,6 +105,30 @@ public class NumberDictionary<T> extends TrieDictionary<T> {
 
             bufOffset = start;
             bufLen = buf.length - start;
+
+            // remove 0 in tail after the decimal point
+            if (decimalPoint != end) {
+                if (negative == true) {
+                    while (buf[bufOffset + bufLen - 2] == '9' && (bufOffset + bufLen - 2 > decimalPoint)) {
+                        bufLen--;
+                    }
+
+                    if (bufOffset + bufLen - 2 == decimalPoint) {
+                        bufLen--;
+                    }
+
+                    buf[bufOffset + bufLen - 1] = ';';
+                } else {
+                    while (buf[bufOffset + bufLen - 1] == '0' && (bufOffset + bufLen - 1 > decimalPoint)) {
+                        bufLen--;
+                    }
+
+                    if (bufOffset + bufLen - 1 == decimalPoint) {
+                        bufLen--;
+                    }
+
+                }
+            }
         }
 
         int decodeNumber(byte[] returnValue, int offset) {

http://git-wip-us.apache.org/repos/asf/kylin/blob/b0a3a28e/core-dictionary/src/test/java/org/apache/kylin/dict/NumberDictionaryTest.java
----------------------------------------------------------------------
diff --git a/core-dictionary/src/test/java/org/apache/kylin/dict/NumberDictionaryTest.java b/core-dictionary/src/test/java/org/apache/kylin/dict/NumberDictionaryTest.java
index 1c04745..36eedf5 100644
--- a/core-dictionary/src/test/java/org/apache/kylin/dict/NumberDictionaryTest.java
+++ b/core-dictionary/src/test/java/org/apache/kylin/dict/NumberDictionaryTest.java
@@ -91,11 +91,14 @@ public class NumberDictionaryTest extends LocalFileMetadataTestCase {
         checkCodec("-12345", "-9999999999999987654;");
         checkCodec("-12345.123", "-9999999999999987654.876;");
         checkCodec("0", "00000000000000000000");
-        checkCodec("0.0", "00000000000000000000.0");
         //test resolved jira-1800
         checkCodec("-0.0045454354354354359999999999877218", "-9999999999999999999.9954545645645645640000000000122781;");
         checkCodec("-0.009999999999877218", "-9999999999999999999.990000000000122781;");
         checkCodec("12343434372493274.438403840384023840253554345345345345", "00012343434372493274.438403840384023840253554345345345345");
+        assertEquals("00000000000000000052.57", encodeNumber("52.5700"));
+        assertEquals("00000000000000000000", encodeNumber("0.00"));
+        assertEquals("00000000000000000000", encodeNumber("0.0"));
+        assertEquals("-9999999999999987654.876;", encodeNumber("-12345.12300"));
     }
 
     private void checkCodec(String number, String code) {