Skip to content

Commit

Permalink
Add struct utility functions. (#10776)
Browse files Browse the repository at this point in the history
This PR adds some struct utility functions. This change is needed for the eventual support of structs in binary operations. See also: PR #9452.

Authors:
  - Bradley Dice (https://github.com/bdice)

Approvers:
  - Vyas Ramasubramani (https://github.com/vyasr)
  - Jake Hemstad (https://github.com/jrhemstad)

URL: #10776
  • Loading branch information
bdice authored May 4, 2022
1 parent 8d861ce commit d3a39b3
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ add_library(
src/ast/expression_parser.cpp
src/ast/expressions.cpp
src/binaryop/binaryop.cpp
src/binaryop/compiled/binary_ops.cu
src/binaryop/compiled/Add.cu
src/binaryop/compiled/ATan2.cu
src/binaryop/compiled/BitwiseAnd.cu
Expand Down Expand Up @@ -220,6 +219,7 @@ add_library(
src/binaryop/compiled/ShiftRightUnsigned.cu
src/binaryop/compiled/Sub.cu
src/binaryop/compiled/TrueDiv.cu
src/binaryop/compiled/binary_ops.cu
src/binaryop/compiled/util.cpp
src/labeling/label_bins.cu
src/bitmask/null_mask.cu
Expand Down
16 changes: 15 additions & 1 deletion cpp/include/cudf/detail/structs/utilities.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
* Copyright (c) 2020-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 @@ -245,6 +245,20 @@ std::tuple<cudf::table_view, std::vector<rmm::device_buffer>> superimpose_parent
table_view const& table,
rmm::cuda_stream_view stream = rmm::cuda_stream_default,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());

/**
* @brief Checks if a column or any of its children is a struct column with structs that are null.
*
* This function searches for structs that are null -- differentiating between structs that are null
* and structs containing null values. Null structs add a column to the result of the flatten column
* utility and necessitates column_nullability::FORCE when flattening the column for comparison
* operations.
*
* @param col Column to check for null structs
* @return A boolean indicating if the column is or contains a struct column that contains a null
* struct.
*/
bool contains_null_structs(column_view const& col);
} // namespace detail
} // namespace structs
} // namespace cudf
2 changes: 1 addition & 1 deletion cpp/include/cudf/table/row_operators.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ __device__ weak_ordering compare_elements(Element lhs, Element rhs)
* @brief A specialization for floating-point `Element` type relational comparison
* to derive the order of the elements with respect to `lhs`.
*
* This Specialization handles `nan` in the following order:
* This specialization handles `nan` in the following order:
* `[-Inf, -ve, 0, -0, +ve, +Inf, NaN, NaN, null] (for null_order::AFTER)`
* `[null, -Inf, -ve, 0, -0, +ve, +Inf, NaN, NaN] (for null_order::BEFORE)`
*
Expand Down
31 changes: 31 additions & 0 deletions cpp/include/cudf/utilities/traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,37 @@ constexpr inline bool is_nested(data_type type)
return cudf::type_dispatcher(type, is_nested_impl{});
}

/**
* @brief Indicates whether `T` is a struct type.
*
* @param T The type to verify
* @return A boolean indicating if T is a struct type
*/
template <typename T>
constexpr inline bool is_struct()
{
return std::is_same_v<T, cudf::struct_view>;
}

struct is_struct_impl {
template <typename T>
constexpr bool operator()()
{
return is_struct<T>();
}
};

/**
* @brief Indicates whether `type` is a struct type.
*
* @param type The `data_type` to verify
* @return A boolean indicating if `type` is a struct type
*/
constexpr inline bool is_struct(data_type type)
{
return cudf::type_dispatcher(type, is_struct_impl{});
}

template <typename FromType>
struct is_bit_castable_to_impl {
template <typename ToType, std::enable_if_t<is_compound<ToType>()>* = nullptr>
Expand Down
6 changes: 6 additions & 0 deletions cpp/src/structs/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,12 @@ std::tuple<cudf::table_view, std::vector<rmm::device_buffer>> superimpose_parent
return {table_view{superimposed_columns}, std::move(superimposed_nullmasks)};
}

bool contains_null_structs(column_view const& col)
{
return (is_struct(col) && col.has_nulls()) ||
std::any_of(col.child_begin(), col.child_end(), contains_null_structs);
}

} // namespace detail
} // namespace structs
} // namespace cudf

0 comments on commit d3a39b3

Please sign in to comment.