Skip to content

Commit

Permalink
Promote has_nested_columns to cudf public API (#16131)
Browse files Browse the repository at this point in the history
The `has_nested_columns` functionality is used in numerous tests. It looks like it should be part of our stable public API.

Authors:
  - Robert Maynard (https://github.com/robertmaynard)

Approvers:
  - Muhammad Haseeb (https://github.com/mhaseeb123)
  - Yunsong Wang (https://github.com/PointKernel)

URL: #16131
  • Loading branch information
robertmaynard authored Jul 2, 2024
1 parent a4be7bd commit a1447c7
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 38 deletions.
12 changes: 6 additions & 6 deletions cpp/include/cudf/table/experimental/row_operators.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ using optional_dremel_view = thrust::optional<detail::dremel_device_view const>;
*
* @tparam has_nested_columns compile-time optimization for primitive types.
* This template parameter is to be used by the developer by querying
* `cudf::detail::has_nested_columns(input)`. `true` compiles operator
* `cudf::has_nested_columns(input)`. `true` compiles operator
* overloads for nested types, while `false` only compiles operator
* overloads for primitive types.
* @tparam Nullate A cudf::nullate type describing whether to check for nulls.
Expand Down Expand Up @@ -1014,7 +1014,7 @@ class self_comparator {
*
* @tparam has_nested_columns compile-time optimization for primitive types.
* This template parameter is to be used by the developer by querying
* `cudf::detail::has_nested_columns(input)`. `true` compiles operator
* `cudf::has_nested_columns(input)`. `true` compiles operator
* overloads for nested types, while `false` only compiles operator
* overloads for primitive types.
* @tparam Nullate A cudf::nullate type describing whether to check for nulls.
Expand Down Expand Up @@ -1186,7 +1186,7 @@ class two_table_comparator {
*
* @tparam has_nested_columns compile-time optimization for primitive types.
* This template parameter is to be used by the developer by querying
* `cudf::detail::has_nested_columns(input)`. `true` compiles operator
* `cudf::has_nested_columns(input)`. `true` compiles operator
* overloads for nested types, while `false` only compiles operator
* overloads for primitive types.
* @tparam Nullate A cudf::nullate type describing whether to check for nulls.
Expand Down Expand Up @@ -1326,7 +1326,7 @@ struct nan_equal_physical_equality_comparator {
*
* @tparam has_nested_columns compile-time optimization for primitive types.
* This template parameter is to be used by the developer by querying
* `cudf::detail::has_nested_columns(input)`. `true` compiles operator
* `cudf::has_nested_columns(input)`. `true` compiles operator
* overloads for nested types, while `false` only compiles operator
* overloads for primitive types.
* @tparam Nullate A cudf::nullate type describing whether to check for nulls.
Expand Down Expand Up @@ -1643,7 +1643,7 @@ class self_comparator {
*
* @tparam has_nested_columns compile-time optimization for primitive types.
* This template parameter is to be used by the developer by querying
* `cudf::detail::has_nested_columns(input)`. `true` compiles operator
* `cudf::has_nested_columns(input)`. `true` compiles operator
* overloads for nested types, while `false` only compiles operator
* overloads for primitive types.
* @tparam Nullate A cudf::nullate type describing whether to check for nulls.
Expand Down Expand Up @@ -1757,7 +1757,7 @@ class two_table_comparator {
*
* @tparam has_nested_columns compile-time optimization for primitive types.
* This template parameter is to be used by the developer by querying
* `cudf::detail::has_nested_columns(input)`. `true` compiles operator
* `cudf::has_nested_columns(input)`. `true` compiles operator
* overloads for nested types, while `false` only compiles operator
* overloads for primitive types.
* @tparam Nullate A cudf::nullate type describing whether to check for nulls.
Expand Down
19 changes: 16 additions & 3 deletions cpp/include/cudf/table/table_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <cudf/column/column_view.hpp>
#include <cudf/types.hpp>
#include <cudf/utilities/export.hpp>

#include <algorithm>
#include <vector>
Expand All @@ -32,7 +33,7 @@
* passed by value.
*/

namespace cudf {
namespace CUDF_EXPORT cudf {
namespace detail {
/**
* @brief Base class for a table of `ColumnView`s
Expand Down Expand Up @@ -123,7 +124,10 @@ class table_view_base {
* @param column_index The index of the desired column
* @return A reference to the desired column
*/
[[nodiscard]] ColumnView const& column(size_type column_index) const;
[[nodiscard]] ColumnView const& column(size_type column_index) const
{
return _columns.at(column_index);
}

/**
* @brief Returns the number of columns
Expand Down Expand Up @@ -174,8 +178,17 @@ class table_view_base {
* @return Whether nested columns exist in the input table
*/
bool has_nested_columns(table_view const& table);

} // namespace detail

/**
* @brief Determine if any nested columns exist in a given table.
*
* @param table The input table
* @return Whether nested columns exist in the input table
*/
bool has_nested_columns(table_view const& table);

/**
* @brief A set of cudf::column_view's of the same size.
*
Expand Down Expand Up @@ -374,4 +387,4 @@ extern template bool is_relationally_comparable<mutable_table_view>(mutable_tabl
mutable_table_view const& rhs);
// @endcond
} // namespace detail
} // namespace cudf
} // namespace CUDF_EXPORT cudf
9 changes: 2 additions & 7 deletions cpp/src/table/table_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ auto concatenate_column_views(std::vector<ViewType> const& views)
return concat_cols;
}

template <typename ColumnView>
ColumnView const& table_view_base<ColumnView>::column(size_type column_index) const
{
return _columns.at(column_index);
}

// Explicit instantiation for a table of `column_view`s
template class table_view_base<column_view>;

Expand Down Expand Up @@ -172,6 +166,7 @@ bool has_nested_columns(table_view const& table)
return std::any_of(
table.begin(), table.end(), [](column_view const& col) { return is_nested(col.type()); });
}

} // namespace detail

bool has_nested_columns(table_view const& table) { return detail::has_nested_columns(table); }
} // namespace cudf
36 changes: 17 additions & 19 deletions cpp/tests/table/experimental_row_operator_tests.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2023, NVIDIA CORPORATION.
* Copyright (c) 2022-2024, 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 @@ -109,15 +109,14 @@ TYPED_TEST(TypedTableViewTest, TestSortSameTableFromTwoTables)
auto const lhs = cudf::table_view{{col1}};
auto const empty_rhs = cudf::table_view{{col2}};

auto const stream = cudf::get_default_stream();
auto const test_sort = [stream](auto const& preprocessed,
auto const& input,
auto const& comparator,
auto const& expected) {
auto const order = sorted_order(
preprocessed, input.num_rows(), cudf::detail::has_nested_columns(input), comparator, stream);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected, order->view());
};
auto const stream = cudf::get_default_stream();
auto const test_sort =
[stream](
auto const& preprocessed, auto const& input, auto const& comparator, auto const& expected) {
auto const order = sorted_order(
preprocessed, input.num_rows(), cudf::has_nested_columns(input), comparator, stream);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected, order->view());
};

auto const test_sort_two_tables = [&](auto const& preprocessed_lhs,
auto const& preprocessed_empty_rhs) {
Expand Down Expand Up @@ -188,15 +187,14 @@ TYPED_TEST(TypedTableViewTest, TestSortSameTableFromTwoTablesWithListsOfStructs)
auto const lhs = cudf::table_view{{*col1}};
auto const empty_rhs = cudf::table_view{{*col2}};

auto const stream = cudf::get_default_stream();
auto const test_sort = [stream](auto const& preprocessed,
auto const& input,
auto const& comparator,
auto const& expected) {
auto const order = sorted_order(
preprocessed, input.num_rows(), cudf::detail::has_nested_columns(input), comparator, stream);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected, order->view());
};
auto const stream = cudf::get_default_stream();
auto const test_sort =
[stream](
auto const& preprocessed, auto const& input, auto const& comparator, auto const& expected) {
auto const order = sorted_order(
preprocessed, input.num_rows(), cudf::has_nested_columns(input), comparator, stream);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected, order->view());
};

auto const test_sort_two_tables = [&](auto const& preprocessed_lhs,
auto const& preprocessed_empty_rhs) {
Expand Down
4 changes: 2 additions & 2 deletions cpp/tests/table/row_operator_tests_utilities.cu
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ std::unique_ptr<cudf::column> two_table_comparison(cudf::table_view lhs,
auto output = cudf::make_numeric_column(
cudf::data_type(cudf::type_id::BOOL8), lhs.num_rows(), cudf::mask_state::UNALLOCATED);

if (cudf::detail::has_nested_columns(lhs) || cudf::detail::has_nested_columns(rhs)) {
if (cudf::has_nested_columns(lhs) || cudf::has_nested_columns(rhs)) {
thrust::transform(rmm::exec_policy(stream),
lhs_it,
lhs_it + lhs.num_rows(),
Expand Down Expand Up @@ -129,7 +129,7 @@ std::unique_ptr<cudf::column> two_table_equality(cudf::table_view lhs,
auto output = cudf::make_numeric_column(
cudf::data_type(cudf::type_id::BOOL8), lhs.num_rows(), cudf::mask_state::UNALLOCATED);

if (cudf::detail::has_nested_columns(lhs) or cudf::detail::has_nested_columns(rhs)) {
if (cudf::has_nested_columns(lhs) or cudf::has_nested_columns(rhs)) {
auto const equal_comparator =
table_comparator.equal_to<true>(cudf::nullate::NO{}, cudf::null_equality::EQUAL, comparator);

Expand Down
2 changes: 1 addition & 1 deletion cpp/tests/table/row_operator_tests_utilities2.cu
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ std::unique_ptr<cudf::column> self_comparison(cudf::table_view input,
auto output = cudf::make_numeric_column(
cudf::data_type(cudf::type_id::BOOL8), input.num_rows(), cudf::mask_state::UNALLOCATED);

if (cudf::detail::has_nested_columns(input)) {
if (cudf::has_nested_columns(input)) {
thrust::transform(rmm::exec_policy(stream),
thrust::make_counting_iterator(0),
thrust::make_counting_iterator(input.num_rows()),
Expand Down

0 comments on commit a1447c7

Please sign in to comment.