Skip to content

Commit

Permalink
Promote has_nested_columns to cudf public API
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmaynard committed Jun 13, 2024
1 parent 9e8e074 commit 9845334
Show file tree
Hide file tree
Showing 26 changed files with 53 additions and 59 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
21 changes: 17 additions & 4 deletions cpp/include/cudf/table/table_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/

namespace CUDF_EXPORT cudf {
namespace detail {
namespace CUDF_HIDDEN detail {
/**
* @brief Base class for a table of `ColumnView`s
*
Expand Down Expand Up @@ -78,7 +78,17 @@ class table_view_base {
*
* @param cols The vector of columns to construct the table from
*/
explicit table_view_base(std::vector<ColumnView> const& cols);
explicit table_view_base(std::vector<ColumnView> const& cols) : _columns{cols}
{
if (num_columns() > 0) {
std::for_each(_columns.begin(), _columns.end(), [this](ColumnView col) {
CUDF_EXPECTS(col.size() == _columns.front().size(), "Column size mismatch.");
});
_num_rows = _columns.front().size();
} else {
_num_rows = 0;
}
}

/**
* @brief Returns an iterator to the first view in the `table`.
Expand Down Expand Up @@ -123,7 +133,9 @@ class table_view_base {
* @param column_index The index of the desired column
* @return A reference to the desired column
*/
ColumnView const& column(size_type column_index) const;
ColumnView const& column(size_type column_index) const {
return _columns.at(column_index);
}

/**
* @brief Returns the number of columns
Expand Down Expand Up @@ -167,14 +179,15 @@ class table_view_base {
table_view_base& operator=(table_view_base&&) = default;
};

} // 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);
} // namespace detail

/**
* @brief A set of cudf::column_view's of the same size.
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/binaryop/compiled/struct_binary_ops.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void apply_struct_binary_op(mutable_column_view& out,
out.end<bool>(),
device_comparison_functor{optional_iter, is_lhs_scalar, is_rhs_scalar, device_comparator});
};
if (cudf::detail::has_nested_columns(tlhs) || cudf::detail::has_nested_columns(trhs)) {
if (cudf::has_nested_columns(tlhs) || cudf::has_nested_columns(trhs)) {
is_any_v<BinaryOperator, ops::LessEqual, ops::GreaterEqual>
? tabulate_device_operator(
table_comparator.less_equivalent<true>(comparator_nulls, comparator))
Expand Down Expand Up @@ -173,7 +173,7 @@ void apply_struct_equality_op(mutable_column_view& out,
op != binary_operator::NOT_EQUAL));
};

if (cudf::detail::has_nested_columns(tlhs) or cudf::detail::has_nested_columns(trhs)) {
if (cudf::has_nested_columns(tlhs) or cudf::has_nested_columns(trhs)) {
auto device_comparator = table_comparator.equal_to<true>(
nullate::DYNAMIC{has_nested_nulls(tlhs) || has_nested_nulls(trhs)},
null_equality::EQUAL,
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/groupby/hash/groupby.cu
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ std::unique_ptr<table> groupby(table_view const& keys,
mr);
};

if (cudf::detail::has_nested_columns(keys)) {
if (cudf::has_nested_columns(keys)) {
auto const d_key_equal = comparator.equal_to<true>(has_null, null_keys_are_equal);
return comparator_helper(d_key_equal);
} else {
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/groupby/sort/group_nunique.cu
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ std::unique_ptr<column> group_nunique(column_view const& values,
fn);
};

if (cudf::detail::has_nested_columns(values_view)) {
if (cudf::has_nested_columns(values_view)) {
auto const d_equal = comparator.equal_to<true>(
cudf::nullate::DYNAMIC{cudf::has_nested_nulls(values_view)}, null_equality::EQUAL);
comparator_helper(d_equal);
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/groupby/sort/group_rank_scan.cu
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ std::unique_ptr<column> rank_generator(column_view const& grouped_values,
group_labels.begin(), group_offsets.begin(), permuted_equal, resolver));
};

if (cudf::detail::has_nested_columns(grouped_values_view)) {
if (cudf::has_nested_columns(grouped_values_view)) {
auto const d_equal =
comparator.equal_to<true>(cudf::nullate::DYNAMIC{has_nulls}, null_equality::EQUAL);
comparator_helper(d_equal);
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/groupby/sort/sort_helper.cu
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ sort_groupby_helper::index_vector const& sort_groupby_helper::group_offsets(
auto const sorted_order = key_sort_order(stream).data<size_type>();
decltype(group_offsets->begin()) result_end;

if (cudf::detail::has_nested_columns(_keys)) {
if (cudf::has_nested_columns(_keys)) {
auto const d_key_equal = comparator.equal_to<true>(
cudf::nullate::DYNAMIC{cudf::has_nested_nulls(_keys)}, null_equality::EQUAL);
// Using a temporary buffer for intermediate transform results from the iterator containing
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/join/hash_join.cu
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ std::size_t compute_join_output_size(
}
};

if (cudf::detail::has_nested_columns(probe_table)) {
if (cudf::has_nested_columns(probe_table)) {
auto const device_comparator = row_comparator.equal_to<true>(has_nulls, nulls_equal);
return comparator_helper(device_comparator);
} else {
Expand Down Expand Up @@ -230,7 +230,7 @@ probe_join_hash_table(
}
};

if (cudf::detail::has_nested_columns(probe_table)) {
if (cudf::has_nested_columns(probe_table)) {
auto const device_comparator = row_comparator.equal_to<true>(probe_nulls, compare_nulls);
comparator_helper(device_comparator);
} else {
Expand Down Expand Up @@ -310,7 +310,7 @@ std::size_t get_full_join_size(
hash_table.pair_retrieve_outer(
iter, iter + probe_table_num_rows, out1_zip_begin, out2_zip_begin, equality, stream.value());
};
if (cudf::detail::has_nested_columns(probe_table)) {
if (cudf::has_nested_columns(probe_table)) {
auto const device_comparator = row_comparator.equal_to<true>(probe_nulls, compare_nulls);
comparator_helper(device_comparator);
} else {
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/merge/merge.cu
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,8 @@ table_ptr_type merge(cudf::table_view const& left_table,
// extract merged row order according to indices:
//
auto const merged_indices = [&]() {
if (cudf::detail::has_nested_columns(left_table) or
cudf::detail::has_nested_columns(right_table)) {
if (cudf::has_nested_columns(left_table) or
cudf::has_nested_columns(right_table)) {
return generate_merged_indices_nested(
index_left_view, index_right_view, column_order, null_precedence, nullable, stream);
} else {
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/reductions/histogram.cu
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ compute_row_frequencies(table_view const& input,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr)
{
auto const has_nested_columns = cudf::detail::has_nested_columns(input);
auto const has_nested_columns = cudf::has_nested_columns(input);

// Nested types are not tested, thus we just throw exception if we see such input for now.
// We should remove this check after having enough tests.
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/reductions/scan/rank_scan.cu
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ std::unique_ptr<column> rank_generator(column_view const& order_by,
device_comparator, resolver));
};

if (cudf::detail::has_nested_columns(order_by_tview)) {
if (cudf::has_nested_columns(order_by_tview)) {
auto const device_comparator =
comp.equal_to<true>(nullate::DYNAMIC{has_nested_nulls(table_view({order_by}))});
comparator_helper(device_comparator);
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/search/contains_table.cu
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ rmm::device_uvector<bool> contains(table_view const& haystack,
}
};

if (cudf::detail::has_nested_columns(haystack)) {
if (cudf::has_nested_columns(haystack)) {
dispatch_nan_comparator<true>(compare_nulls,
compare_nans,
haystack_has_nulls,
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/search/search_ordered.cu
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ std::unique_ptr<column> search_ordered(table_view const& haystack,
auto const haystack_it = cudf::experimental::row::lhs_iterator(0);
auto const needles_it = cudf::experimental::row::rhs_iterator(0);

if (cudf::detail::has_nested_columns(haystack) || cudf::detail::has_nested_columns(needles)) {
if (cudf::has_nested_columns(haystack) || cudf::has_nested_columns(needles)) {
auto const d_comparator = comparator.less<true>(nullate::DYNAMIC{has_nulls});
if (find_first) {
thrust::lower_bound(rmm::exec_policy(stream),
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/sort/is_sorted.cu
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bool is_sorted(cudf::table_view const& in,
auto const comparator =
experimental::row::lexicographic::self_comparator{in, column_order, null_precedence, stream};

if (cudf::detail::has_nested_columns(in)) {
if (cudf::has_nested_columns(in)) {
auto const device_comparator = comparator.less<true>(has_nested_nulls(in));

// Using a temporary buffer for intermediate transform results from the lambda containing
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/sort/rank.cu
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ rmm::device_uvector<size_type> sorted_dense_rank(column_view input_col,
sorted_index_order, device_comparator});
};

if (cudf::detail::has_nested_columns(t_input)) {
if (cudf::has_nested_columns(t_input)) {
auto const device_comparator =
comparator.equal_to<true>(nullate::DYNAMIC{has_nested_nulls(t_input)});
comparator_helper(device_comparator);
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/sort/sort_impl.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ std::unique_ptr<column> sorted_order(table_view input,

auto const comp = cudf::experimental::row::lexicographic::self_comparator(
input, column_order, null_precedence, stream);
if (cudf::detail::has_nested_columns(input)) {
if (cudf::has_nested_columns(input)) {
auto const comparator = comp.less<true>(nullate::DYNAMIC{has_nested_nulls(input)});
do_sort(comparator);
} else {
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/stream_compaction/distinct.cu
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ rmm::device_uvector<size_type> distinct_indices(table_view const& input,
auto const preprocessed_input =
cudf::experimental::row::hash::preprocessed_table::create(input, stream);
auto const has_nulls = nullate::DYNAMIC{cudf::has_nested_nulls(input)};
auto const has_nested_columns = cudf::detail::has_nested_columns(input);
auto const has_nested_columns = cudf::has_nested_columns(input);

auto const row_hasher = cudf::experimental::row::hash::row_hasher(preprocessed_input);
auto const key_hasher = row_hasher.device_hasher(has_nulls);
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/stream_compaction/distinct_count.cu
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ cudf::size_type distinct_count(table_view const& keys,
return key_set.insert(iter, iter + num_rows, stream.value());
};

if (cudf::detail::has_nested_columns(keys)) {
if (cudf::has_nested_columns(keys)) {
auto const row_equal = row_comp.equal_to<true>(has_nulls, nulls_equal);
return comparator_helper(row_equal);
} else {
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/stream_compaction/unique.cu
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ std::unique_ptr<table> unique(table_view const& input,
auto comp = cudf::experimental::row::equality::self_comparator(keys_view, stream);

size_type const unique_size = [&] {
if (cudf::detail::has_nested_columns(keys_view)) {
if (cudf::has_nested_columns(keys_view)) {
// Using a temporary buffer for intermediate transform results from the functor containing
// the comparator speeds up compile-time significantly without much degradation in
// runtime performance over using the comparator directly in thrust::unique_copy.
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/stream_compaction/unique_count.cu
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ cudf::size_type unique_count(table_view const& keys,
rmm::cuda_stream_view stream)
{
auto const row_comp = cudf::experimental::row::equality::self_comparator(keys, stream);
if (cudf::detail::has_nested_columns(keys)) {
if (cudf::has_nested_columns(keys)) {
auto const comp =
row_comp.equal_to<true>(nullate::DYNAMIC{has_nested_nulls(keys)}, nulls_equal);
// Using a temporary buffer for intermediate transform results from the lambda containing
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/table/row_operators.cu
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ std::shared_ptr<preprocessed_table> preprocessed_table::create(
auto d_depths = detail::make_device_uvector_async(
verticalized_col_depths, stream, rmm::mr::get_current_device_resource());

if (detail::has_nested_columns(preprocessed_input)) {
if (has_nested_columns(preprocessed_input)) {
auto [dremel_data, d_dremel_device_view] = list_lex_preprocess(preprocessed_input, stream);
return std::shared_ptr<preprocessed_table>(
new preprocessed_table(std::move(d_table),
Expand Down
21 changes: 1 addition & 20 deletions cpp/src/table/table_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@

namespace cudf {
namespace detail {
template <typename ColumnView>
table_view_base<ColumnView>::table_view_base(std::vector<ColumnView> const& cols) : _columns{cols}
{
if (num_columns() > 0) {
std::for_each(_columns.begin(), _columns.end(), [this](ColumnView col) {
CUDF_EXPECTS(col.size() == _columns.front().size(), "Column size mismatch.");
});
_num_rows = _columns.front().size();
} else {
_num_rows = 0;
}
}

template <typename ViewType>
auto concatenate_column_views(std::vector<ViewType> const& views)
Expand All @@ -52,12 +40,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 @@ -166,12 +148,11 @@ template bool is_relationally_comparable<table_view>(table_view const& lhs, tabl
// Explicit template instantiation for a table of mutable views
template bool is_relationally_comparable<mutable_table_view>(mutable_table_view const& lhs,
mutable_table_view const& rhs);
} // namespace detail

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
} // namespace cudf
2 changes: 1 addition & 1 deletion cpp/src/transform/one_hot_encode.cu
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ std::pair<std::unique_ptr<column>, table_view> one_hot_encode(column_view const&
ohe_equality_functor<decltype(d_equal)>(input.size(), d_equal));
};

if (cudf::detail::has_nested_columns(t_lhs) or cudf::detail::has_nested_columns(t_rhs)) {
if (cudf::has_nested_columns(t_lhs) or cudf::has_nested_columns(t_rhs)) {
auto const d_equal = comparator.equal_to<true>(
nullate::DYNAMIC{has_nested_nulls(t_lhs) || has_nested_nulls(t_rhs)});
comparator_helper(d_equal);
Expand Down
4 changes: 2 additions & 2 deletions cpp/tests/table/experimental_row_operator_tests.cu
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ TYPED_TEST(TypedTableViewTest, TestSortSameTableFromTwoTables)
auto const& comparator,
auto const& expected) {
auto const order = sorted_order(
preprocessed, input.num_rows(), cudf::detail::has_nested_columns(input), comparator, stream);
preprocessed, input.num_rows(), cudf::has_nested_columns(input), comparator, stream);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected, order->view());
};

Expand Down Expand Up @@ -194,7 +194,7 @@ TYPED_TEST(TypedTableViewTest, TestSortSameTableFromTwoTablesWithListsOfStructs)
auto const& comparator,
auto const& expected) {
auto const order = sorted_order(
preprocessed, input.num_rows(), cudf::detail::has_nested_columns(input), comparator, stream);
preprocessed, input.num_rows(), cudf::has_nested_columns(input), comparator, stream);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected, order->view());
};

Expand Down
Loading

0 comments on commit 9845334

Please sign in to comment.