column.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2021, 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 
20 #include <cudf/null_mask.hpp>
21 #include <cudf/types.hpp>
22 
23 #include <rmm/cuda_stream_view.hpp>
24 #include <rmm/device_buffer.hpp>
25 
26 #include <memory>
27 #include <type_traits>
28 #include <utility>
29 #include <vector>
30 
36 namespace cudf {
37 
45 class column {
46  public:
47  column() = default;
48  ~column() = default;
49  column& operator=(column const& other) = delete;
50  column& operator=(column&& other) = delete;
51 
63  column(column const& other,
65  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
66 
74  column(column&& other) noexcept;
75 
92  template <typename B1, typename B2 = rmm::device_buffer>
95  B1&& data,
96  B2&& null_mask = {},
97  size_type null_count = UNKNOWN_NULL_COUNT,
98  std::vector<std::unique_ptr<column>>&& children = {})
99  : _type{dtype},
100  _size{size},
101  _data{std::forward<B1>(data)},
102  _null_mask{std::forward<B2>(null_mask)},
103  _null_count{null_count},
104  _children{std::move(children)}
105  {
106  }
107 
119  rmm::cuda_stream_view stream = rmm::cuda_stream_default,
120  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
121 
125  [[nodiscard]] data_type type() const noexcept { return _type; }
126 
130  [[nodiscard]] size_type size() const noexcept { return _size; }
131 
140  [[nodiscard]] size_type null_count() const;
141 
155  void set_null_mask(rmm::device_buffer&& new_null_mask,
156  size_type new_null_count = UNKNOWN_NULL_COUNT);
157 
173  void set_null_mask(rmm::device_buffer const& new_null_mask,
174  size_type new_null_count = UNKNOWN_NULL_COUNT,
176 
188  void set_null_count(size_type new_null_count);
189 
202  [[nodiscard]] bool nullable() const noexcept { return (_null_mask.size() > 0); }
203 
210  [[nodiscard]] bool has_nulls() const noexcept { return (null_count() > 0); }
211 
215  [[nodiscard]] size_type num_children() const noexcept { return _children.size(); }
216 
223  column& child(size_type child_index) noexcept { return *_children[child_index]; };
224 
231  [[nodiscard]] column const& child(size_type child_index) const noexcept
232  {
233  return *_children[child_index];
234  };
235 
241  struct contents {
242  std::unique_ptr<rmm::device_buffer> data;
243  std::unique_ptr<rmm::device_buffer> null_mask;
244  std::vector<std::unique_ptr<column>> children;
245  };
246 
262  contents release() noexcept;
263 
270  [[nodiscard]] column_view view() const;
271 
280  operator column_view() const { return this->view(); };
281 
295 
310  operator mutable_column_view() { return this->mutable_view(); };
311 
312  private:
313  cudf::data_type _type{type_id::EMPTY};
314  cudf::size_type _size{};
315  rmm::device_buffer _data{};
316  rmm::device_buffer _null_mask{};
318  mutable cudf::size_type _null_count{UNKNOWN_NULL_COUNT};
320  std::vector<std::unique_ptr<column>> _children{};
321 };
323  // end of group
325 } // namespace cudf
cudf::column
A container of nullable device data as a column of elements.
Definition: column.hpp:45
cudf::column::null_count
size_type null_count() const
Returns the count of null elements.
cudf::size_type
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:84
cudf::column::num_children
size_type num_children() const noexcept
Returns the number of child columns.
Definition: column.hpp:215
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:300
types.hpp
Type declarations for libcudf.
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:448
rmm::cuda_stream_view
rmm::device_buffer::size
std::size_t size() const noexcept
cudf::column::size
size_type size() const noexcept
Returns the number of elements.
Definition: column.hpp:130
rmm::device_buffer
cudf::column::contents
Wrapper for the contents of a column.
Definition: column.hpp:241
cudf::column::mutable_view
mutable_column_view mutable_view()
Creates a mutable, non-owning view of the column's data and children.
device_buffer.hpp
cudf::data_type
Indicator for the logical data type of an element in a column.
Definition: types.hpp:240
cudf::column::column
column(data_type dtype, size_type size, B1 &&data, B2 &&null_mask={}, size_type null_count=UNKNOWN_NULL_COUNT, std::vector< std::unique_ptr< column >> &&children={})
Construct a new column from existing device memory.
Definition: column.hpp:93
cudf::column::set_null_mask
void set_null_mask(rmm::device_buffer &&new_null_mask, size_type new_null_count=UNKNOWN_NULL_COUNT)
Sets the column's null value indicator bitmask to new_null_mask.
cudf::column::child
column & child(size_type child_index) noexcept
Returns a reference to the specified child.
Definition: column.hpp:223
cudf
cuDF interfaces
Definition: aggregation.hpp:34
cudf::column::column
column(column_view view, rmm::cuda_stream_view stream=rmm::cuda_stream_default, rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Construct a new column by deep copying the contents of a column_view.
cudf::column::has_nulls
bool has_nulls() const noexcept
Indicates whether the column contains null elements.
Definition: column.hpp:210
cudf::column::nullable
bool nullable() const noexcept
Indicates whether it is possible for the column to contain null values, i.e., it has an allocated nul...
Definition: column.hpp:202
cudf::column::view
column_view view() const
Creates an immutable, non-owning view of the column's data and children.
null_mask.hpp
APIs for managing validity bitmasks.
cudf::column::set_null_count
void set_null_count(size_type new_null_count)
Updates the count of null elements.
cudf::column::release
contents release() noexcept
Releases ownership of the column's contents.
rmm::mr::device_memory_resource
cudf::column::set_null_mask
void set_null_mask(rmm::device_buffer const &new_null_mask, size_type new_null_count=UNKNOWN_NULL_COUNT, rmm::cuda_stream_view stream=rmm::cuda_stream_view{})
Sets the column's null value indicator bitmask to new_null_mask.
column_view.hpp
column view class definitions
cudf::column::child
column const & child(size_type child_index) const noexcept
Returns a const reference to the specified child.
Definition: column.hpp:231
cudf::column::column
column(column const &other, rmm::cuda_stream_view stream=rmm::cuda_stream_view{}, rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Construct a new column object by deep copying the contents of other.
cudf::column::column
column(column &&other) noexcept
Move the contents from other to create a new column.
cudf::column::type
data_type type() const noexcept
Returns the column's logical element type.
Definition: column.hpp:125