table.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 
7 #include <cudf/column/column.hpp>
11 
12 #include <rmm/cuda_stream_view.hpp>
13 
14 #include <memory>
15 #include <vector>
16 
22 namespace CUDF_EXPORT cudf {
23 
31 class table {
32  public:
33  table() = default;
34  ~table() = default;
35  table(table&&) = default;
36  table& operator=(table const&) = delete;
37  table& operator=(table&&) = delete;
38 
49  explicit table(table const& other,
59  table(std::vector<std::unique_ptr<column>>&& columns);
60 
78  table(std::vector<std::unique_ptr<column>>&& columns, size_type num_rows);
79 
90 
96  [[nodiscard]] size_type num_columns() const noexcept { return _columns.size(); }
97 
103  [[nodiscard]] size_type num_rows() const noexcept { return _num_rows; }
104 
112  [[nodiscard]] std::size_t alloc_size() const;
113 
120  [[nodiscard]] table_view view() const;
121 
126  operator table_view() const { return this->view(); };
127 
135 
140  operator mutable_table_view() { return this->mutable_view(); };
141 
150  std::vector<std::unique_ptr<column>> release();
151 
164  template <typename InputIterator>
165  [[nodiscard]] table_view select(InputIterator begin, InputIterator end) const
166  {
167  std::vector<column_view> columns(std::distance(begin, end));
169  begin, end, columns.begin(), [this](auto index) { return _columns.at(index)->view(); });
170  return table_view{columns, num_rows()};
171  }
172 
183  [[nodiscard]] table_view select(std::vector<cudf::size_type> const& column_indices) const
184  {
185  return select(column_indices.begin(), column_indices.end());
186  };
187 
197  column& get_column(cudf::size_type column_index) { return *(_columns.at(column_index)); }
198 
208  [[nodiscard]] column const& get_column(cudf::size_type i) const { return *(_columns.at(i)); }
209 
210  private:
211  std::vector<std::unique_ptr<column>> _columns{};
212  size_type _num_rows{};
213 };
214 
215 } // namespace CUDF_EXPORT cudf
A container of nullable device data as a column of elements.
Definition: column.hpp:36
A set of mutable_column_views of the same size.
Definition: table_view.hpp:274
A set of cudf::column_view's of the same size.
Definition: table_view.hpp:206
A set of cudf::column's of the same size.
Definition: table.hpp:31
mutable_table_view mutable_view()
Returns a mutable, non-owning mutable_table_view of the contents of this table.
table(std::vector< std::unique_ptr< column >> &&columns, size_type num_rows)
Moves the contents from a vector of unique_ptrs to columns to construct a new table with an explicit ...
std::vector< std::unique_ptr< column > > release()
Releases ownership of the columns by returning a vector of unique_ptrs to the constituent columns.
table_view select(std::vector< cudf::size_type > const &column_indices) const
Returns a table_view with set of specified columns.
Definition: table.hpp:183
column const & get_column(cudf::size_type i) const
Returns a const reference to the specified column.
Definition: table.hpp:208
table(table const &other, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Construct a new table by copying the contents of another table.
table_view view() const
Returns an immutable, non-owning table_view of the contents of this table.
table(std::vector< std::unique_ptr< column >> &&columns)
Moves the contents from a vector of unique_ptrs to columns to construct a new table.
size_type num_rows() const noexcept
Returns the number of rows.
Definition: table.hpp:103
table(table &&)=default
Move constructor.
table_view select(InputIterator begin, InputIterator end) const
Returns a table_view built from a range of column indices.
Definition: table.hpp:165
table(table_view view, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Copy the contents of a table_view to construct a new table.
size_type num_columns() const noexcept
Returns the number of columns in the table.
Definition: table.hpp:96
std::size_t alloc_size() const
Returns the total device allocation size of the table's columns in bytes.
column & get_column(cudf::size_type column_index)
Returns a reference to the specified column.
Definition: table.hpp:197
Class definition for cudf::column.
APIs for querying the default CUDA stream and per-thread default stream status.
rmm::cuda_stream_view const get_default_stream()
Get the current default stream.
rmm::device_async_resource_ref get_current_device_resource_ref()
Get the current device memory resource reference.
cuda::mr::resource_ref< cuda::mr::device_accessible > device_async_resource_ref
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
APIs for getting and setting the current device memory resource.
cuDF interfaces
Definition: host_udf.hpp:26
Class definitions for (mutable)_table_view