column_factories.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>
19 #include <cudf/types.hpp>
22 #include <cudf/utilities/span.hpp>
24 
25 #include <rmm/cuda_stream_view.hpp>
26 
27 #include <thrust/pair.h>
28 
29 namespace CUDF_EXPORT cudf {
45 std::unique_ptr<column> make_empty_column(data_type type);
46 
55 std::unique_ptr<column> make_empty_column(type_id id);
56 
75 std::unique_ptr<column> make_numeric_column(
76  data_type type,
77  size_type size,
78  mask_state state = mask_state::UNALLOCATED,
81 
99 template <typename B>
100 std::unique_ptr<column> make_numeric_column(
101  data_type type,
102  size_type size,
103  B&& null_mask,
107 {
108  CUDF_EXPECTS(is_numeric(type), "Invalid, non-numeric type.");
109  return std::make_unique<column>(type,
110  size,
111  rmm::device_buffer{size * cudf::size_of(type), stream, mr},
112  std::forward<B>(null_mask),
113  null_count);
114 }
115 
133 std::unique_ptr<column> make_fixed_point_column(
134  data_type type,
135  size_type size,
136  mask_state state = mask_state::UNALLOCATED,
139 
156 template <typename B>
157 std::unique_ptr<column> make_fixed_point_column(
158  data_type type,
159  size_type size,
160  B&& null_mask,
164 {
165  CUDF_EXPECTS(is_fixed_point(type), "Invalid, non-fixed_point type.");
166  return std::make_unique<column>(type,
167  size,
168  rmm::device_buffer{size * cudf::size_of(type), stream, mr},
169  std::forward<B>(null_mask),
170  null_count);
171 }
172 
191 std::unique_ptr<column> make_timestamp_column(
192  data_type type,
193  size_type size,
194  mask_state state = mask_state::UNALLOCATED,
197 
215 template <typename B>
216 std::unique_ptr<column> make_timestamp_column(
217  data_type type,
218  size_type size,
219  B&& null_mask,
223 {
224  CUDF_EXPECTS(is_timestamp(type), "Invalid, non-timestamp type.");
225  return std::make_unique<column>(type,
226  size,
227  rmm::device_buffer{size * cudf::size_of(type), stream, mr},
228  std::forward<B>(null_mask),
229  null_count);
230 }
231 
250 std::unique_ptr<column> make_duration_column(
251  data_type type,
252  size_type size,
253  mask_state state = mask_state::UNALLOCATED,
256 
274 template <typename B>
275 std::unique_ptr<column> make_duration_column(
276  data_type type,
277  size_type size,
278  B&& null_mask,
282 {
283  CUDF_EXPECTS(is_duration(type), "Invalid, non-duration type.");
284  return std::make_unique<column>(type,
285  size,
286  rmm::device_buffer{size * cudf::size_of(type), stream, mr},
287  std::forward<B>(null_mask),
288  null_count);
289 }
290 
309 std::unique_ptr<column> make_fixed_width_column(
310  data_type type,
311  size_type size,
312  mask_state state = mask_state::UNALLOCATED,
315 
333 template <typename B>
334 std::unique_ptr<column> make_fixed_width_column(
335  data_type type,
336  size_type size,
337  B&& null_mask,
341 {
342  CUDF_EXPECTS(is_fixed_width(type), "Invalid, non-fixed-width type.");
343  if (is_timestamp(type)) {
344  return make_timestamp_column(type, size, std::forward<B>(null_mask), null_count, stream, mr);
345  } else if (is_duration(type)) {
346  return make_duration_column(type, size, std::forward<B>(null_mask), null_count, stream, mr);
347  } else if (is_fixed_point(type)) {
348  return make_fixed_point_column(type, size, std::forward<B>(null_mask), null_count, stream, mr);
349  }
350  return make_numeric_column(type, size, std::forward<B>(null_mask), null_count, stream, mr);
351 }
352 
376 std::unique_ptr<column> make_strings_column(
377  cudf::device_span<thrust::pair<char const*, size_type> const> strings,
380 
407 std::unique_ptr<column> make_strings_column(
409  string_view const null_placeholder,
412 
430 std::unique_ptr<column> make_strings_column(size_type num_strings,
431  std::unique_ptr<column> offsets_column,
432  rmm::device_buffer&& chars_buffer,
434  rmm::device_buffer&& null_mask);
435 
492 std::unique_ptr<cudf::column> make_lists_column(
493  size_type num_rows,
494  std::unique_ptr<column> offsets_column,
495  std::unique_ptr<column> child_column,
497  rmm::device_buffer&& null_mask,
500 
524 std::unique_ptr<cudf::column> make_structs_column(
525  size_type num_rows,
526  std::vector<std::unique_ptr<column>>&& child_columns,
528  rmm::device_buffer&& null_mask,
531 
546 std::unique_ptr<column> make_column_from_scalar(
547  scalar const& s,
548  size_type size,
551 
566 std::unique_ptr<column> make_dictionary_from_scalar(
567  scalar const& s,
568  size_type size,
571  // end of group
573 } // namespace CUDF_EXPORT cudf
Indicator for the logical data type of an element in a column.
Definition: types.hpp:243
An owning class to represent a singular value.
Definition: scalar.hpp:48
A non-owning, immutable view of device data that is a variable length char array representing a UTF-8...
Definition: string_view.hpp:44
Class definition for cudf::column.
std::unique_ptr< column > make_fixed_width_column(data_type type, size_type size, B &&null_mask, size_type null_count, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Construct column with sufficient uninitialized storage to hold size elements of the specified fixed w...
std::unique_ptr< cudf::column > make_structs_column(size_type num_rows, std::vector< std::unique_ptr< column >> &&child_columns, size_type null_count, rmm::device_buffer &&null_mask, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Construct a STRUCT column using specified child columns as members.
std::unique_ptr< column > make_dictionary_from_scalar(scalar const &s, size_type size, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Construct a dictionary column with size elements that are all equal to the given scalar.
std::unique_ptr< column > make_numeric_column(data_type type, size_type size, B &&null_mask, size_type null_count, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Construct column with sufficient uninitialized storage to hold size elements of the specified numeric...
std::unique_ptr< column > make_duration_column(data_type type, size_type size, B &&null_mask, size_type null_count, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Construct column with sufficient uninitialized storage to hold size elements of the specified duratio...
std::unique_ptr< column > make_timestamp_column(data_type type, size_type size, B &&null_mask, size_type null_count, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Construct column with sufficient uninitialized storage to hold size elements of the specified timesta...
std::unique_ptr< column > make_empty_column(type_id id)
Creates an empty column of the specified type.
std::unique_ptr< cudf::column > make_lists_column(size_type num_rows, std::unique_ptr< column > offsets_column, std::unique_ptr< column > child_column, size_type null_count, rmm::device_buffer &&null_mask, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Construct a LIST type column given offsets column, child column, null mask and null count.
std::unique_ptr< column > make_column_from_scalar(scalar const &s, size_type size, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Construct a column with size elements that are all equal to the given scalar.
std::unique_ptr< column > make_strings_column(size_type num_strings, std::unique_ptr< column > offsets_column, rmm::device_buffer &&chars_buffer, size_type null_count, rmm::device_buffer &&null_mask)
Construct a STRING type column given offsets column, chars columns, and null mask and null count.
std::unique_ptr< column > make_fixed_point_column(data_type type, size_type size, B &&null_mask, size_type null_count, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Construct column with sufficient uninitialized storage to hold size elements of the specified fixed_p...
cudf::size_type null_count(bitmask_type const *bitmask, size_type start, size_type stop, rmm::cuda_stream_view stream=cudf::get_default_stream())
Given a validity bitmask, counts the number of null elements (unset bits) in the range [start,...
rmm::cuda_stream_view const get_default_stream()
Get the current default stream.
rmm::device_async_resource_ref get_current_device_resource_ref()
Get the current device memory resource reference.
cuda::mr::async_resource_ref< cuda::mr::device_accessible > device_async_resource_ref
std::unique_ptr< column > is_timestamp(strings_column_view const &input, std::string_view format, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Verifies the given strings column can be parsed to timestamps using the provided format pattern.
std::unique_ptr< column > is_fixed_point(strings_column_view const &input, data_type decimal_type=data_type{type_id::DECIMAL64}, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Returns a boolean column identifying strings in which all characters are valid for conversion to fixe...
#define CUDF_EXPECTS(...)
Macro for checking (pre-)conditions that throws an exception when a condition is violated.
Definition: error.hpp:178
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:95
mask_state
Controls the allocation/initialization of a null mask.
Definition: types.hpp:181
constexpr bool is_duration()
Indicates whether the type T is a duration type.
Definition: traits.hpp:423
std::size_t size_of(data_type t)
Returns the size in bytes of elements of the specified data_type
constexpr bool is_numeric()
Indicates whether the type T is a numeric type.
Definition: traits.hpp:174
constexpr bool is_fixed_width()
Indicates whether elements of type T are fixed-width.
Definition: traits.hpp:515
type_id
Identifies a column's logical element type.
Definition: types.hpp:203
cuDF interfaces
Definition: aggregation.hpp:35
APIs for spans.
Device version of C++20 std::span with reduced feature set.
Definition: span.hpp:328
Type declarations for libcudf.