diff --git a/src/main/java/org/tikv/common/columnar/TiChunkColumnVector.java b/src/main/java/org/tikv/common/columnar/TiChunkColumnVector.java index 2ffa102853..96e0b5c68a 100644 --- a/src/main/java/org/tikv/common/columnar/TiChunkColumnVector.java +++ b/src/main/java/org/tikv/common/columnar/TiChunkColumnVector.java @@ -178,7 +178,7 @@ public class TiChunkColumnVector extends TiColumnVector { if (bytes.length == 0) return 0; long result = 0; for (byte b : bytes) { - result = (result << 8) | b; + result = (result << 8) | (b & 0xff); } return result; } diff --git a/src/test/java/org/tikv/common/columnar/TiChunkColumnVectorTest.java b/src/test/java/org/tikv/common/columnar/TiChunkColumnVectorTest.java new file mode 100644 index 0000000000..376ea25313 --- /dev/null +++ b/src/test/java/org/tikv/common/columnar/TiChunkColumnVectorTest.java @@ -0,0 +1,37 @@ +/* + * Copyright 2022 TiKV Project Authors. + * + * Licensed 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.tikv.common.columnar; + +import java.nio.ByteBuffer; +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Test; +import org.tikv.common.types.BitType; + +public class TiChunkColumnVectorTest extends TestCase { + + @Test + public void testGetLong() { + long expect = 32767; + ByteBuffer buffer = ByteBuffer.allocate(8); + buffer.putLong(expect); + TiChunkColumnVector tiChunkColumnVector = + new TiChunkColumnVector(BitType.BIT, -1, 1, 0, new byte[] {-1}, new long[] {0, 8}, buffer); + Assert.assertEquals(expect, tiChunkColumnVector.getLong(0)); + } +}