avro.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 
8 #include "types.hpp"
9 
11 #include <cudf/types.hpp>
13 
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
23 namespace CUDF_EXPORT cudf {
24 namespace io {
31 
36  source_info _source;
37 
38  // Names of column to read; empty is all
39  std::vector<std::string> _columns;
40 
41  // Rows to skip from the start;
42  size_type _skip_rows = 0;
43  // Rows to read; -1 is all
44  size_type _num_rows = -1;
45 
51  explicit avro_reader_options(source_info src) : _source{std::move(src)} {}
52 
54 
55  public:
61  avro_reader_options() = default;
62 
68  [[nodiscard]] source_info const& get_source() const { return _source; }
69 
75  [[nodiscard]] std::vector<std::string> get_columns() const { return _columns; }
76 
82  [[nodiscard]] size_type get_skip_rows() const { return _skip_rows; }
83 
89  [[nodiscard]] size_type get_num_rows() const { return _num_rows; }
90 
96  void set_source(source_info src) { _source = std::move(src); }
97 
103  void set_columns(std::vector<std::string> col_names) { _columns = std::move(col_names); }
104 
110  void set_skip_rows(size_type val) { _skip_rows = val; }
111 
117  void set_num_rows(size_type val) { _num_rows = val; }
118 
126 };
127 
132  avro_reader_options options;
133 
134  public:
141 
147  explicit avro_reader_options_builder(source_info src) : options{std::move(src)} {}
148 
155  avro_reader_options_builder& columns(std::vector<std::string> col_names)
156  {
157  options._columns = std::move(col_names);
158  return *this;
159  }
160 
168  {
169  options._skip_rows = val;
170  return *this;
171  }
172 
180  {
181  options._num_rows = val;
182  return *this;
183  }
184 
188  operator avro_reader_options&&() { return std::move(options); }
189 
197  avro_reader_options&& build() { return std::move(options); }
198 };
199 
218  avro_reader_options const& options,
221  // end of group
223 } // namespace io
224 } // namespace CUDF_EXPORT cudf
Builder to build options for read_avro().
Definition: avro.hpp:131
avro_reader_options_builder()=default
Default constructor.
avro_reader_options_builder(source_info src)
Constructor from source info.
Definition: avro.hpp:147
avro_reader_options_builder & columns(std::vector< std::string > col_names)
Set names of the column to be read.
Definition: avro.hpp:155
avro_reader_options_builder & num_rows(size_type val)
Sets number of rows to read.
Definition: avro.hpp:179
avro_reader_options_builder & skip_rows(size_type val)
Sets number of rows to skip.
Definition: avro.hpp:167
avro_reader_options && build()
move avro_reader_options member once it's built.
Definition: avro.hpp:197
Settings to use for read_avro().
Definition: avro.hpp:35
void set_source(source_info src)
Sets source info.
Definition: avro.hpp:96
avro_reader_options()=default
Default constructor.
std::vector< std::string > get_columns() const
Returns names of the columns to be read.
Definition: avro.hpp:75
static avro_reader_options_builder builder(source_info src)
create avro_reader_options_builder which will build avro_reader_options.
void set_skip_rows(size_type val)
Sets number of rows to skip.
Definition: avro.hpp:110
size_type get_num_rows() const
Returns number of rows to read.
Definition: avro.hpp:89
source_info const & get_source() const
Returns source info.
Definition: avro.hpp:68
void set_columns(std::vector< std::string > col_names)
Set names of the column to be read.
Definition: avro.hpp:103
void set_num_rows(size_type val)
Sets number of rows to read.
Definition: avro.hpp:117
size_type get_skip_rows() const
Returns number of rows to skip from the start.
Definition: avro.hpp:82
rmm::cuda_stream_view const get_default_stream()
Get the current default stream.
table_with_metadata read_avro(avro_reader_options const &options, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Reads an Avro dataset into a set of columns.
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
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:84
APIs for getting and setting the current device memory resource.
cuDF interfaces
Definition: host_udf.hpp:26
Source information for read interfaces.
Definition: types.hpp:306
Table with table metadata used by io readers to return the metadata by value.
Definition: types.hpp:271
Class definitions for (mutable)_table_view
Type declarations for libcudf.