Skip to content

Commit b12a2a5

Browse files
committed
fix wrong value returned by the method
1 parent f264250 commit b12a2a5

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

java/vector/src/main/java/org/apache/arrow/vector/BitVector.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ public final void get(int index, NullableBitHolder holder) {
384384
* Get the number of bits set to 1
385385
* @return the number of bits set to 1
386386
*/
387+
@Override
387388
public final int getNullCount() {
388389
int count = 0;
389390
for (int i = 0; i < allocationSizeInBytes; ++i) {
@@ -392,7 +393,7 @@ public final int getNullCount() {
392393
// will have 32bits set to 1. Masking the MSB and then adding it back solves the issue.
393394
count += Integer.bitCount(byteValue & 0x7F) - (byteValue >> 7);
394395
}
395-
return count;
396+
return (allocationSizeInBytes * 8) - count;
396397
}
397398
}
398399

java/vector/src/test/java/org/apache/arrow/vector/TestValueVector.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public void testBitVector() {
301301
assertEquals(0, accessor.get(100));
302302
assertEquals(1, accessor.get(1022));
303303

304-
assertEquals(2, accessor.getNullCount());
304+
assertEquals(1022, accessor.getNullCount());
305305

306306
// test setting the same value twice
307307
m.set(0, 1);
@@ -318,21 +318,21 @@ public void testBitVector() {
318318
assertEquals(1, accessor.get(1));
319319

320320
// should not change
321-
assertEquals(2, accessor.getNullCount());
321+
assertEquals(1022, accessor.getNullCount());
322322

323323
// Ensure unallocated space returns 0
324324
assertEquals(0, accessor.get(3));
325325

326326
m.set(1, 0);
327327
m.set(1022, 0);
328328

329-
assertEquals(0, accessor.getNullCount());
329+
assertEquals(1024, accessor.getNullCount());
330330

331331
for (int i = 0; i < 1024; ++i) {
332332
m.set(i, 1);
333333
}
334334

335-
assertEquals(1024, accessor.getNullCount());
335+
assertEquals(0, accessor.getNullCount());
336336
}
337337
}
338338

0 commit comments

Comments
 (0)