Skip to content

Commit 56d64ef

Browse files
shiyuhang0marsishandsomezz-jason
authored
[fix #537] fix convert byte[] to long error (#538)
Co-authored-by: Liangliang Gu <marsishandsome@gmail.com> Co-authored-by: Jian Zhang <zjsariel@gmail.com>
1 parent ef16787 commit 56d64ef

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/main/java/org/tikv/common/columnar/TiChunkColumnVector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ private long getLongFromBinary(int rowId) {
178178
if (bytes.length == 0) return 0;
179179
long result = 0;
180180
for (byte b : bytes) {
181-
result = (result << 8) | b;
181+
result = (result << 8) | (b & 0xff);
182182
}
183183
return result;
184184
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2022 TiKV Project Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.tikv.common.columnar;
19+
20+
import java.nio.ByteBuffer;
21+
import junit.framework.TestCase;
22+
import org.junit.Assert;
23+
import org.junit.Test;
24+
import org.tikv.common.types.BitType;
25+
26+
public class TiChunkColumnVectorTest extends TestCase {
27+
28+
@Test
29+
public void testGetLong() {
30+
long expect = 32767;
31+
ByteBuffer buffer = ByteBuffer.allocate(8);
32+
buffer.putLong(expect);
33+
TiChunkColumnVector tiChunkColumnVector =
34+
new TiChunkColumnVector(BitType.BIT, -1, 1, 0, new byte[] {-1}, new long[] {0, 8}, buffer);
35+
Assert.assertEquals(expect, tiChunkColumnVector.getLong(0));
36+
}
37+
}

0 commit comments

Comments
 (0)