Skip to content

Commit

Permalink
Improve test coverage for struct search (#8396)
Browse files Browse the repository at this point in the history
This PR adds a simple test case for struct binary search. In this test, we do binary search for 2 structs columns in which one column has a bit mask (but no null element) while the other column does not have any bit mask.

Reference: #8374 | #8187

Authors:
  - Nghia Truong (https://github.com/ttnghia)

Approvers:
  - Conor Hoekstra (https://github.com/codereport)

URL: #8396
  • Loading branch information
ttnghia authored Jun 3, 2021
1 parent 7e2a76b commit c2ec012
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions cpp/tests/search/search_struct_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,45 @@ TYPED_TEST(TypedStructSearchTest, SimpleInputWithTargetHavingNullsTests)
CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected_upper_bound, results.second->view(), print_all);
}

TYPED_TEST(TypedStructSearchTest, OneColumnHasNullMaskButNoNullElementTest)
{
using col_wrapper = cudf::test::fixed_width_column_wrapper<TypeParam, int32_t>;

auto child_col1 = col_wrapper{1, 20, 30};
auto const structs_col1 = structs_col{{child_col1}}.release();

auto child_col2 = col_wrapper{0, 10, 10};
auto const structs_col2 = structs_col{child_col2}.release();

// structs_col3 (and its child column) will have a null mask but no null element
auto child_col3 = col_wrapper{{0, 10, 10}, cudf::test::iterator_no_null()};
auto const structs_col3 = structs_col{{child_col3}, cudf::test::iterator_no_null()}.release();

// Search struct elements of structs_col2 and structs_col3 in the column structs_col1
{
auto const results1 = search_bounds(structs_col1, structs_col2);
auto const results2 = search_bounds(structs_col1, structs_col3);
auto const expected_lower_bound = int32s_col{0, 1, 1};
auto const expected_upper_bound = int32s_col{0, 1, 1};
CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected_lower_bound, results1.first->view(), print_all);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected_lower_bound, results2.first->view(), print_all);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected_upper_bound, results1.second->view(), print_all);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected_upper_bound, results2.second->view(), print_all);
}

// Search struct elements of structs_col1 in the columns structs_col2 and structs_col3
{
auto const results1 = search_bounds(structs_col2, structs_col1);
auto const results2 = search_bounds(structs_col3, structs_col1);
auto const expected_lower_bound = int32s_col{1, 3, 3};
auto const expected_upper_bound = int32s_col{1, 3, 3};
CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected_lower_bound, results1.first->view(), print_all);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected_lower_bound, results2.first->view(), print_all);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected_upper_bound, results1.second->view(), print_all);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected_upper_bound, results2.second->view(), print_all);
}
}

TYPED_TEST(TypedStructSearchTest, ComplexStructTest)
{
// Testing on struct<string, numeric, bool>.
Expand Down

0 comments on commit c2ec012

Please sign in to comment.