table_view.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2020, 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 {
49 template <typename ColumnView>
51  static_assert(std::is_same<ColumnView, column_view>::value or
52  std::is_same<ColumnView, mutable_column_view>::value,
53  "table_view_base can only be instantiated with column_view or "
54  "column_view_base.");
55 
56  private:
57  std::vector<ColumnView> _columns{};
58  size_type _num_rows{};
59 
60  public:
61  using iterator = decltype(std::begin(_columns));
62  using const_iterator = decltype(std::cbegin(_columns));
63 
80  explicit table_view_base(std::vector<ColumnView> const& cols);
81 
85  iterator begin() noexcept { return std::begin(_columns); }
86 
90  const_iterator begin() const noexcept { return std::begin(_columns); }
91 
98  iterator end() noexcept { return std::end(_columns); }
99 
106  const_iterator end() const noexcept { return std::end(_columns); }
107 
117  ColumnView const& column(size_type column_index) const;
118 
122  size_type num_columns() const noexcept { return _columns.size(); }
123 
127  size_type num_rows() const noexcept { return _num_rows; }
128 
129  table_view_base() = default;
130 
131  ~table_view_base() = default;
132 
133  table_view_base(table_view_base const&) = default;
134 
135  table_view_base(table_view_base&&) = default;
136  table_view_base& operator=(table_view_base const&) = default;
137  table_view_base& operator=(table_view_base&&) = default;
138 };
139 } // namespace detail
140 
149 class table_view : public detail::table_view_base<column_view> {
151 
152  public:
153  using ColumnView = column_view;
154 
155  table_view() = default;
156 
175  table_view(std::vector<table_view> const& views);
176 
187  table_view select(std::vector<size_type> const& column_indices) const;
188 };
189 
198 class mutable_table_view : public detail::table_view_base<mutable_column_view> {
200 
201  public:
203 
204  mutable_table_view() = default;
205 
206  mutable_column_view& column(size_type column_index) const
207  {
208  return const_cast<mutable_column_view&>(table_view_base::column(column_index));
209  }
213  operator table_view();
214 
233  mutable_table_view(std::vector<mutable_table_view> const& views);
234 };
235 
236 inline bool has_nulls(table_view view)
237 {
238  return std::any_of(view.begin(), view.end(), [](column_view col) { return col.has_nulls(); });
239 }
240 
248 inline bool have_same_types(table_view const& lhs, table_view const& rhs)
249 {
250  return std::equal(
251  lhs.begin(),
252  lhs.end(),
253  rhs.begin(),
254  rhs.end(),
255  [](column_view const& lcol, column_view const& rcol) { return (lcol.type() == rcol.type()); });
256 }
257 
272  std::vector<size_type> const& map,
273  table_view const& target);
274 
275 } // namespace cudf
cudf::mutable_table_view
A set of mutable_column_views of the same size.
Definition: table_view.hpp:198
cudf::column
A container of nullable device data as a column of elements.
Definition: column.hpp:45
cudf::detail::table_view_base::begin
const_iterator begin() const noexcept
Returns an iterator to the first view in the table.
Definition: table_view.hpp:90
cudf::mutable_table_view::mutable_table_view
mutable_table_view(std::vector< mutable_table_view > const &views)
Construct a table from a vector of table views.
cudf::table_view::select
table_view select(std::vector< size_type > const &column_indices) const
Returns a table_view with set of specified columns.
cudf::column_view
A non-owning, immutable view of device data as a column of elements, some of which may be null as ind...
Definition: column_view.hpp:281
types.hpp
Type declarations for libcudf.
cudf::detail::table_view_base::num_rows
size_type num_rows() const noexcept
Returns the number of rows.
Definition: table_view.hpp:127
cudf::mutable_column_view
A non-owning, mutable view of device data as a column of elements, some of which may be null as indic...
Definition: column_view.hpp:388
cudf::table_view::table_view
table_view(std::vector< table_view > const &views)
Construct a table from a vector of table views.
cudf::detail::table_view_base::begin
iterator begin() noexcept
Returns an iterator to the first view in the table.
Definition: table_view.hpp:85
cudf::detail::table_view_base::end
iterator end() noexcept
Returns an iterator one past the last column view in the table.
Definition: table_view.hpp:98
cudf::detail::table_view_base::num_columns
size_type num_columns() const noexcept
Returns the number of columns.
Definition: table_view.hpp:122
cudf::detail::table_view_base::table_view_base
table_view_base(std::vector< ColumnView > const &cols)
Construct a table from a vector of column views.
cudf::detail::table_view_base::end
const_iterator end() const noexcept
Returns an iterator one past the last column view in the table.
Definition: table_view.hpp:106
cudf::scatter_columns
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.
cudf::table_view
A set of cudf::column_view's of the same size.
Definition: table_view.hpp:149
cudf::have_same_types
bool have_same_types(table_view const &lhs, table_view const &rhs)
Checks if two table_views have columns of same types.
Definition: table_view.hpp:248
cudf
cuDF interfaces
Definition: aggregation.hpp:34
cudf::detail::table_view_base
Base class for a table of ColumnViews.
Definition: table_view.hpp:50
cudf::detail::table_view_base::column
ColumnView const & column(size_type column_index) const
Returns a reference to the view of the specified column.
column_view.hpp
column view class definitons