table_view.hpp
前往此文件的文档。
1 /*
2  * 版权所有 (c) 2019-2024, NVIDIA CORPORATION.
3  *
4  * 根据 Apache 许可证第 2.0 版(以下简称“许可证”)获得许可;
5  * 除非符合许可证的规定,否则不得使用此文件。
6  * 您可以在以下网址获取许可证副本:
7  *
8  * https://apache.ac.cn/licenses/LICENSE-2.0
9  *
10  * 除非适用法律要求或书面同意,否则根据许可证分发的软件是基于“原样”提供的,
11  * 不附带任何明示或暗示的担保或条件。
12  * 请参阅许可证以了解特定语言的权限和限制。
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
19 #include <cudf/types.hpp>
20 #include <cudf/utilities/export.hpp>
21 
22 #include <algorithm>
23 #include <vector>
24 
36 namespace CUDF_EXPORT cudf {
37 namespace detail {
51 template <typename ColumnView>
53  static_assert(std::is_same_v<ColumnView, column_view> or
54  std::is_same_v<ColumnView, mutable_column_view>,
55  "table_view_base can only be instantiated with column_view or "
56  "column_view_base.");
57 
58  private
59  std::vector<ColumnView> _columns{};
60  size_type _num_rows{};
61 
62  public
63  using iterator = decltype(std::begin(_columns));
64  using const_iterator = decltype(std::cbegin(_columns));
65 
82  explicit table_view_base(std::vector<ColumnView> const& cols);
83 
89  iterator begin() noexcept { return std::begin(_columns); }
90 
96  [[nodiscard]] const_iterator begin() const noexcept { return std::begin(_columns); }
97 
106  iterator end() noexcept { return std::end(_columns); }
107 
116  [[nodiscard]] const_iterator end() const noexcept { return std::end(_columns); }
117 
127  [[nodiscard]] ColumnView const& column(size_type column_index) const
128  {
129  return _columns.at(column_index);
130  }
131 
137  [[nodiscard]] size_type num_columns() const noexcept { return _columns.size(); }
138 
144  [[nodiscard]] size_type num_rows() const noexcept { return _num_rows; }
145 
151  [[nodiscard]] size_type is_empty() const noexcept { return num_columns() == 0; }
152 
153  table_view_base() = default;
154 
155  ~table_view_base() = default;
156 
157  table_view_base(table_view_base const&) = default;
158 
172 };
173 
181 
182 } // namespace detail
183 
191 
200 class table_view : public detail::table_view_base<column_view> {
202 
203  public
205 
206  table_view() = default;
207 
226  table_view(std::vector<table_view> const& views);
227 
239  template <typename InputIterator>
240  [[nodiscard]] table_view select(InputIterator begin, InputIterator end) const
241  {
242  std::vector<column_view> columns(std::distance(begin, end));
243  std::transform(begin, end, columns.begin(), [this](auto index) { return this->column(index); });
244  return table_view{columns};
245  }
246 
257  [[nodiscard]] table_view select(std::vector<size_type> const& column_indices) const;
258 };
259 
268 class mutable_table_view : public detail::table_view_base<mutable_column_view> {
270 
271  public
273 
274  mutable_table_view() = default;
275 
282  [[nodiscard]] mutable_column_view& column(size_type column_index) const
283  {
284  return const_cast<mutable_column_view&>(table_view_base::column(column_index));
285  }
289  operator table_view();
290 
309  mutable_table_view(std::vector<mutable_table_view> const& views);
310 };
311 
318 bool nullable(table_view const& view);
319 
328 bool has_nulls(table_view const& view);
329 
336 bool has_nested_nulls(table_view const& input);
337 
346 
353 std::vector<column_view> get_nullable_columns(table_view const& table);
354 
369  std::vector<size_type> const& map,
370  table_view const& target);
371 
372 namespace detail;
381 template <typename TableView>
382 bool is_relationally_comparable(TableView const& lhs, TableView const& rhs);
383 // @cond
384 extern template bool is_relationally_comparable<table_view>(table_view const& lhs,
385  table_view const& rhs);
386 extern template bool is_relationally_comparable<mutable_table_view>(mutable_table_view const& lhs,
387  mutable_table_view const& rhs);
388 // @endcond
389 } // namespace detail
390 } // namespace CUDF_EXPORT cudf
一个非拥有、不可变的设备数据视图,表示为元素的列,其中一些元素可能为空...
定义于: column_view.hpp:327
ColumnView 表的基类。
定义于: table_view.hpp:52
table_view_base(std::vector< ColumnView > const &cols)
从列视图向量构造表。
table_view_base(table_view_base &&)=default
移动构造函数。
iterator begin() noexcept
返回表中第一个视图的迭代器。
定义于: table_view.hpp:89
ColumnView const & column(size_type column_index) const
返回指定列视图的引用。
定义于: table_view.hpp:127
const_iterator end() const noexcept
返回表中最后一个列视图之后位置的迭代器。
定义于: table_view.hpp:116
table_view_base & operator=(table_view_base &&)=default
移动赋值运算符。
size_type num_columns() const noexcept
返回列数。
定义于: table_view.hpp:137
size_type is_empty() const noexcept
如果 num_columns() 返回零,则返回 true,否则返回 false。
定义于: table_view.hpp:151
decltype(std::begin(_columns)) iterator
表的迭代器类型。
定义于: table_view.hpp:63
size_type num_rows() const noexcept
返回行数。
定义于: table_view.hpp:144
iterator end() noexcept
返回表中最后一个列视图之后位置的迭代器。
定义于: table_view.hpp:106
const_iterator begin() const noexcept
返回表中第一个视图的迭代器。
定义于: table_view.hpp:96
decltype(std::cbegin(_columns)) const_iterator
表的 const 迭代器类型
定义于: table_view.hpp:64
table_view_base(table_view_base const &)=default
拷贝构造函数。
table_view_base & operator=(table_view_base const &)=default
拷贝赋值运算符。
一个非拥有、可变的设备数据视图,表示为元素的列,其中一些元素可能为空...
定义于: column_view.hpp:503
一组大小相同的 mutable_column_view。
定义于: table_view.hpp:268
mutable_table_view(std::vector< mutable_table_view > const &views)
从表视图向量构造表。
mutable_column_view & column(size_type column_index) const
返回指定索引处的列。
定义于: table_view.hpp:282
一组大小相同的 cudf::column_view。
定义于: table_view.hpp:200
table_view select(InputIterator begin, InputIterator end) const
从列索引范围构建并返回 table_view。
定义于: table_view.hpp:240
table_view(std::vector< table_view > const &views)
从表视图向量构造表。
table_view select(std::vector< size_type > const &column_indices) const
返回包含指定列集的 table_view。
一组大小相同的 cudf::column。
定义于: table.hpp:40
column view 类定义
std::unique_ptr< column > transform(std::vector< column_view > const &inputs, std::string const &transform_udf, data_type output_type, bool is_ptx, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
通过对输入列的每个元素应用转换函数来创建一个新列。
int32_t size_type
列和表的行索引类型。
定义于: types.hpp:95
size_type distance(T f, T l)
类似于 std::distance,但返回 cudf::size_type 并执行 static_cast
定义于: types.hpp:110
cuDF 接口
定义于: host_udf.hpp:37
bool nullable(table_view const &view)
如果表中任一列可空,则返回 True。(非整个层级结构)
bool has_nulls(table_view const &view)
如果表中任一列包含 null 值,则返回 True。
std::vector< column_view > get_nullable_columns(table_view const &table)
此函数用于收集给定表中所有嵌套级别的所有可空列。
bool has_nested_columns(table_view const &table)
确定给定表中是否存在任何嵌套列。
bool has_nested_nullable_columns(table_view const &input)
如果表在列层级结构的任一级别包含可空列,则返回 True。
bool has_nested_nulls(table_view const &input)
如果表在其列层级结构任一级别包含 null 值,则返回 True。
table_view scatter_columns(table_view const &source, std::vector< size_type > const &map, table_view const &target)
根据列索引映射将 column_view 从一个 table_view 复制到另一个 table_view 中。
bool is_relationally_comparable(TableView const &lhs, TableView const &rhs)
指示输入表中各自的列是否具有关系可比性。
libcudf 的类型声明。