Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zanmato1984 committed Jul 25, 2024
1 parent 674e221 commit 75b8fee
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
6 changes: 5 additions & 1 deletion cpp/src/arrow/compute/row/row_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,12 @@ Status RowTableImpl::ResizeFixedLengthBuffers(int64_t num_extra_rows) {
}

Status RowTableImpl::ResizeOptionalVaryingLengthBuffer(int64_t num_extra_bytes) {
if (metadata_.is_fixed_length) {
return Status::OK();
}

int64_t num_bytes = offsets()[num_rows_];
if (bytes_capacity_ >= num_bytes + num_extra_bytes || metadata_.is_fixed_length) {
if (bytes_capacity_ >= num_bytes + num_extra_bytes) {
return Status::OK();
}

Expand Down
49 changes: 29 additions & 20 deletions cpp/src/arrow/compute/row/row_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,34 +69,43 @@ TEST(RowTableMemoryConsumption, Encode) {
constexpr int64_t num_rows_max = 8192;
constexpr int64_t padding_for_vectors = 64;

ASSERT_OK_AND_ASSIGN(
auto fixed_length_column,
::arrow::gen::Constant(std::make_shared<UInt32Scalar>(0))->Generate(num_rows_max));
std::vector<std::shared_ptr<Array>> fixed_length_columns;
for (const auto& dt : {int8(), uint16(), int32(), uint64(), fixed_size_binary(16),
fixed_size_binary(32)}) {
ASSERT_OK_AND_ASSIGN(auto fixed_length_column,
::arrow::gen::Random(dt)->Generate(num_rows_max));
fixed_length_columns.push_back(std::move(fixed_length_column));
}

ASSERT_OK_AND_ASSIGN(auto var_length_column,
::arrow::gen::Constant(std::make_shared<BinaryScalar>("X"))
->Generate(num_rows_max));

for (int64_t num_rows : {1023, 1024, 1025, 4095, 4096, 4097}) {
for (int64_t num_rows : {1024, 1025, 4095, 4096, 4097}) {
// Fixed length column.
{
SCOPED_TRACE("encoding fixed length column of " + std::to_string(num_rows) +
" rows");
ASSERT_OK_AND_ASSIGN(auto row_table,
MakeRowTableFromColumn(fixed_length_column, num_rows,
uint32()->byte_width(), 0));
ASSERT_NE(row_table.data(0), NULLPTR);
ASSERT_NE(row_table.data(1), NULLPTR);
ASSERT_EQ(row_table.data(2), NULLPTR);

int64_t actual_null_mask_size =
num_rows * row_table.metadata().null_masks_bytes_per_row;
ASSERT_LE(actual_null_mask_size, row_table.buffer_size(0) - padding_for_vectors);
ASSERT_GT(actual_null_mask_size * 2,
row_table.buffer_size(0) - padding_for_vectors);

int64_t actual_rows_size = num_rows * uint32()->byte_width();
ASSERT_LE(actual_rows_size, row_table.buffer_size(1) - padding_for_vectors);
ASSERT_GT(actual_rows_size * 2, row_table.buffer_size(1) - padding_for_vectors);
for (const auto& col : fixed_length_columns) {
const auto& dt = col->type();
SCOPED_TRACE("encoding fixed length column of type " + dt->ToString());
ASSERT_OK_AND_ASSIGN(auto row_table,
MakeRowTableFromColumn(col, num_rows, dt->byte_width(),
/*string_alignment=*/0));
ASSERT_NE(row_table.data(0), NULLPTR);
ASSERT_NE(row_table.data(1), NULLPTR);
ASSERT_EQ(row_table.data(2), NULLPTR);

int64_t actual_null_mask_size =
num_rows * row_table.metadata().null_masks_bytes_per_row;
ASSERT_LE(actual_null_mask_size, row_table.buffer_size(0) - padding_for_vectors);
ASSERT_GT(actual_null_mask_size * 2,
row_table.buffer_size(0) - padding_for_vectors);

int64_t actual_rows_size = num_rows * dt->byte_width();
ASSERT_LE(actual_rows_size, row_table.buffer_size(1) - padding_for_vectors);
ASSERT_GT(actual_rows_size * 2, row_table.buffer_size(1) - padding_for_vectors);
}
}

// Var length column.
Expand Down

0 comments on commit 75b8fee

Please sign in to comment.