column.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 
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 
57  column(column const& other);
58 
70  column(column const& other,
71  rmm::cuda_stream_view stream,
72  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
73 
81  column(column&& other) noexcept;
82 
99  template <typename B1, typename B2 = rmm::device_buffer>
101  size_type size,
102  B1&& data,
103  B2&& null_mask = {},
104  size_type null_count = UNKNOWN_NULL_COUNT,
105  std::vector<std::unique_ptr<column>>&& children = {})
106  : _type{dtype},
107  _size{size},
108  _data{std::forward<B1>(data)},
109  _null_mask{std::forward<B2>(null_mask)},
110  _null_count{null_count},
111  _children{std::move(children)}
112  {
113  }
114 
126  rmm::cuda_stream_view stream = rmm::cuda_stream_default,
127  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
128 
132  data_type type() const noexcept { return _type; }
133 
137  size_type size() const noexcept { return _size; }
138 
147  size_type null_count() const;
148 
162  void set_null_mask(rmm::device_buffer&& new_null_mask,
163  size_type new_null_count = UNKNOWN_NULL_COUNT);
164 
178  void set_null_mask(rmm::device_buffer const& new_null_mask,
179  size_type new_null_count = UNKNOWN_NULL_COUNT);
180 
192  void set_null_count(size_type new_null_count);
193 
206  bool nullable() const noexcept { return (_null_mask.size() > 0); }
207 
214  bool has_nulls() const noexcept { return (null_count() > 0); }
215 
219  size_type num_children() const noexcept { return _children.size(); }
220 
227  column& child(size_type child_index) noexcept { return *_children[child_index]; };
228 
235  column const& child(size_type child_index) const noexcept { return *_children[child_index]; };
236 
242  struct contents {
243  std::unique_ptr<rmm::device_buffer> data;
244  std::unique_ptr<rmm::device_buffer> null_mask;
245  std::vector<std::unique_ptr<column>> children;
246  };
247 
263  contents release() noexcept;
264 
271  column_view view() const;
272 
281  operator column_view() const { return this->view(); };
282 
296 
311  operator mutable_column_view() { return this->mutable_view(); };
312 
313  private:
314  cudf::data_type _type{type_id::EMPTY};
315  cudf::size_type _size{};
316  rmm::device_buffer _data{};
317  rmm::device_buffer _null_mask{};
319  mutable cudf::size_type _null_count{UNKNOWN_NULL_COUNT};
321  std::vector<std::unique_ptr<column>> _children{};
322 };
324  // end of group
326 } // 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::column::column
column(column const &other, rmm::cuda_stream_view stream, 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::set_null_mask
void set_null_mask(rmm::device_buffer const &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::num_children
size_type num_children() const noexcept
Returns the number of child columns.
Definition: column.hpp:219
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:294
types.hpp
Type declarations for libcudf.
cudf::column::column
column(column const &other)
Construct a new column by deep copying the contents of other.
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:401
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:137
rmm::device_buffer
cudf::column::contents
Wrapper for the contents of a column.
Definition: column.hpp:242
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:243
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:100
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:227
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:214
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:206
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
column_view.hpp
column view class definitons
cudf::column::child
column const & child(size_type child_index) const noexcept
Returns a const reference to the specified child.
Definition: column.hpp:235
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:132