Skip to content

Commit

Permalink
Fix NullMask setNullRange (#3267)
Browse files Browse the repository at this point in the history
* fix null set range

* add test
  • Loading branch information
ray6080 committed Apr 15, 2024
1 parent 3600a93 commit d7bdcbf
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/common/null_mask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,17 @@ void NullMask::setNullRange(uint64_t* nullEntries, uint64_t offset, uint64_t num
} else {
if (isNull) {
// Set bits including and after the first bit pos to true
nullEntries[firstEntryPos] |= ~NULL_HIGH_MASKS[firstBitPos];
nullEntries[firstEntryPos] |= ~NULL_LOWER_MASKS[firstBitPos];
if (lastBitPos > 0) {
// Set bits before the last bit pos to true
nullEntries[lastEntryPos] |=
~NULL_LOWER_MASKS[NUM_BITS_PER_NULL_ENTRY - lastBitPos];
nullEntries[lastEntryPos] |= NULL_LOWER_MASKS[lastBitPos];
}
} else {
// Set bits including and after the first bit pos to false
nullEntries[firstEntryPos] &= NULL_LOWER_MASKS[firstBitPos];
if (lastBitPos > 0) {
// Set bits before the last bit pos to false
nullEntries[lastEntryPos] &= NULL_HIGH_MASKS[NUM_BITS_PER_NULL_ENTRY - lastBitPos];
nullEntries[lastEntryPos] &= ~NULL_LOWER_MASKS[lastBitPos];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/storage/compression/compression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ bool CompressionMetadata::canUpdateInPlace(const uint8_t* data, uint32_t pos,
case PhysicalTypeID::BOOL: {
return NullMask::isNull(reinterpret_cast<const uint64_t*>(data), pos) ==
*reinterpret_cast<const bool*>(this->data.data());
} break;
}
default: {
auto size = getDataTypeSizeInChunk(physicalType);
return memcmp(data + pos * size, this->data.data(), size) == 0;
Expand Down
2 changes: 0 additions & 2 deletions src/storage/store/dictionary_chunk.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "storage/store/dictionary_chunk.h"

#include <cstdint>

#include <bit>

using namespace kuzu::common;
Expand Down
15 changes: 14 additions & 1 deletion test/common/null_mask_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,29 @@ TEST(NullMaskTests, TestRangeSingleEntry) {
ASSERT_EQ(data[0], ~0b1111100000);
}

TEST(NullMaskTests, TestRangeMultipleEntries) {
TEST(NullMaskTests, TestRangeMultipleEntries1) {
std::vector<uint64_t> data{NullMask::ALL_NULL_ENTRY, NullMask::ALL_NULL_ENTRY,
NullMask::ALL_NULL_ENTRY};
NullMask::setNullRange(data.data(), 5, 150, false);
ASSERT_EQ(data[0], 0b11111);
ASSERT_EQ(data[1], 0);
ASSERT_NE(data[2], 0);
ASSERT_TRUE(NullMask::isNull(data.data(), 4));
ASSERT_FALSE(NullMask::isNull(data.data(), 5));
ASSERT_FALSE(NullMask::isNull(data.data(), 154));
ASSERT_TRUE(NullMask::isNull(data.data(), 155));
}

TEST(NullMaskTests, TestRangeMultipleEntries2) {
std::vector<uint64_t> data{NullMask::NO_NULL_ENTRY, NullMask::NO_NULL_ENTRY,
NullMask::NO_NULL_ENTRY};
NullMask::setNullRange(data.data(), 5, 150, true);
ASSERT_FALSE(NullMask::isNull(data.data(), 4));
ASSERT_TRUE(NullMask::isNull(data.data(), 5));
ASSERT_TRUE(NullMask::isNull(data.data(), 154));
ASSERT_FALSE(NullMask::isNull(data.data(), 155));
}

TEST(NullMaskTests, CopyNullMaskAll) {
const int size = 10;
std::vector<uint64_t> source(size);
Expand Down
9 changes: 9 additions & 0 deletions test/test_files/update_node/create_empty.test
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,12 @@ bar
---- 2
8fffffff-ffff-ffff-ffff-ffffffffffff
a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a12

-CASE CreateBatch
-STATEMENT CREATE NODE TABLE test(id INT64, age INT64, PRIMARY KEY(id));
---- ok
-STATEMENT UNWIND RANGE(1,100) AS id CREATE (t:test {id:id});
---- ok
-STATEMENT MATCH (t:test) WHERE t.age IS NOT NULL RETURN COUNT(*);
---- 1
0

0 comments on commit d7bdcbf

Please sign in to comment.