Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null check when comparing structs in min and max reduction/groupby operations #9994

Merged
merged 3 commits into from Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions cpp/src/reductions/struct_minmax_util.cuh
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, NVIDIA CORPORATION.
* Copyright (c) 2022, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,6 +23,7 @@
#include <cudf/detail/utilities/vector_factories.hpp>
#include <cudf/table/row_operators.cuh>
#include <cudf/table/table_device_view.cuh>
#include <cudf/table/table_view.hpp>

namespace cudf {
namespace reduction {
Expand Down Expand Up @@ -97,7 +98,7 @@ class comparison_binop_generator {
table_view{{input}}, {}, std::vector<null_order>{DEFAULT_NULL_ORDER})},
d_flattened_input_ptr{table_device_view::create(flattened_input, stream)},
is_min_op(is_min_op),
has_nulls{input.has_nulls()},
has_nulls{has_nested_nulls(table_view{{input}})},
ttnghia marked this conversation as resolved.
Show resolved Hide resolved
null_orders_dvec(0, stream)
{
if (is_min_op) {
Expand Down
23 changes: 22 additions & 1 deletion cpp/tests/groupby/max_tests.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2021, NVIDIA CORPORATION.
* Copyright (c) 2019-2022, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -388,5 +388,26 @@ TEST_F(groupby_max_struct_test, null_keys_and_values)
test_single_agg(keys, vals, expect_keys, expect_vals, std::move(agg));
}

TEST_F(groupby_max_struct_test, values_with_null_child)
{
constexpr int32_t null{0};
auto const keys = fixed_width_column_wrapper<int32_t>{1, 1};
auto const vals = [] {
auto child1 = fixed_width_column_wrapper<int32_t>{1, 1};
auto child2 = fixed_width_column_wrapper<int32_t>{{-1, null}, null_at(1)};
return structs_column_wrapper{child1, child2};
}();

auto const expect_keys = fixed_width_column_wrapper<int32_t>{1};
auto const expect_vals = [] {
auto child1 = fixed_width_column_wrapper<int32_t>{1};
auto child2 = fixed_width_column_wrapper<int32_t>{-1};
return structs_column_wrapper{child1, child2};
}();

auto agg = cudf::make_max_aggregation<groupby_aggregation>();
test_single_agg(keys, vals, expect_keys, expect_vals, std::move(agg));
}

} // namespace test
} // namespace cudf
23 changes: 22 additions & 1 deletion cpp/tests/groupby/min_tests.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2021, NVIDIA CORPORATION.
* Copyright (c) 2019-2022, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -387,5 +387,26 @@ TEST_F(groupby_min_struct_test, null_keys_and_values)
test_single_agg(keys, vals, expect_keys, expect_vals, std::move(agg));
}

TEST_F(groupby_min_struct_test, values_with_null_child)
{
constexpr int32_t null{0};
auto const keys = fixed_width_column_wrapper<int32_t>{1, 1};
auto const vals = [] {
auto child1 = fixed_width_column_wrapper<int32_t>{1, 1};
auto child2 = fixed_width_column_wrapper<int32_t>{{-1, null}, null_at(1)};
return structs_column_wrapper{child1, child2};
}();

auto const expect_keys = fixed_width_column_wrapper<int32_t>{1};
auto const expect_vals = [] {
auto child1 = fixed_width_column_wrapper<int32_t>{1};
auto child2 = fixed_width_column_wrapper<int32_t>{{null}, null_at(0)};
return structs_column_wrapper{child1, child2};
}();

auto agg = cudf::make_min_aggregation<groupby_aggregation>();
test_single_agg(keys, vals, expect_keys, expect_vals, std::move(agg));
}

} // namespace test
} // namespace cudf