Skip to content

Commit

Permalink
ARROW-2567: [C++] Not only compare type ids on Array equality
Browse files Browse the repository at this point in the history
Author: Korn, Uwe <[email protected]>

Closes apache#2025 from xhochy/ARROW-2567 and squashes the following commits:

2db252a <Korn, Uwe> ARROW-2567:  Not only compare type ids on Array equality
  • Loading branch information
xhochy committed May 12, 2018
1 parent e1c3d4b commit 321773c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cpp/src/arrow/array-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ TEST_F(TestArray, TestEquality) {
EXPECT_FALSE(array->RangeEquals(0, 4, 0, unequal_array));
EXPECT_FALSE(array->RangeEquals(0, 8, 0, unequal_array));
EXPECT_FALSE(array->RangeEquals(1, 2, 1, unequal_array));

auto timestamp_ns_array = std::make_shared<NumericArray<TimestampType>>(
timestamp(TimeUnit::NANO), array->length(), array->data()->buffers[1],
array->data()->buffers[0], array->null_count());
auto timestamp_us_array = std::make_shared<NumericArray<TimestampType>>(
timestamp(TimeUnit::MICRO), array->length(), array->data()->buffers[1],
array->data()->buffers[0], array->null_count());
ASSERT_FALSE(array->Equals(timestamp_ns_array));
// ARROW-2567: Ensure that not only the type id but also the type equality
// itself is checked.
ASSERT_FALSE(timestamp_us_array->Equals(timestamp_ns_array));
}

TEST_F(TestArray, TestNullArrayEquality) {
Expand Down
5 changes: 5 additions & 0 deletions cpp/src/arrow/compare.cc
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,11 @@ static bool BaseDataEquals(const Array& left, const Array& right) {
left.type_id() != right.type_id()) {
return false;
}
// ARROW-2567: Ensure that not only the type id but also the type equality
// itself is checked.
if (!TypeEquals(*left.type(), *right.type())) {
return false;
}
if (left.null_count() > 0 && left.null_count() < left.length()) {
return BitmapEquals(left.null_bitmap()->data(), left.offset(),
right.null_bitmap()->data(), right.offset(), left.length());
Expand Down

0 comments on commit 321773c

Please sign in to comment.