Skip to content

Commit

Permalink
ListViewType: Implement type Compare + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecrv committed Apr 26, 2023
1 parent db662bc commit 6ae5d3b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cpp/src/arrow/compare.cc
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,9 @@ class TypeEqualsVisitor {
}

Status Visit(const ListViewType& left) {
return Status::NotImplemented("list-view type comparison");
const auto& right = checked_cast<const ListViewType&>(right_);
result_ = left.value_type()->Equals(right.value_type());
return Status::OK();
}

Status Visit(const ExtensionType& left) {
Expand Down
19 changes: 19 additions & 0 deletions cpp/src/arrow/type_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2219,6 +2219,25 @@ TEST(TypesTest, TestRunEndEncodedType) {
"run_end_encoded<run_ends: int64, values: list<item: int32>>");
}

TEST(TypesTest, TestListViewType) {
auto int32_expected = std::make_shared<ListViewType>(int32());
auto int32_list_view_type = list_view(int32());

ASSERT_EQ(*int32_expected, *int32_list_view_type);

auto int32_list_view_type_cast =
std::dynamic_pointer_cast<ListViewType>(int32_list_view_type);
ASSERT_EQ(*int32_list_view_type_cast->value_type(), *int32());

ASSERT_TRUE(int32_list_view_type->field(0)->Equals(Field("values", int32(), true)));

auto int64_list_view_type = list_view(int64());
ASSERT_NE(*int32_list_view_type, *int64_list_view_type);

ASSERT_EQ(int32_list_view_type->ToString(), "list_view<values: int32>");
ASSERT_EQ(int64_list_view_type->ToString(), "list_view<values: int64>");
}

#define TEST_PREDICATE(all_types, type_predicate) \
for (auto type : all_types) { \
ASSERT_EQ(type_predicate(type->id()), type_predicate(*type)); \
Expand Down

0 comments on commit 6ae5d3b

Please sign in to comment.