column_factories.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
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 <cuda/std/utility>
15 #include <cuda/stream>
16 
22 namespace CUDF_EXPORT cudf {
36 std::unique_ptr<column> make_empty_column(data_type type);
37 
46 std::unique_ptr<column> make_empty_column(type_id id);
47 
66 std::unique_ptr<column> make_numeric_column(
67  data_type type,
68  size_type size,
69  mask_state state = mask_state::UNALLOCATED,
70  cuda::stream_ref stream = cudf::get_default_stream(),
72 
90 template <typename B>
91 std::unique_ptr<column> make_numeric_column(
92  data_type type,
93  size_type size,
94  B&& null_mask,
96  cuda::stream_ref stream = cudf::get_default_stream(),
98 {
99  CUDF_EXPECTS(is_numeric(type), "Invalid, non-numeric type.");
100  return std::make_unique<column>(type,
101  size,
102  rmm::device_buffer{size * cudf::size_of(type), stream, mr},
103  std::forward<B>(null_mask),
104  null_count);
105 }
106 
124 std::unique_ptr<column> make_fixed_point_column(
125  data_type type,
126  size_type size,
127  mask_state state = mask_state::UNALLOCATED,
128  cuda::stream_ref stream = cudf::get_default_stream(),
130 
147 template <typename B>
148 std::unique_ptr<column> make_fixed_point_column(
149  data_type type,
150  size_type size,
151  B&& null_mask,
153  cuda::stream_ref stream = cudf::get_default_stream(),
155 {
156  CUDF_EXPECTS(is_fixed_point(type), "Invalid, non-fixed_point type.");
157  return std::make_unique<column>(type,
158  size,
159  rmm::device_buffer{size * cudf::size_of(type), stream, mr},
160  std::forward<B>(null_mask),
161  null_count);
162 }
163 
182 std::unique_ptr<column> make_timestamp_column(
183  data_type type,
184  size_type size,
185  mask_state state = mask_state::UNALLOCATED,
186  cuda::stream_ref stream = cudf::get_default_stream(),
188 
206 template <typename B>
207 std::unique_ptr<column> make_timestamp_column(
208  data_type type,
209  size_type size,
210  B&& null_mask,
212  cuda::stream_ref stream = cudf::get_default_stream(),
214 {
215  CUDF_EXPECTS(is_timestamp(type), "Invalid, non-timestamp type.");
216  return std::make_unique<column>(type,
217  size,
218  rmm::device_buffer{size * cudf::size_of(type), stream, mr},
219  std::forward<B>(null_mask),
220  null_count);
221 }
222 
241 std::unique_ptr<column> make_duration_column(
242  data_type type,
243  size_type size,
244  mask_state state = mask_state::UNALLOCATED,
245  cuda::stream_ref stream = cudf::get_default_stream(),
247 
265 template <typename B>
266 std::unique_ptr<column> make_duration_column(
267  data_type type,
268  size_type size,
269  B&& null_mask,
271  cuda::stream_ref stream = cudf::get_default_stream(),
273 {
274  CUDF_EXPECTS(is_duration(type), "Invalid, non-duration type.");
275  return std::make_unique<column>(type,
276  size,
277  rmm::device_buffer{size * cudf::size_of(type), stream, mr},
278  std::forward<B>(null_mask),
279  null_count);
280 }
281 
300 std::unique_ptr<column> make_fixed_width_column(
301  data_type type,
302  size_type size,
303  mask_state state = mask_state::UNALLOCATED,
304  cuda::stream_ref stream = cudf::get_default_stream(),
306 
324 template <typename B>
325 std::unique_ptr<column> make_fixed_width_column(
326  data_type type,
327  size_type size,
328  B&& null_mask,
330  cuda::stream_ref stream = cudf::get_default_stream(),
332 {
333  CUDF_EXPECTS(is_fixed_width(type), "Invalid, non-fixed-width type.");
334  if (is_timestamp(type)) {
335  return make_timestamp_column(type, size, std::forward<B>(null_mask), null_count, stream, mr);
336  } else if (is_duration(type)) {
337  return make_duration_column(type, size, std::forward<B>(null_mask), null_count, stream, mr);
338  } else if (is_fixed_point(type)) {
339  return make_fixed_point_column(type, size, std::forward<B>(null_mask), null_count, stream, mr);
340  }
341  return make_numeric_column(type, size, std::forward<B>(null_mask), null_count, stream, mr);
342 }
343 
367 std::unique_ptr<column> make_strings_column(
368  cudf::device_span<cuda::std::pair<char const*, size_type> const> strings,
369  cuda::stream_ref stream = cudf::get_default_stream(),
371 
387 std::vector<std::unique_ptr<column>> make_strings_column_batch(
388  std::vector<cudf::device_span<cuda::std::pair<char const*, size_type> const>> const& input,
389  cuda::stream_ref stream = cudf::get_default_stream(),
391 
418 std::unique_ptr<column> make_strings_column(
420  string_view const null_placeholder,
421  cuda::stream_ref stream = cudf::get_default_stream(),
423 
441 std::unique_ptr<column> make_strings_column(size_type num_strings,
442  std::unique_ptr<column> offsets_column,
443  rmm::device_buffer&& chars_buffer,
445  rmm::device_buffer&& null_mask);
446 
500 std::unique_ptr<cudf::column> make_lists_column(size_type num_rows,
501  std::unique_ptr<column> offsets_column,
502  std::unique_ptr<column> child_column,
504  rmm::device_buffer&& null_mask);
505 
514 std::unique_ptr<column> make_empty_lists_column(data_type child_type);
515 
539 std::unique_ptr<cudf::column> make_structs_column(
540  size_type num_rows,
541  std::vector<std::unique_ptr<column>>&& child_columns,
543  rmm::device_buffer&& null_mask,
544  cuda::stream_ref stream = cudf::get_default_stream(),
546 
573 std::unique_ptr<cudf::column> create_structs_hierarchy(
574  size_type num_rows,
575  std::vector<std::unique_ptr<column>>&& child_columns,
577  rmm::device_buffer&& null_mask,
578  cuda::stream_ref stream = cudf::get_default_stream(),
580 
595 std::unique_ptr<column> make_column_from_scalar(
596  scalar const& s,
597  size_type size,
598  cuda::stream_ref stream = cudf::get_default_stream(),
600 
615 std::unique_ptr<column> make_dictionary_from_scalar(
616  scalar const& s,
617  size_type size,
618  cuda::stream_ref stream = cudf::get_default_stream(),
620  // end of group
622 } // namespace CUDF_EXPORT cudf
Indicator for the logical data type of an element in a column.
Definition: types.hpp:279
An owning class to represent a singular value.
Definition: scalar.hpp:42
A non-owning, immutable view of device data that is a variable length char array representing a UTF-8...
Definition: string_view.hpp:35
Class definition for cudf::column.
APIs for querying the default CUDA stream and per-thread default stream status.
std::vector< std::unique_ptr< column > > make_strings_column_batch(std::vector< cudf::device_span< cuda::std::pair< char const *, size_type > const >> const &input, cuda::stream_ref 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< 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, cuda::stream_ref 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_duration_column(data_type type, size_type size, B &&null_mask, size_type null_count, cuda::stream_ref 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< 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, cuda::stream_ref 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_empty_lists_column(data_type child_type)
Create an empty LIST column.
std::unique_ptr< column > make_fixed_width_column(data_type type, size_type size, B &&null_mask, size_type null_count, cuda::stream_ref 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< column > make_column_from_scalar(scalar const &s, size_type size, cuda::stream_ref 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_fixed_point_column(data_type type, size_type size, B &&null_mask, size_type null_count, cuda::stream_ref 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...
std::unique_ptr< column > make_numeric_column(data_type type, size_type size, B &&null_mask, size_type null_count, cuda::stream_ref 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_empty_column(type_id id)
Creates an empty column of the specified type.
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_dictionary_from_scalar(scalar const &s, size_type size, cuda::stream_ref 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 > 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)
Construct a LIST type column given offsets column, child column, null mask and null count.
std::unique_ptr< column > make_timestamp_column(data_type type, size_type size, B &&null_mask, size_type null_count, cuda::stream_ref 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...
size_type null_count(bitmask_type const *bitmask, size_type start, size_type stop, cuda::stream_ref stream=cudf::get_default_stream())
Given a validity bitmask, counts the number of null elements (unset bits) in the range [start,...
cuda::stream_ref 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::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, cuda::stream_ref 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}, cuda::stream_ref 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:182
cuda::std::span< T, Extent > device_span
Device span is an alias of cuda::std::span.
Definition: span.hpp:300
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:76
mask_state
Controls the allocation/initialization of a null mask.
Definition: types.hpp:162
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:584
constexpr CUDF_HOST_DEVICE bool is_duration()
Indicates whether the type T is a duration type.
Definition: traits.hpp:470
type_id
Identifies a column's logical element type.
Definition: types.hpp:185
constexpr CUDF_HOST_DEVICE bool is_numeric()
Indicates whether the type T is a numeric type.
Definition: traits.hpp:173
APIs for getting and setting the current device memory resource.
cuDF interfaces
Definition: host_udf.hpp:27
APIs for spans.
Type traits for classifying and querying properties of cudf column and scalar types.
Type declarations for libcudf.