column_factories.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2019-2025, NVIDIA CORPORATION.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #pragma once
6 
7 #include <cudf/column/column.hpp>
8 #include <cudf/types.hpp>
11 #include <cudf/utilities/span.hpp>
13 
14 #include <rmm/cuda_stream_view.hpp>
15 
16 namespace CUDF_EXPORT cudf {
32 std::unique_ptr<column> make_empty_column(data_type type);
33 
42 std::unique_ptr<column> make_empty_column(type_id id);
43 
62 std::unique_ptr<column> make_numeric_column(
63  data_type type,
64  size_type size,
65  mask_state state = mask_state::UNALLOCATED,
68 
86 template <typename B>
87 std::unique_ptr<column> make_numeric_column(
88  data_type type,
89  size_type size,
90  B&& null_mask,
94 {
95  CUDF_EXPECTS(is_numeric(type), "Invalid, non-numeric type.");
96  return std::make_unique<column>(type,
97  size,
98  rmm::device_buffer{size * cudf::size_of(type), stream, mr},
99  std::forward<B>(null_mask),
100  null_count);
101 }
102 
120 std::unique_ptr<column> make_fixed_point_column(
121  data_type type,
122  size_type size,
123  mask_state state = mask_state::UNALLOCATED,
126 
143 template <typename B>
144 std::unique_ptr<column> make_fixed_point_column(
145  data_type type,
146  size_type size,
147  B&& null_mask,
151 {
152  CUDF_EXPECTS(is_fixed_point(type), "Invalid, non-fixed_point type.");
153  return std::make_unique<column>(type,
154  size,
155  rmm::device_buffer{size * cudf::size_of(type), stream, mr},
156  std::forward<B>(null_mask),
157  null_count);
158 }
159 
178 std::unique_ptr<column> make_timestamp_column(
179  data_type type,
180  size_type size,
181  mask_state state = mask_state::UNALLOCATED,
184 
202 template <typename B>
203 std::unique_ptr<column> make_timestamp_column(
204  data_type type,
205  size_type size,
206  B&& null_mask,
210 {
211  CUDF_EXPECTS(is_timestamp(type), "Invalid, non-timestamp type.");
212  return std::make_unique<column>(type,
213  size,
214  rmm::device_buffer{size * cudf::size_of(type), stream, mr},
215  std::forward<B>(null_mask),
216  null_count);
217 }
218 
237 std::unique_ptr<column> make_duration_column(
238  data_type type,
239  size_type size,
240  mask_state state = mask_state::UNALLOCATED,
243 
261 template <typename B>
262 std::unique_ptr<column> make_duration_column(
263  data_type type,
264  size_type size,
265  B&& null_mask,
269 {
270  CUDF_EXPECTS(is_duration(type), "Invalid, non-duration type.");
271  return std::make_unique<column>(type,
272  size,
273  rmm::device_buffer{size * cudf::size_of(type), stream, mr},
274  std::forward<B>(null_mask),
275  null_count);
276 }
277 
296 std::unique_ptr<column> make_fixed_width_column(
297  data_type type,
298  size_type size,
299  mask_state state = mask_state::UNALLOCATED,
302 
320 template <typename B>
321 std::unique_ptr<column> make_fixed_width_column(
322  data_type type,
323  size_type size,
324  B&& null_mask,
328 {
329  CUDF_EXPECTS(is_fixed_width(type), "Invalid, non-fixed-width type.");
330  if (is_timestamp(type)) {
331  return make_timestamp_column(type, size, std::forward<B>(null_mask), null_count, stream, mr);
332  } else if (is_duration(type)) {
333  return make_duration_column(type, size, std::forward<B>(null_mask), null_count, stream, mr);
334  } else if (is_fixed_point(type)) {
335  return make_fixed_point_column(type, size, std::forward<B>(null_mask), null_count, stream, mr);
336  }
337  return make_numeric_column(type, size, std::forward<B>(null_mask), null_count, stream, mr);
338 }
339 
363 std::unique_ptr<column> make_strings_column(
364  cudf::device_span<thrust::pair<char const*, size_type> const> strings,
367 
383 std::vector<std::unique_ptr<column>> make_strings_column_batch(
384  std::vector<cudf::device_span<thrust::pair<char const*, size_type> const>> const& input,
387 
414 std::unique_ptr<column> make_strings_column(
416  string_view const null_placeholder,
419 
437 std::unique_ptr<column> make_strings_column(size_type num_strings,
438  std::unique_ptr<column> offsets_column,
439  rmm::device_buffer&& chars_buffer,
441  rmm::device_buffer&& null_mask);
442 
499 std::unique_ptr<cudf::column> make_lists_column(
500  size_type num_rows,
501  std::unique_ptr<column> offsets_column,
502  std::unique_ptr<column> child_column,
504  rmm::device_buffer&& null_mask,
507 
518 std::unique_ptr<column> make_empty_lists_column(
519  data_type child_type,
522 
546 std::unique_ptr<cudf::column> make_structs_column(
547  size_type num_rows,
548  std::vector<std::unique_ptr<column>>&& child_columns,
550  rmm::device_buffer&& null_mask,
553 
580 std::unique_ptr<cudf::column> create_structs_hierarchy(
581  size_type num_rows,
582  std::vector<std::unique_ptr<column>>&& child_columns,
584  rmm::device_buffer&& null_mask,
587 
602 std::unique_ptr<column> make_column_from_scalar(
603  scalar const& s,
604  size_type size,
607 
622 std::unique_ptr<column> make_dictionary_from_scalar(
623  scalar const& s,
624  size_type size,
627  // end of group
629 } // namespace CUDF_EXPORT cudf
Indicator for the logical data type of an element in a column.
Definition: types.hpp:238
An owning class to represent a singular value.
Definition: scalar.hpp:40
A non-owning, immutable view of device data that is a variable length char array representing a UTF-8...
Definition: string_view.hpp:33
Class definition for cudf::column.
std::vector< std::unique_ptr< column > > make_strings_column_batch(std::vector< cudf::device_span< thrust::pair< char const *, size_type > const >> const &input, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Construct a batch of STRING type columns given an array of device spans of pointer/size pairs.
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< cudf::column > create_structs_hierarchy(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_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< column > make_empty_lists_column(data_type child_type, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Create an empty LIST column.
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.
detail::cccl_async_resource_ref< cuda::mr::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:143
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:84
mask_state
Controls the allocation/initialization of a null mask.
Definition: types.hpp:170
std::size_t size_of(data_type t)
Returns the size in bytes of elements of the specified data_type
constexpr CUDF_HOST_DEVICE bool is_fixed_width()
Indicates whether elements of type T are fixed-width.
Definition: traits.hpp:558
constexpr CUDF_HOST_DEVICE bool is_duration()
Indicates whether the type T is a duration type.
Definition: traits.hpp:466
type_id
Identifies a column's logical element type.
Definition: types.hpp:192
constexpr CUDF_HOST_DEVICE bool is_numeric()
Indicates whether the type T is a numeric type.
Definition: traits.hpp:169
cuDF interfaces
Definition: host_udf.hpp:26
APIs for spans.
Device version of C++20 std::span with reduced feature set.
Definition: span.hpp:323
Type declarations for libcudf.