libcudf  24.02.00
table_view.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2023, 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 
19 #include <cudf/types.hpp>
20 
21 #include <algorithm>
22 #include <vector>
23 
35 namespace cudf {
36 namespace detail {
50 template <typename ColumnView>
52  static_assert(std::is_same_v<ColumnView, column_view> or
53  std::is_same_v<ColumnView, mutable_column_view>,
54  "table_view_base can only be instantiated with column_view or "
55  "column_view_base.");
56 
57  private:
58  std::vector<ColumnView> _columns{};
59  size_type _num_rows{};
60 
61  public:
62  using iterator = decltype(std::begin(_columns));
63  using const_iterator = decltype(std::cbegin(_columns));
64 
81  explicit table_view_base(std::vector<ColumnView> const& cols);
82 
88  iterator begin() noexcept { return std::begin(_columns); }
89 
95  [[nodiscard]] const_iterator begin() const noexcept { return std::begin(_columns); }
96 
105  iterator end() noexcept { return std::end(_columns); }
106 
115  [[nodiscard]] const_iterator end() const noexcept { return std::end(_columns); }
116 
126  ColumnView const& column(size_type column_index) const;
127 
133  [[nodiscard]] size_type num_columns() const noexcept { return _columns.size(); }
134 
140  [[nodiscard]] size_type num_rows() const noexcept { return _num_rows; }
141 
147  [[nodiscard]] size_type is_empty() const noexcept { return num_columns() == 0; }
148 
149  table_view_base() = default;
150 
151  ~table_view_base() = default;
152 
153  table_view_base(table_view_base const&) = default;
154 
168 };
169 
177 } // namespace detail
178 
187 class table_view : public detail::table_view_base<column_view> {
189 
190  public:
192 
193  table_view() = default;
194 
213  table_view(std::vector<table_view> const& views);
214 
226  template <typename InputIterator>
227  table_view select(InputIterator begin, InputIterator end) const
228  {
229  std::vector<column_view> columns(std::distance(begin, end));
230  std::transform(begin, end, columns.begin(), [this](auto index) { return this->column(index); });
231  return table_view(columns);
232  }
233 
244  [[nodiscard]] table_view select(std::vector<size_type> const& column_indices) const;
245 };
246 
255 class mutable_table_view : public detail::table_view_base<mutable_column_view> {
257 
258  public:
260 
261  mutable_table_view() = default;
262 
269  [[nodiscard]] mutable_column_view& column(size_type column_index) const
270  {
271  return const_cast<mutable_column_view&>(table_view_base::column(column_index));
272  }
276  operator table_view();
277 
296  mutable_table_view(std::vector<mutable_table_view> const& views);
297 };
298 
305 bool nullable(table_view const& view);
306 
315 bool has_nulls(table_view const& view);
316 
323 bool has_nested_nulls(table_view const& input);
324 
333 
340 std::vector<column_view> get_nullable_columns(table_view const& table);
341 
349 bool have_same_types(table_view const& lhs, table_view const& rhs);
350 
365  std::vector<size_type> const& map,
366  table_view const& target);
367 
368 namespace detail {
377 template <typename TableView>
378 bool is_relationally_comparable(TableView const& lhs, TableView const& rhs);
379 // @cond
380 extern template bool is_relationally_comparable<table_view>(table_view const& lhs,
381  table_view const& rhs);
382 extern template bool is_relationally_comparable<mutable_table_view>(mutable_table_view const& lhs,
383  mutable_table_view const& rhs);
384 // @endcond
385 } // namespace detail
386 } // namespace 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:51
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:88
ColumnView const & column(size_type column_index) const
Returns a reference to the view of the specified column.
const_iterator end() const noexcept
Returns an iterator one past the last column view in the table.
Definition: table_view.hpp:115
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:133
size_type is_empty() const noexcept
Returns true if num_columns() returns zero, or false otherwise.
Definition: table_view.hpp:147
decltype(std::begin(_columns)) iterator
Iterator type for the table.
Definition: table_view.hpp:62
size_type num_rows() const noexcept
Returns the number of rows.
Definition: table_view.hpp:140
iterator end() noexcept
Returns an iterator one past the last column view in the table.
Definition: table_view.hpp:105
const_iterator begin() const noexcept
Returns an iterator to the first view in the table.
Definition: table_view.hpp:95
decltype(std::cbegin(_columns)) const_iterator
const iterator type for the table
Definition: table_view.hpp:63
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:255
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:269
A set of cudf::column_view's of the same size.
Definition: table_view.hpp:187
table_view select(InputIterator begin, InputIterator end) const
Returns a table_view built from a range of column indices.
Definition: table_view.hpp:227
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:40
column view class definitions
std::unique_ptr< column > transform(column_view const &input, std::string const &unary_udf, data_type output_type, bool is_ptx, rmm::mr::device_memory_resource *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
constexpr bool is_relationally_comparable()
Indicates whether objects of types L and R can be relationally compared.
Definition: traits.hpp:125
cuDF interfaces
Definition: aggregation.hpp:34
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 have_same_types(table_view const &lhs, table_view const &rhs)
Checks if two table_views have columns of same types.
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 has_nested_columns(table_view const &table)
Determine if any nested columns exist in a given table.
Type declarations for libcudf.