Skip to content

Commit

Permalink
debug cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mapleFU committed Sep 3, 2024
1 parent 4d005c2 commit e3f2efa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
33 changes: 25 additions & 8 deletions cpp/src/arrow/compute/row/row_encoder_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -331,17 +331,25 @@ void RowEncoder::Init(const std::vector<TypeHolder>& column_types, ExecContext*
void RowEncoder::Clear() {
offsets_.clear();
bytes_.clear();
fixed_with_row_count_ = 0;
}

Status RowEncoder::EncodeAndAppendForFixedWidth(const ExecSpan& batch) {
size_t length_before =
static_cast<size_t>(this->fixed_width_length_) * this->fixed_with_row_count_;
ARROW_CHECK_EQ(length_before, bytes_.size());
#ifndef NDEBUG
int32_t accum_length = 0;
for (int i = 0; i < batch.num_values(); ++i) {
encoders_[i]->AddLength(batch[i], batch.length, &accum_length);
{
int32_t accum_length = 0;
std::vector<int32_t> lengthes(batch.length, 0);
for (int i = 0; i < batch.num_values(); ++i) {
encoders_[i]->AddLength(batch[i], batch.length, lengthes.data());
}
for (int i = 0; i < batch.length; ++i) {
accum_length += lengthes[i];
}
ARROW_CHECK_EQ(accum_length, this->fixed_width_length_ * batch.length);
}
ARROW_DCHECK_EQ(accum_length, this->fixed_width_length_ * batch.length);
#endif
bytes_.resize(length_before + batch.length * this->fixed_width_length_);
std::vector<uint8_t*> buf_ptrs(batch.length);
Expand All @@ -356,7 +364,7 @@ Status RowEncoder::EncodeAndAppendForFixedWidth(const ExecSpan& batch) {
}

Status RowEncoder::EncodeAndAppend(const ExecSpan& batch) {
if (fixed_width_length_ != kInvalidFixedWidthOffset) {
if (IsFixedWidth()) {
return EncodeAndAppendForFixedWidth(batch);
}
if (offsets_.empty()) {
Expand Down Expand Up @@ -396,9 +404,18 @@ Result<ExecBatch> RowEncoder::Decode(int64_t num_rows, const int32_t* row_ids) {
ExecBatch out({}, num_rows);

std::vector<uint8_t*> buf_ptrs(num_rows);
for (int64_t i = 0; i < num_rows; ++i) {
buf_ptrs[i] = (row_ids[i] == kRowIdForNulls()) ? encoded_nulls_.data()
: bytes_.data() + offsets_[row_ids[i]];
if (IsFixedWidth()) {
for (int64_t i = 0; i < num_rows; ++i) {
buf_ptrs[i] = (row_ids[i] == kRowIdForNulls())
? encoded_nulls_.data()
: bytes_.data() + fixed_width_length_ * row_ids[i];
}
} else {
for (int64_t i = 0; i < num_rows; ++i) {
buf_ptrs[i] = (row_ids[i] == kRowIdForNulls())
? encoded_nulls_.data()
: bytes_.data() + offsets_[row_ids[i]];
}
}

out.values.resize(encoders_.size());
Expand Down
9 changes: 6 additions & 3 deletions cpp/src/arrow/compute/row/row_encoder_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ class ARROW_EXPORT RowEncoder {
}
int32_t row_length = 0;
int32_t row_offset = 0;
if (fixed_width_length_ != kInvalidFixedWidthOffset) {
if (IsFixedWidth()) {
row_length = fixed_width_length_;
row_offset = fixed_with_row_count_ * i * fixed_width_length_;
row_offset = i * fixed_width_length_;
} else {
row_length = offsets_[i + 1] - offsets_[i];
row_offset = offsets_[i];
Expand All @@ -387,14 +387,17 @@ class ARROW_EXPORT RowEncoder {
}

int32_t num_rows() const {
if (kInvalidFixedWidthOffset == fixed_width_length_) {
if (IsFixedWidth()) {
return fixed_with_row_count_;
}
return offsets_.empty() ? 0 : offsets_[0];
}

private:
Status EncodeAndAppendForFixedWidth(const ExecSpan& batch);
bool IsFixedWidth() const noexcept {
return fixed_width_length_ != kInvalidFixedWidthOffset;
}

private:
static constexpr int32_t kInvalidFixedWidthOffset = 1;
Expand Down

0 comments on commit e3f2efa

Please sign in to comment.