[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>
This commit is contained in:
shiyuhang0 2022-03-29 14:28:02 +08:00 committed by GitHub
parent ef1678724f
commit 56d64ef5c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 1 deletions

View File

@ -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;
}

View File

@ -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));
}
}