tttMelody closed pull request #117: KYLIN-3293, fix FixedLenHexDimEnc.java 
return a wrong code length lea…
URL: https://github.com/apache/kylin/pull/117
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/core-metadata/src/main/java/org/apache/kylin/dimension/FixedLenHexDimEnc.java 
b/core-metadata/src/main/java/org/apache/kylin/dimension/FixedLenHexDimEnc.java
index a931450a0b..1eb0565062 100644
--- 
a/core-metadata/src/main/java/org/apache/kylin/dimension/FixedLenHexDimEnc.java
+++ 
b/core-metadata/src/main/java/org/apache/kylin/dimension/FixedLenHexDimEnc.java
@@ -117,7 +117,6 @@ public DimensionEncoding createDimensionEncoding(String 
encodingName, String[] a
     // 
============================================================================
 
     private int hexLength;
-    private int bytelen;
 
     transient private int avoidVerbose = 0;
     transient private int avoidVerbose2 = 0;
@@ -131,7 +130,6 @@ public FixedLenHexDimEnc(int len) {
             throw new IllegalArgumentException("len has to be positive: " + 
len);
         }
         this.hexLength = len;
-        this.bytelen = (hexLength + 1) / 2;
     }
 
     @Override
@@ -153,20 +151,20 @@ public int hashCode() {
 
     @Override
     public int getLengthOfEncoding() {
-        return bytelen;
+        return getByteLen();
     }
 
     @Override
     public void encode(String valueStr, byte[] output, int outputOffset) {
         if (valueStr == null) {
-            Arrays.fill(output, outputOffset, outputOffset + bytelen, NULL);
+            Arrays.fill(output, outputOffset, outputOffset + getByteLen(), 
NULL);
             return;
         }
 
         byte[] value = Bytes.toBytes(valueStr);
         int valueLen = value.length;
-        int endOffset = outputOffset + bytelen;
-        
+        int endOffset = outputOffset + getByteLen();
+
         if (valueLen > hexLength) {
             if (avoidVerbose++ % 10000 == 0) {
                 logger.warn("Expect at most " + hexLength + " bytes, but got " 
+ valueLen + ", will truncate, value string: " + Bytes.toString(value, 0, 
valueLen) + " times:" + avoidVerbose);
@@ -199,7 +197,7 @@ public void encode(String valueStr, byte[] output, int 
outputOffset) {
 
     @Override
     public String decode(byte[] bytes, int offset, int len) {
-        Preconditions.checkArgument(len == bytelen, "len " + len + " not 
equals " + bytelen);
+        Preconditions.checkArgument(len == getByteLen(), "len " + len + " not 
equals " + getByteLen());
 
         if (isNull(bytes, offset, len)) {
             return null;
@@ -229,7 +227,7 @@ public String decode(byte[] bytes, int offset, int len) {
         private byte[] currentBuf() {
             byte[] buf = (byte[]) current.get();
             if (buf == null) {
-                buf = new byte[bytelen];
+                buf = new byte[getByteLen()];
                 current.set(buf);
             }
             return buf;
@@ -252,17 +250,17 @@ public Object deserialize(ByteBuffer in) {
 
         @Override
         public int peekLength(ByteBuffer in) {
-            return bytelen;
+            return getByteLen();
         }
 
         @Override
         public int maxLength() {
-            return bytelen;
+            return getByteLen();
         }
 
         @Override
         public int getStorageBytesEstimate() {
-            return bytelen;
+            return getByteLen();
         }
 
         @Override
@@ -290,4 +288,7 @@ private boolean isF(byte[] value, int offset, int length) {
         return true;
     }
 
+    private int getByteLen() {
+        return (this.hexLength + 1) / 2;
+    }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to