table.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2024, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include <cudf/column/column.hpp>
21 
22 #include <rmm/cuda_stream_view.hpp>
23 #include <rmm/mr/device/per_device_resource.hpp>
24 #include <rmm/resource_ref.hpp>
25 
26 #include <memory>
27 #include <vector>
28 
34 namespace cudf {
35 
41 class table {
42  public:
43  table() = default;
44  ~table() = default;
45  table(table&&) = default;
46  table& operator=(table const&) = delete;
47  table& operator=(table&&) = delete;
48 
59  explicit table(table const& other,
60  rmm::cuda_stream_view stream = cudf::get_default_stream(),
61  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
69  table(std::vector<std::unique_ptr<column>>&& columns);
70 
79  rmm::cuda_stream_view stream = cudf::get_default_stream(),
80  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
81 
87  [[nodiscard]] size_type num_columns() const noexcept { return _columns.size(); }
88 
94  [[nodiscard]] size_type num_rows() const noexcept { return _num_rows; }
95 
102  [[nodiscard]] table_view view() const;
103 
108  operator table_view() const { return this->view(); };
109 
117 
122  operator mutable_table_view() { return this->mutable_view(); };
123 
132  std::vector<std::unique_ptr<column>> release();
133 
146  template <typename InputIterator>
147  [[nodiscard]] table_view select(InputIterator begin, InputIterator end) const
148  {
149  std::vector<column_view> columns(std::distance(begin, end));
151  begin, end, columns.begin(), [this](auto index) { return _columns.at(index)->view(); });
152  return table_view(columns);
153  }
154 
165  [[nodiscard]] table_view select(std::vector<cudf::size_type> const& column_indices) const
166  {
167  return select(column_indices.begin(), column_indices.end());
168  };
169 
179  column& get_column(cudf::size_type column_index) { return *(_columns.at(column_index)); }
180 
190  [[nodiscard]] column const& get_column(cudf::size_type i) const { return *(_columns.at(i)); }
191 
192  private:
193  std::vector<std::unique_ptr<column>> _columns{};
194  size_type _num_rows{};
195 };
196 
197 } // namespace cudf
A container of nullable device data as a column of elements.
Definition: column.hpp:48
A set of mutable_column_views of the same size.
Definition: table_view.hpp:268
A set of cudf::column_view's of the same size.
Definition: table_view.hpp:200
A set of cudf::column's of the same size.
Definition: table.hpp:41
mutable_table_view mutable_view()
Returns a mutable, non-owning mutable_table_view of the contents of this table.
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:165
column const & get_column(cudf::size_type i) const
Returns a const reference to the specified column.
Definition: table.hpp:190
table_view view() const
Returns an immutable, non-owning table_view of the contents of this table.
table(table const &other, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Construct a new table by copying the contents of another 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.
table(table_view view, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Copy the contents of a table_view to construct a new table.
size_type num_rows() const noexcept
Returns the number of rows.
Definition: table.hpp:94
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:147
size_type num_columns() const noexcept
Returns the number of columns in the table.
Definition: table.hpp:87
column & get_column(cudf::size_type column_index)
Returns a reference to the specified column.
Definition: table.hpp:179
Class definition for cudf::column.
rmm::cuda_stream_view const get_default_stream()
Get the current default stream.
std::unique_ptr< column > transform(column_view const &input, std::string const &unary_udf, data_type output_type, bool is_ptx, rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Creates a new column by applying a unary function against every element of an input column.
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:93
size_type distance(T f, T l)
Similar to std::distance but returns cudf::size_type and performs static_cast
Definition: types.hpp:108
cuDF interfaces
Definition: aggregation.hpp:34
Class definitions for (mutable)_table_view