Skip to content

Commit

Permalink
Fix make_empty_scalar_like on list_type (#9759)
Browse files Browse the repository at this point in the history
Fixes #9758

In `make_empty_scalar_like`, we create list scalar with the list column itself, which is wrong. The correct way is with the child of list column.

Authors:
  - Alfred Xu (https://github.com/sperlingxx)

Approvers:
  - Nghia Truong (https://github.com/ttnghia)
  - Devavret Makkar (https://github.com/devavret)

URL: #9759
  • Loading branch information
sperlingxx authored Dec 2, 2021
1 parent 5491cc7 commit c10966c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions cpp/src/scalar/scalar_factories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <cudf/utilities/type_dispatcher.hpp>

#include <cudf/detail/copy.hpp>
#include <cudf/lists/lists_column_view.hpp>
#include <rmm/cuda_stream_view.hpp>

namespace cudf {
Expand Down Expand Up @@ -184,10 +185,12 @@ std::unique_ptr<scalar> make_empty_scalar_like(column_view const& column,
{
std::unique_ptr<scalar> result;
switch (column.type().id()) {
case type_id::LIST:
result = make_list_scalar(empty_like(column)->view(), stream, mr);
case type_id::LIST: {
auto const empty_child = empty_like(lists_column_view(column).child());
result = make_list_scalar(empty_child->view(), stream, mr);
result->set_valid_async(false, stream);
break;
}
case type_id::STRUCT:
// The input column must have at least 1 row to extract a scalar (row) from it.
result = detail::get_element(column, 0, stream, mr);
Expand Down
8 changes: 6 additions & 2 deletions cpp/tests/reductions/reduction_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1961,7 +1961,11 @@ struct ListReductionTest : public cudf::test::BaseFixture {
cudf::reduce(input_data, agg, cudf::data_type(cudf::type_id::LIST));
auto list_result = dynamic_cast<cudf::list_scalar*>(result.get());
EXPECT_EQ(is_valid, list_result->is_valid());
if (is_valid) { CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected_value, list_result->view()); }
if (is_valid) {
CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected_value, list_result->view());
} else {
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_value, list_result->view());
}
};

if (succeeded_condition) {
Expand Down Expand Up @@ -2047,7 +2051,7 @@ TEST_F(ListReductionTest, NonValidListReductionNthElement)

// test against empty input
this->reduction_test(LCW{},
ElementCol{{0}, {0}}, // expected_value,
ElementCol{}, // expected_value,
true,
false,
cudf::make_nth_element_aggregation(0, cudf::null_policy::INCLUDE));
Expand Down

0 comments on commit c10966c

Please sign in to comment.