Skip to content

Commit

Permalink
Prevent creation of sparse map for empty typed columns
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasil Pashov committed Feb 15, 2024
1 parent 0d0c31e commit 5684779
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions cpp/arcticdb/codec/codec-inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ std::size_t decode_ndarray(
}

if(field.sparse_map_bytes()) {
util::check(!is_empty_type(type_desc_tag.data_type()), "Empty typed columns should not have sparse map");
util::check_magic<util::BitMagicStart>(data_in);
const auto bitmap_size = field.sparse_map_bytes() - util::combined_bit_magic_delimiters_size();
bv = util::deserialize_bytes_to_bitmap(data_in, bitmap_size);
Expand Down
3 changes: 2 additions & 1 deletion cpp/arcticdb/codec/codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,8 @@ void encode_sparse_map(
Buffer& out,
std::ptrdiff_t& pos
) {
if (column_data.bit_vector() != nullptr && column_data.bit_vector()->count() > 0) {
if (column_data.bit_vector() != nullptr && column_data.bit_vector()->count() > 0) {
util::check(!is_empty_type(column_data.type().data_type()), "Empty typed columns should not have sparse maps");
ARCTICDB_DEBUG(log::codec(), "Sparse map count = {} pos = {}", column_data.bit_vector()->count(), pos);
const size_t sparse_bm_bytes = encode_bitmap(*column_data.bit_vector(), out, pos);
util::variant_match(variant_field, [&](auto field) {
Expand Down
8 changes: 4 additions & 4 deletions cpp/arcticdb/column_store/column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ void Column::default_initialize_rows(size_t start_pos, size_t num_rows, bool ens
}

void Column::set_row_data(size_t row_id) {
if (is_empty_type(type_.data_type())) {
return;
}
last_logical_row_ = row_id;
const auto last_stored_row = row_count() - 1;
if(sparse_map_) {
Expand Down Expand Up @@ -592,10 +595,7 @@ std::shared_ptr<Column> Column::truncate(const std::shared_ptr<Column>& column,
auto buffer = ::arcticdb::truncate(column->data_.buffer(), start_byte, end_byte);
auto res = std::make_shared<Column>(column->type(), column->allow_sparse_, std::move(buffer));
if (column->is_sparse()) {
util::BitMagic output_sparse_map = is_empty_type(column->type().data_type())
? util::BitMagic{}
: truncate_sparse_map(column->sparse_map(), start_row, end_row);
res->set_sparse_map(std::move(output_sparse_map));
res->set_sparse_map(truncate_sparse_map(column->sparse_map(), start_row, end_row));
}
res->set_row_data(end_row - (start_row + 1));
return res;
Expand Down

0 comments on commit 5684779

Please sign in to comment.