[ 
https://issues.apache.org/jira/browse/KYLIN-3293?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16415201#comment-16415201
 ] 

ASF GitHub Bot commented on KYLIN-3293:
---------------------------------------

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

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-cube/src/main/java/org/apache/kylin/cube/gridtable/TrimmedCubeCodeSystem.java
 
b/core-cube/src/main/java/org/apache/kylin/cube/gridtable/TrimmedCubeCodeSystem.java
index a0b230e9b0..261e501d8c 100644
--- 
a/core-cube/src/main/java/org/apache/kylin/cube/gridtable/TrimmedCubeCodeSystem.java
+++ 
b/core-cube/src/main/java/org/apache/kylin/cube/gridtable/TrimmedCubeCodeSystem.java
@@ -51,7 +51,7 @@ public void encodeColumnValue(int col, Object value, int 
roundingFlag, ByteBuffe
         serializer.serialize(value, buf);
     }
 
-    private static void writeDimensionEncoding(DimensionEncoding encoding, 
ByteBuffer out) {
+    public static void writeDimensionEncoding(DimensionEncoding encoding, 
ByteBuffer out) {
         try {
             if (encoding == null) {
                 BytesUtil.writeVInt(1, out);
@@ -71,7 +71,7 @@ private static void writeDimensionEncoding(DimensionEncoding 
encoding, ByteBuffe
         }
     }
 
-    private static DimensionEncoding readDimensionEncoding(ByteBuffer in) {
+    public static DimensionEncoding readDimensionEncoding(ByteBuffer in) {
         try {
             int isNull = BytesUtil.readVInt(in);
             if (isNull == 1) {
diff --git 
a/core-cube/src/test/java/org/apache/kylin/gridtable/TrimmedCubeCodeSystemTest.java
 
b/core-cube/src/test/java/org/apache/kylin/gridtable/TrimmedCubeCodeSystemTest.java
new file mode 100644
index 0000000000..dc3c762119
--- /dev/null
+++ 
b/core-cube/src/test/java/org/apache/kylin/gridtable/TrimmedCubeCodeSystemTest.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kylin.gridtable;
+
+import static 
org.apache.kylin.cube.gridtable.TrimmedCubeCodeSystem.readDimensionEncoding;
+import static 
org.apache.kylin.cube.gridtable.TrimmedCubeCodeSystem.writeDimensionEncoding;
+
+import java.nio.ByteBuffer;
+
+import org.apache.kylin.dimension.DimensionEncoding;
+import org.apache.kylin.dimension.FixedLenHexDimEnc;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TrimmedCubeCodeSystemTest {
+    @Test
+    public void testFixLenHexEncSerDser() {
+        FixedLenHexDimEnc enc = new FixedLenHexDimEnc(6);
+        ByteBuffer buff = ByteBuffer.allocate(1024);
+        writeDimensionEncoding(enc, buff);
+        buff.flip();
+        DimensionEncoding dimensionEncoding = readDimensionEncoding(buff);
+        Assert.assertEquals(3, 
dimensionEncoding.asDataTypeSerializer().peekLength(null));
+    }
+}
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..1d7e3c983e 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
@@ -40,7 +40,7 @@
  * <p>
  * 1. "FFFF" will become null encode and decode
  * 2. "AB" will become "AB00"
- * 
+ *
  * <p>
  * Due to these limitations hex representation of hash values(with no padding, 
better with even characters) is more suitable
  */
@@ -166,7 +166,7 @@ public void encode(String valueStr, byte[] output, int 
outputOffset) {
         byte[] value = Bytes.toBytes(valueStr);
         int valueLen = value.length;
         int endOffset = outputOffset + bytelen;
-        
+
         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);
@@ -274,11 +274,13 @@ public Object valueOf(String str) {
     @Override
     public void writeExternal(ObjectOutput out) throws IOException {
         out.writeShort(hexLength);
+        out.writeShort(bytelen);
     }
 
     @Override
     public void readExternal(ObjectInput in) throws IOException, 
ClassNotFoundException {
         hexLength = in.readShort();
+        bytelen = in.readShort();
     }
 
     private boolean isF(byte[] value, int offset, int length) {


 

----------------------------------------------------------------
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:
us...@infra.apache.org


> FixedLenHexDimEnc return a wrong code length leads to cut bytes error.
> ----------------------------------------------------------------------
>
>                 Key: KYLIN-3293
>                 URL: https://issues.apache.org/jira/browse/KYLIN-3293
>             Project: Kylin
>          Issue Type: Bug
>            Reporter: jiatao.tao
>            Assignee: jiatao.tao
>            Priority: Major
>
> FixedLenHexDimEnc lost its byteLen when deserializing, so in  
> GTRecord#loadColumnsFromColumnBlocks, the byte after cutting are wrong.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to