Skip to content

Commit

Permalink
ListViewArray: Implement Compare + (TODO: tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecrv committed Apr 28, 2023
1 parent 65c11f8 commit 5b0944c
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion cpp/src/arrow/compare.cc
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,40 @@ class RangeDataEqualsImpl {
}

Status Visit(const ListViewType& type) {
return Status::NotImplemented("comparing ListViewType");
// Sizes are required to be identical for full equality, so we test them first
const auto* left_sizes = left_.GetValues<int32_t>(2);
const auto* right_sizes = right_.GetValues<int32_t>(2);
auto compare_sizes = [&](int64_t i, int64_t length) -> bool {
return memcmp(left_sizes + left_start_idx_ + i, right_sizes + right_start_idx_ + i,
length * sizeof(int32_t)) == 0;
};
VisitValidRuns(std::move(compare_sizes));
if (!result_) {
return Status::OK();
}

// All sizes match, now compare the valid list views
const auto* left_offsets = left_.GetValues<int32_t>(1);
const auto* right_offsets = right_.GetValues<int32_t>(1);
const ArrayData& left_values = *left_.child_data[0];
const ArrayData& right_values = *right_.child_data[0];
auto compare_view = [&](int64_t i, int64_t length) -> bool {
for (int64_t j = i; j < i + length; ++j) {
const int32_t left_offset = left_offsets[left_start_idx_ + j];
const int32_t right_offset = right_offsets[right_start_idx_ + j];
const int32_t size = left_sizes[left_start_idx_ + j];
RangeDataEqualsImpl impl(options_, floating_approximate_, left_values,
right_values,
left_start_idx_ + left_.offset + left_offset,
right_start_idx_ + right_.offset + right_offset, size);
if (!impl.Compare()) {
return false;
}
}
return true;
};
VisitValidRuns(compare_view);
return Status::OK();
}

Status Visit(const ExtensionType& type) {
Expand Down

0 comments on commit 5b0944c

Please sign in to comment.