From 089f02bccacff5d743a762d7bb1ce793ff072686 Mon Sep 17 00:00:00 2001 From: congqixia Date: Thu, 31 Jul 2025 09:55:36 +0800 Subject: [PATCH] fix: [StorageV2] Align null bitmap offset for fixed-length datatype (#43654) Related to #43626 Similar to previous pr #43321, null bitmap could be dislocated if the bitset ptr does not count the offset of array Signed-off-by: Congqi Xia --- internal/core/src/common/ChunkWriter.h | 30 +++++++++++--------------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/internal/core/src/common/ChunkWriter.h b/internal/core/src/common/ChunkWriter.h index eab141b7db..b5adb3889b 100644 --- a/internal/core/src/common/ChunkWriter.h +++ b/internal/core/src/common/ChunkWriter.h @@ -98,7 +98,7 @@ class ChunkWriter final : public ChunkWriterBase { } ChunkWriter(int dim, std::string file_path, bool nullable) - : ChunkWriterBase(std::move(file_path), nullable), dim_(dim) {}; + : ChunkWriterBase(std::move(file_path), nullable), dim_(dim){}; void write(const arrow::ArrayVector& array_vec) override { @@ -126,16 +126,14 @@ class ChunkWriter final : public ChunkWriterBase { // 2. Data values: Contiguous storage of data elements in the order: // data1, data2, ..., dataN where each data element has size dim_*sizeof(T) if (nullable_) { + // tuple + std::vector> + null_bitmaps; for (const auto& data : array_vec) { - auto null_bitmap = data->null_bitmap_data(); - auto null_bitmap_n = (data->length() + 7) / 8; - if (null_bitmap) { - target_->write(null_bitmap, null_bitmap_n); - } else { - std::vector null_bitmap(null_bitmap_n, 0xff); - target_->write(null_bitmap.data(), null_bitmap_n); - } + null_bitmaps.emplace_back( + data->null_bitmap_data(), data->length(), data->offset()); } + write_null_bit_maps(null_bitmaps); } for (const auto& data : array_vec) { @@ -183,17 +181,13 @@ ChunkWriter::write( } if (nullable_) { - // chunk layout: nullbitmap, data1, data2, ..., datan + // tuple + std::vector> null_bitmaps; for (const auto& data : array_vec) { - auto null_bitmap = data->null_bitmap_data(); - auto null_bitmap_n = (data->length() + 7) / 8; - if (null_bitmap) { - target_->write(null_bitmap, null_bitmap_n); - } else { - std::vector null_bitmap(null_bitmap_n, 0xff); - target_->write(null_bitmap.data(), null_bitmap_n); - } + null_bitmaps.emplace_back( + data->null_bitmap_data(), data->length(), data->offset()); } + write_null_bit_maps(null_bitmaps); } for (const auto& data : array_vec) {