avro.hpp
查看此文件的文档。
1 /*
2  * Copyright (c) 2020-2025, 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  * https://apache.ac.cn/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 {
37 /// @brief 用于构建 read_avro() 选项的构建器。
42 /// @brief 用于 read_avro() 的设置。
43 class avro_reader_options {
44  source_info _source;
45 
46  // 要读取的列名;为空表示所有列
47  std::vector<std::string> _columns;
48 
49  // 从开始跳过的行数;
50  size_type _skip_rows = 0;
51  // 要读取的行数;-1 表示所有行
52  size_type _num_rows = -1;
58  /// @brief 构造函数。
59  explicit avro_reader_options(source_info src) : _source{std::move(src)} {}
60 
62 
68  /// @brief 默认构造函数。
69  avro_reader_options() = default;
75  /// @brief 返回源信息。
76  [[nodiscard]] source_info const& get_source() const { return _source; }
82  /// @brief 返回要读取的列名。
83  [[nodiscard]] std::vector<std::string> get_columns() const { return _columns; }
89  /// @brief 返回从开始跳过的行数。
90  [[nodiscard]] size_type get_skip_rows() const { return _skip_rows; }
96  /// @brief 返回要读取的行数。
97  [[nodiscard]] size_type get_num_rows() const { return _num_rows; }
103  /// @brief 设置要读取的列名。
104  void set_columns(std::vector<std::string> col_names) { _columns = std::move(col_names); }
110  /// @brief 设置要跳过的行数。
111  void set_skip_rows(size_type val) { _skip_rows = val; }
117  /// @brief 设置要读取的行数。
118  void set_num_rows(size_type val) { _num_rows = val; }
125  /// @brief 创建将构建 avro_reader_options 的 avro_reader_options_builder。
127 };
131 /// @brief 用于构建 read_avro() 选项的构建器。
133  avro_reader_options options;
134 
140  /// @brief 默认构造函数。
141  avro_reader_options_builder() = default;
147  /// @brief 从源信息构造函数。
148  explicit avro_reader_options_builder(source_info src) : options{std::move(src)} {}
155  /// @brief 设置要读取的列名。
156  avro_reader_options_builder& columns(std::vector<std::string> col_names)
157  {
158  options._columns = std::move(col_names);
159  return *this;
160  }
167  /// @brief 设置要跳过的行数。
169  {
170  options._skip_rows = val;
171  return *this;
172  }
179  /// @brief 设置要读取的行数。
181  {
182  options._num_rows = val;
183  return *this;
184  }
188  /// @brief 构建完成后移动 avro_reader_options 成员。
189  operator avro_reader_options&&() { return std::move(options); }
197  /// @brief 构建完成后移动 avro_reader_options 成员。
198  avro_reader_options&& build() { return std::move(options); }
199 };
217 /// @brief 将 Avro 数据集读取到一组列中。
219  avro_reader_options const& options,
223  // end of group
224 } // namespace io
用于构建 read_avro() 选项的构建器。
定义: avro.hpp:131
avro_reader_options_builder()=default
默认构造函数。
avro_reader_options_builder(source_info src)
从源信息构造函数。
定义: avro.hpp:147
avro_reader_options_builder & columns(std::vector< std::string > col_names)
设置要读取的列名。
定义: avro.hpp:155
avro_reader_options_builder & num_rows(size_type val)
设置要读取的行数。
定义: avro.hpp:179
avro_reader_options_builder & skip_rows(size_type val)
设置要跳过的行数。
定义: avro.hpp:167
avro_reader_options && build()
构建完成后移动 avro_reader_options 成员。
定义: avro.hpp:197
用于 read_avro() 的设置。
定义: avro.hpp:42
avro_reader_options()=default
默认构造函数。
std::vector< std::string > get_columns() const
返回要读取的列名。
定义: avro.hpp:82
static avro_reader_options_builder builder(source_info src)
创建将构建 avro_reader_options 的 avro_reader_options_builder。
void set_skip_rows(size_type val)
设置要跳过的行数。
定义: avro.hpp:110
size_type get_num_rows() const
返回要读取的行数。
定义: avro.hpp:96
source_info const & get_source() const
返回源信息。
定义: avro.hpp:75
void set_columns(std::vector< std::string > col_names)
设置要读取的列名。
定义: avro.hpp:103
void set_num_rows(size_type val)
设置要读取的行数。
定义: avro.hpp:117
size_type get_skip_rows() const
返回从开始跳过的行数。
定义: avro.hpp:89
rmm::cuda_stream_view const get_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())
将 Avro 数据集读取到一组列中。
rmm::device_async_resource_ref get_current_device_resource_ref()
获取当前的设备内存资源引用。
cuda::mr::async_resource_ref< cuda::mr::device_accessible > device_async_resource_ref
int32_t size_type
列和表的行索引类型。
定义: types.hpp:95
cuDF 接口
读取接口的源信息。
包含表元数据的表,由 io 读取器用于按值返回元数据。
(mutable)_table_view 的类定义
libcudf 的类型声明。