avro.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020-2023, 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>
23 
25 
26 #include <memory>
27 #include <string>
28 #include <vector>
29 
30 namespace cudf {
31 namespace io {
38 class avro_reader_options_builder;
39 
44  source_info _source;
45 
46  // Names of column to read; empty is all
47  std::vector<std::string> _columns;
48 
49  // Rows to skip from the start;
50  size_type _skip_rows = 0;
51  // Rows to read; -1 is all
52  size_type _num_rows = -1;
53 
59  explicit avro_reader_options(source_info src) : _source{std::move(src)} {}
60 
62 
63  public:
69  avro_reader_options() = default;
70 
76  [[nodiscard]] source_info const& get_source() const { return _source; }
77 
83  [[nodiscard]] std::vector<std::string> get_columns() const { return _columns; }
84 
90  [[nodiscard]] size_type get_skip_rows() const { return _skip_rows; }
91 
97  [[nodiscard]] size_type get_num_rows() const { return _num_rows; }
98 
104  void set_columns(std::vector<std::string> col_names) { _columns = std::move(col_names); }
105 
111  void set_skip_rows(size_type val) { _skip_rows = val; }
112 
118  void set_num_rows(size_type val) { _num_rows = val; }
119 
127 };
128 
133  avro_reader_options options;
134 
135  public:
142 
148  explicit avro_reader_options_builder(source_info src) : options{std::move(src)} {}
149 
156  avro_reader_options_builder& columns(std::vector<std::string> col_names)
157  {
158  options._columns = std::move(col_names);
159  return *this;
160  }
161 
169  {
170  options._skip_rows = val;
171  return *this;
172  }
173 
181  {
182  options._num_rows = val;
183  return *this;
184  }
185 
189  operator avro_reader_options&&() { return std::move(options); }
190 
198  avro_reader_options&& build() { return std::move(options); }
199 };
200 
218  avro_reader_options const& options,
220  // end of group
222 } // namespace io
223 } // namespace cudf
Builder to build options for read_avro().
Definition: avro.hpp:132
avro_reader_options_builder()=default
Default constructor.
avro_reader_options_builder(source_info src)
Constructor from source info.
Definition: avro.hpp:148
avro_reader_options_builder & columns(std::vector< std::string > col_names)
Set names of the column to be read.
Definition: avro.hpp:156
avro_reader_options_builder & num_rows(size_type val)
Sets number of rows to read.
Definition: avro.hpp:180
avro_reader_options_builder & skip_rows(size_type val)
Sets number of rows to skip.
Definition: avro.hpp:168
avro_reader_options && build()
move avro_reader_options member once it's built.
Definition: avro.hpp:198
Settings to use for read_avro().
Definition: avro.hpp:43
avro_reader_options()=default
Default constructor.
std::vector< std::string > get_columns() const
Returns names of the columns to be read.
Definition: avro.hpp:83
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:111
size_type get_num_rows() const
Returns number of rows to read.
Definition: avro.hpp:97
source_info const & get_source() const
Returns source info.
Definition: avro.hpp:76
void set_columns(std::vector< std::string > col_names)
Set names of the column to be read.
Definition: avro.hpp:104
void set_num_rows(size_type val)
Sets number of rows to read.
Definition: avro.hpp:118
size_type get_skip_rows() const
Returns number of rows to skip from the start.
Definition: avro.hpp:90
table_with_metadata read_avro(avro_reader_options const &options, rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Reads an Avro dataset into a set of columns.
device_memory_resource * get_current_device_resource()
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:93
cuDF interfaces
Definition: aggregation.hpp:34
Source information for read interfaces.
Definition: io/types.hpp:294
Table with table metadata used by io readers to return the metadata by value.
Definition: io/types.hpp:249
Class definitions for (mutable)_table_view
Type declarations for libcudf.