avro.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020-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 
17 #pragma once
18 
19 #include "types.hpp"
20 
22 #include <cudf/types.hpp>
24 
25 #include <memory>
26 #include <string>
27 #include <vector>
28 
29 namespace CUDF_EXPORT cudf {
30 namespace io {
38 
43  source_info _source;
44 
45  // Names of column to read; empty is all
46  std::vector<std::string> _columns;
47 
48  // Rows to skip from the start;
49  size_type _skip_rows = 0;
50  // Rows to read; -1 is all
51  size_type _num_rows = -1;
52 
58  explicit avro_reader_options(source_info src) : _source{std::move(src)} {}
59 
61 
62  public:
68  avro_reader_options() = default;
69 
75  [[nodiscard]] source_info const& get_source() const { return _source; }
76 
82  [[nodiscard]] std::vector<std::string> get_columns() const { return _columns; }
83 
89  [[nodiscard]] size_type get_skip_rows() const { return _skip_rows; }
90 
96  [[nodiscard]] size_type get_num_rows() const { return _num_rows; }
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 
217  avro_reader_options const& options,
219  // end of group
221 } // namespace io
222 } // 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:42
avro_reader_options()=default
Default constructor.
std::vector< std::string > get_columns() const
Returns names of the columns to be read.
Definition: avro.hpp:82
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:96
source_info const & get_source() const
Returns source info.
Definition: avro.hpp:75
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:89
table_with_metadata read_avro(avro_reader_options const &options, 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::async_resource_ref< cuda::mr::device_accessible > device_async_resource_ref
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:95
cuDF interfaces
Definition: aggregation.hpp:35
Source information for read interfaces.
Definition: io/types.hpp:337
Table with table metadata used by io readers to return the metadata by value.
Definition: io/types.hpp:292
Class definitions for (mutable)_table_view
Type declarations for libcudf.