table_view.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #pragma once
6 
8 #include <cudf/types.hpp>
9 #include <cudf/utilities/export.hpp>
10 
11 #include <algorithm>
12 #include <vector>
13 
25 namespace CUDF_EXPORT cudf {
26 namespace detail {
40 template <typename ColumnView>
42  static_assert(std::is_same_v<ColumnView, column_view> or
43  std::is_same_v<ColumnView, mutable_column_view>,
44  "table_view_base can only be instantiated with column_view or "
45  "column_view_base.");
46 
47  private:
48  std::vector<ColumnView> _columns{};
49  size_type _num_rows{};
50 
51  public:
52  using iterator = decltype(std::begin(_columns));
53  using const_iterator = decltype(std::cbegin(_columns));
54 
71  explicit table_view_base(std::vector<ColumnView> const& cols);
72 
86  table_view_base(std::vector<ColumnView> const& cols, size_type num_rows);
87 
93  iterator begin() noexcept { return std::begin(_columns); }
94 
100  [[nodiscard]] const_iterator begin() const noexcept { return std::begin(_columns); }
101 
110  iterator end() noexcept { return std::end(_columns); }
111 
120  [[nodiscard]] const_iterator end() const noexcept { return std::end(_columns); }
121 
131  [[nodiscard]] ColumnView const& column(size_type column_index) const
132  {
133  return _columns.at(column_index);
134  }
135 
141  [[nodiscard]] size_type num_columns() const noexcept { return _columns.size(); }
142 
148  [[nodiscard]] size_type num_rows() const noexcept { return _num_rows; }
149 
155  [[nodiscard]] size_type is_empty() const noexcept { return num_columns() == 0; }
156 
157  table_view_base() = default;
158 
159  ~table_view_base() = default;
160 
161  table_view_base(table_view_base const&) = default;
162 
176 };
177 
185 
186 } // namespace detail
187 
195 
206 class table_view : public detail::table_view_base<column_view> {
208 
209  public:
211 
212  table_view() = default;
213 
232  table_view(std::vector<table_view> const& views);
233 
245  template <typename InputIterator>
246  [[nodiscard]] table_view select(InputIterator begin, InputIterator end) const
247  {
248  std::vector<column_view> columns(std::distance(begin, end));
249  std::transform(begin, end, columns.begin(), [this](auto index) { return this->column(index); });
250  return table_view{columns, num_rows()};
251  }
252 
263  [[nodiscard]] table_view select(std::vector<size_type> const& column_indices) const;
264 };
265 
274 class mutable_table_view : public detail::table_view_base<mutable_column_view> {
276 
277  public:
279 
280  mutable_table_view() = default;
281 
288  [[nodiscard]] mutable_column_view& column(size_type column_index) const
289  {
290  return const_cast<mutable_column_view&>(table_view_base::column(column_index));
291  }
295  operator table_view();
296 
315  mutable_table_view(std::vector<mutable_table_view> const& views);
316 };
317 
324 bool nullable(table_view const& view);
325 
334 bool has_nulls(table_view const& view);
335 
342 bool has_nested_nulls(table_view const& input);
343 
352 
359 std::vector<column_view> get_nullable_columns(table_view const& table);
360 
375  std::vector<size_type> const& map,
376  table_view const& target);
377 
378 namespace detail {
387 template <typename TableView>
388 bool is_relationally_comparable(TableView const& lhs, TableView const& rhs);
389 // @cond
390 extern template bool is_relationally_comparable<table_view>(table_view const& lhs,
391  table_view const& rhs);
392 extern template bool is_relationally_comparable<mutable_table_view>(mutable_table_view const& lhs,
393  mutable_table_view const& rhs);
394 // @endcond
395 } // namespace detail
396 } // namespace CUDF_EXPORT cudf
A non-owning, immutable view of device data as a column of elements, some of which may be null as ind...
Base class for a table of ColumnViews.
Definition: table_view.hpp:41
table_view_base(std::vector< ColumnView > const &cols)
Construct a table from a vector of column views.
table_view_base(table_view_base &&)=default
Move constructor.
iterator begin() noexcept
Returns an iterator to the first view in the table.
Definition: table_view.hpp:93
ColumnView const & column(size_type column_index) const
Returns a reference to the view of the specified column.
Definition: table_view.hpp:131
const_iterator end() const noexcept
Returns an iterator one past the last column view in the table.
Definition: table_view.hpp:120
table_view_base & operator=(table_view_base &&)=default
Move assignment operator.
size_type num_columns() const noexcept
Returns the number of columns.
Definition: table_view.hpp:141
size_type is_empty() const noexcept
Returns true if num_columns() returns zero, or false otherwise.
Definition: table_view.hpp:155
decltype(std::begin(_columns)) iterator
Iterator type for the table.
Definition: table_view.hpp:52
size_type num_rows() const noexcept
Returns the number of rows.
Definition: table_view.hpp:148
iterator end() noexcept
Returns an iterator one past the last column view in the table.
Definition: table_view.hpp:110
table_view_base(std::vector< ColumnView > const &cols, size_type num_rows)
Construct a table from a vector of column views with an explicit row count.
const_iterator begin() const noexcept
Returns an iterator to the first view in the table.
Definition: table_view.hpp:100
decltype(std::cbegin(_columns)) const_iterator
const iterator type for the table
Definition: table_view.hpp:53
table_view_base(table_view_base const &)=default
Copy constructor.
table_view_base & operator=(table_view_base const &)=default
Copy assignment operator.
A non-owning, mutable view of device data as a column of elements, some of which may be null as indic...
A set of mutable_column_views of the same size.
Definition: table_view.hpp:274
mutable_table_view(std::vector< mutable_table_view > const &views)
Construct a table from a vector of table views.
mutable_column_view & column(size_type column_index) const
Returns column at specified index.
Definition: table_view.hpp:288
A set of cudf::column_view's of the same size.
Definition: table_view.hpp:206
table_view select(InputIterator begin, InputIterator end) const
Returns a table_view built from a range of column indices.
Definition: table_view.hpp:246
table_view(std::vector< table_view > const &views)
Construct a table from a vector of table views.
table_view select(std::vector< size_type > const &column_indices) const
Returns a table_view with set of specified columns.
A set of cudf::column's of the same size.
Definition: table.hpp:31
column view class definitions
std::unique_ptr< column > transform(std::vector< column_view > const &inputs, std::string const &transform_udf, data_type output_type, bool is_ptx, std::optional< void * > user_data=std::nullopt, null_aware is_null_aware=null_aware::NO, output_nullability null_policy=output_nullability::PRESERVE, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Creates a new column by applying a transform function against every element of the input columns.
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:84
size_type distance(T f, T l)
Similar to std::distance but returns cudf::size_type and performs static_cast
Definition: types.hpp:99
cuDF interfaces
Definition: host_udf.hpp:26
bool nullable(table_view const &view)
Returns True if any of the columns in the table is nullable. (not entire hierarchy)
bool has_nulls(table_view const &view)
Returns True if the table has nulls in any of its columns.
std::vector< column_view > get_nullable_columns(table_view const &table)
The function to collect all nullable columns at all nested levels in a given table.
bool has_nested_columns(table_view const &table)
Determine if any nested columns exist in a given table.
bool has_nested_nullable_columns(table_view const &input)
Returns True if the table has a nullable column at any level of the column hierarchy.
bool has_nested_nulls(table_view const &input)
Returns True if the table has nulls in any of its columns hierarchy.
table_view scatter_columns(table_view const &source, std::vector< size_type > const &map, table_view const &target)
Copy column_views from a table_view into another table_view according to a column indices map.
bool is_relationally_comparable(TableView const &lhs, TableView const &rhs)
Indicates whether respective columns in input tables are relationally comparable.
Type declarations for libcudf.