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 <rmm/cuda_stream_view.hpp>
15 
16 #include <cuda/std/utility>
17 
23 namespace CUDF_EXPORT cudf {
37 std::unique_ptr<column> make_empty_column(data_type type);
38 
47 std::unique_ptr<column> make_empty_column(type_id id);
48 
67 std::unique_ptr<column> make_numeric_column(
68  data_type type,
69  size_type size,
70  mask_state state = mask_state::UNALLOCATED,
73 
91 template <typename B>
92 std::unique_ptr<column> make_numeric_column(
93  data_type type,
94  size_type size,
95  B&& null_mask,
99 {
100  CUDF_EXPECTS(is_numeric(type), "Invalid, non-numeric type.");
101  return std::make_unique<column>(type,
102  size,
103  rmm::device_buffer{size * cudf::size_of(type), stream, mr},
104  std::forward<B>(null_mask),
105  null_count);
106 }
107 
125 std::unique_ptr<column> make_fixed_point_column(
126  data_type type,
127  size_type size,
128  mask_state state = mask_state::UNALLOCATED,
131 
148 template <typename B>
149 std::unique_ptr<column> make_fixed_point_column(
150  data_type type,
151  size_type size,
152  B&& null_mask,
156 {
157  CUDF_EXPECTS(is_fixed_point(type), "Invalid, non-fixed_point type.");
158  return std::make_unique<column>(type,
159  size,
160  rmm::device_buffer{size * cudf::size_of(type), stream, mr},
161  std::forward<B>(null_mask),
162  null_count);
163 }
164 
183 std::unique_ptr<column> make_timestamp_column(
184  data_type type,
185  size_type size,
186  mask_state state = mask_state::UNALLOCATED,
189 
207 template <typename B>
208 std::unique_ptr<column> make_timestamp_column(
209  data_type type,
210  size_type size,
211  B&& null_mask,
215 {
216  CUDF_EXPECTS(is_timestamp(type), "Invalid, non-timestamp type.");
217  return std::make_unique<column>(type,
218  size,
219  rmm::device_buffer{size * cudf::size_of(type), stream, mr},
220  std::forward<B>(null_mask),
221  null_count);
222 }
223 
242 std::unique_ptr<column> make_duration_column(
243  data_type type,
244  size_type size,
245  mask_state state = mask_state::UNALLOCATED,
248 
266 template <typename B>
267 std::unique_ptr<column> make_duration_column(
268  data_type type,
269  size_type size,
270  B&& null_mask,
274 {
275  CUDF_EXPECTS(is_duration(type), "Invalid, non-duration type.");
276  return std::make_unique<column>(type,
277  size,
278  rmm::device_buffer{size * cudf::size_of(type), stream, mr},
279  std::forward<B>(null_mask),
280  null_count);
281 }
282 
301 std::unique_ptr<column> make_fixed_width_column(
302  data_type type,
303  size_type size,
304  mask_state state = mask_state::UNALLOCATED,
307 
325 template <typename B>
326 std::unique_ptr<column> make_fixed_width_column(
327  data_type type,
328  size_type size,
329  B&& null_mask,
333 {
334  CUDF_EXPECTS(is_fixed_width(type), "Invalid, non-fixed-width type.");
335  if (is_timestamp(type)) {
336  return make_timestamp_column(type, size, std::forward<B>(null_mask), null_count, stream, mr);
337  } else if (is_duration(type)) {
338  return make_duration_column(type, size, std::forward<B>(null_mask), null_count, stream, mr);
339  } else if (is_fixed_point(type)) {
340  return make_fixed_point_column(type, size, std::forward<B>(null_mask), null_count, stream, mr);
341  }
342  return make_numeric_column(type, size, std::forward<B>(null_mask), null_count, stream, mr);
343 }
344 
368 std::unique_ptr<column> make_strings_column(
369  cudf::device_span<cuda::std::pair<char const*, size_type> const> strings,
372 
388 std::vector<std::unique_ptr<column>> make_strings_column_batch(
389  std::vector<cudf::device_span<cuda::std::pair<char const*, size_type> const>> const& input,
392 
419 std::unique_ptr<column> make_strings_column(
421  string_view const null_placeholder,
424 
442 std::unique_ptr<column> make_strings_column(size_type num_strings,
443  std::unique_ptr<column> offsets_column,
444  rmm::device_buffer&& chars_buffer,
446  rmm::device_buffer&& null_mask);
447 
498 std::unique_ptr<cudf::column> make_lists_column(size_type num_rows,
499  std::unique_ptr<column> offsets_column,
500  std::unique_ptr<column> child_column,
502  rmm::device_buffer&& null_mask);
503 
512 std::unique_ptr<column> make_empty_lists_column(data_type child_type);
513 
537 std::unique_ptr<cudf::column> make_structs_column(
538  size_type num_rows,
539  std::vector<std::unique_ptr<column>>&& child_columns,
541  rmm::device_buffer&& null_mask,
544 
571 std::unique_ptr<cudf::column> create_structs_hierarchy(
572  size_type num_rows,
573  std::vector<std::unique_ptr<column>>&& child_columns,
575  rmm::device_buffer&& null_mask,
578 
593 std::unique_ptr<column> make_column_from_scalar(
594  scalar const& s,
595  size_type size,
598 
613 std::unique_ptr<column> make_dictionary_from_scalar(
614  scalar const& s,
615  size_type size,
618  // end of group
620 } // namespace CUDF_EXPORT cudf
Indicator for the logical data type of an element in a column.
Definition: types.hpp:286
An owning class to represent a singular value.
Definition: scalar.hpp:41
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::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_empty_lists_column(data_type child_type)
Create an empty LIST column.
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_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::vector< std::unique_ptr< column > > make_strings_column_batch(std::vector< cudf::device_span< cuda::std::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_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...
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.
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::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:182
cuda::std::span< T, Extent > device_span
Device span is an alias of cuda::std::span.
Definition: span.hpp:296
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: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:192
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:26
APIs for spans.
Type traits for classifying and querying properties of cudf column and scalar types.
Type declarations for libcudf.