io/json.hpp
前往此文件的文档。
1 /*
2  * 版权所有 (c) 2020-2024, NVIDIA CORPORATION。
3  *
4  * 根据 Apache 许可证 2.0 版(“许可证”)的规定获得许可;
5  * 除非遵守许可证,否则不得使用此文件。
6  * 您可以在以下位置获取许可证副本
7  *
8  * https://apache.ac.cn/licenses/LICENSE-2.0
9  *
10  * 除非适用法律要求或书面同意,软件
11  * 根据许可证分发,不提供任何形式的明示或暗示的保证或条件。
12  * 请参阅许可证中关于特定语言管理权限和
13  * 许可证下的限制。
14  */
15 
16 #pragma once
17 
18 #include "types.hpp"
19 
20 #include <cudf/detail/utilities/visitor_overload.hpp>
22 #include <cudf/types.hpp>
23 #include <cudf/utilities/error.hpp>
25 
26 #include <map>
27 #include <string>
28 #include <utility>
29 #include <variant>
30 #include <vector>
31 
32 namespace CUDF_EXPORT cudf {
33 namespace io {
41 // JSON 读取器选项构建器
42 
52 
56  std::map<std::string, schema_element> child_types;
57 
61  std::optional<std::vector<std::string>> column_order;
62 };
63 
67 // JSON 读取器恢复模式类型
67 enum class json_recovery_mode_t {
68  FAIL, // 在无效 JSON 行失败
69  RECOVER_WITH_NULL // 在无效 JSON 行时以 null 恢复
70 };
71 
95 // JSON 读取器选项
95 class json_reader_options {
96  public
97  // 用于指定数据类型的可能变体
97  using dtype_variant =
98  std::variant<std::vector<data_type>,
99  std::map<std::string, data_type>,
100  std::map<std::string, schema_element>,
102 
103  private
104  source_info _source; // 源信息
105 
106  // 列的数据类型;为空则推断数据类型
107  dtype_variant _dtypes;
108  // 指定源文件的压缩格式或从文件扩展名推断
109  compression_type _compression = compression_type::AUTO;
110 
111  // 将文件按行读取为 JSON 对象
112  bool _lines = false;
113  // 将混合类型解析为字符串列
114  bool _mixed_types_as_string = false;
115  // JSON 行中分隔记录的分隔符
116  char _delimiter = '\n';
117  // 读取时修剪列,根据 _dtypes 选项选择
118  bool _prune_columns = false;
119  // 实验性功能:新的列树构建
120  bool _experimental = false;
121 
122  // 从头跳过的字节数
123  size_t _byte_range_offset = 0;
124  // 读取的字节数;总是读取完整的行
125  size_t _byte_range_size = 0;
126 
127  // 是否将日期解析为 DD/MM 而非 MM/DD
128  bool _dayfirst = false;
129 
130  // 是否保留字符串值的引号字符
131  bool _keep_quotes = false;
132 
133  // 规范化单引号
134  bool _normalize_single_quotes = false;
135 
136  // 规范化未加引号的空格和制表符
137  bool _normalize_whitespace = false;
138 
139  // 在无效 JSON 行后是否恢复
140  json_recovery_mode_t _recovery_mode = json_recovery_mode_t::FAIL;
141 
142  // 用于 spark 的验证检查
143  // JSON 验证是否应严格
144  // 注意:严格验证强制执行 JSON 规范 https://www.json.org/json-en.html
145  bool _strict_validation = false;
146  // 允许数值带有前导零。
147  bool _allow_numeric_leading_zeros = true;
148  // 允许非数字:NaN, +INF, -INF, +Infinity, Infinity, -Infinity
149  bool _allow_nonnumeric_numbers = true;
150  // 允许未加引号的控制字符
151  bool _allow_unquoted_control_chars = true;
152  // 额外识别为 null 值的数值
153  std::vector<std::string> _na_values;
154 
160  // 供构建器使用的私有构造函数
160  explicit json_reader_options(source_info src) : _source{std::move(src)} {}
161 
163 
164  public
170  // 构造具有默认值的新选项
170  explicit json_reader_options() = default;
171 
178  // 创建新的构建器实例
179 
185  // 返回源信息
185  [[nodiscard]] source_info const& get_source() const { return _source; }
186 
192  // 返回数据类型
192  [[nodiscard]] dtype_variant const& get_dtypes() const { return _dtypes; }
193 
199  // 返回压缩类型
199  [[nodiscard]] compression_type get_compression() const { return _compression; }
200 
206  // 返回要读取的字节范围的偏移量
206  [[nodiscard]] size_t get_byte_range_offset() const { return _byte_range_offset; }
207 
213  // 返回要读取的字节范围的大小
213  [[nodiscard]] size_t get_byte_range_size() const { return _byte_range_size; }
214 
220  // 返回要读取的字节范围的大小,包括填充
220  [[nodiscard]] size_t get_byte_range_size_with_padding() const
221  {
222  if (_byte_range_size == 0) {
223  return 0;
224  } else {
225  return _byte_range_size + get_byte_range_padding();
226  }
227  }
228 
234  // 根据列数返回所需的填充字节数。
234  [[nodiscard]] size_t get_byte_range_padding() const
235  {
236  auto const num_columns =
237  std::visit(cudf::detail::visitor_overload{
238  [](auto const& dtypes) { return dtypes.size(); },
239  [](schema_element const& dtypes) { return dtypes.child_types.size(); }},
240  _dtypes);
241 
242  auto const max_row_bytes = 16 * 1024; // 16KB
243  auto const column_bytes = 64;
244  auto const base_padding = 1024; // 1KB
245 
246  if (num_columns == 0) {
247  // Use flat size if the number of columns is not known
248  return max_row_bytes;
249  } else {
250  // Expand the size based on the number of columns, if available
251  return base_padding + num_columns * column_bytes;
252  }
253  }
254 
260  // 返回用于在 JSON 行中分隔记录的分隔符
260  [[nodiscard]] char get_delimiter() const { return _delimiter; }
261 
267  // 返回是否启用 JSON 行读取
267  [[nodiscard]] bool is_enabled_lines() const { return _lines; }
268 
274  // 返回是否将混合类型解析为字符串
274  [[nodiscard]] bool is_enabled_mixed_types_as_string() const { return _mixed_types_as_string; }
275 
286  // 返回是否根据数据类型修剪列
286  [[nodiscard]] bool is_enabled_prune_columns() const { return _prune_columns; }
287 
295  // 返回是否启用实验性功能
295  [[nodiscard]] bool is_enabled_experimental() const { return _experimental; }
296 
302  // 返回是否将日期解析为 DD/MM 而非 MM/DD
302  [[nodiscard]] bool is_enabled_dayfirst() const { return _dayfirst; }
303 
309  // 返回是否保留字符串值的引号字符
309  [[nodiscard]] bool is_enabled_keep_quotes() const { return _keep_quotes; }
310 
316  // 返回是否规范化单引号
316  [[nodiscard]] bool is_enabled_normalize_single_quotes() const { return _normalize_single_quotes; }
317 
323  // 返回是否规范化未加引号的空格和制表符
323  [[nodiscard]] bool is_enabled_normalize_whitespace() const { return _normalize_whitespace; }
324 
330  // 返回无效 JSON 行的恢复模式
330  [[nodiscard]] json_recovery_mode_t recovery_mode() const { return _recovery_mode; }
331 
337  // 返回是否启用严格 JSON 验证
337  [[nodiscard]] bool is_strict_validation() const { return _strict_validation; }
338 
346  // 返回是否允许带有前导零的数值。
346  [[nodiscard]] bool is_allowed_numeric_leading_zeros() const
347  {
348  return _allow_numeric_leading_zeros;
349  }
350 
359  // 返回是否允许非数字。
359  [[nodiscard]] bool is_allowed_nonnumeric_numbers() const { return _allow_nonnumeric_numbers; }
360 
369  // 返回是否允许未加引号的控制字符。
369  [[nodiscard]] bool is_allowed_unquoted_control_chars() const
370  {
371  return _allow_unquoted_control_chars;
372  }
373 
379  // 返回额外识别为 null 值的数值
379  [[nodiscard]] std::vector<std::string> const& get_na_values() const { return _na_values; }
380 
386  // 通过 std::vector 设置数据类型
386  void set_dtypes(std::vector<data_type> types) { _dtypes = std::move(types); }
387 
393  // 通过 std::map 设置数据类型
393  void set_dtypes(std::map<std::string, data_type> types) { _dtypes = std::move(types); }
394 
400  // 通过 std::map 设置数据类型
400  void set_dtypes(std::map<std::string, schema_element> types) { _dtypes = std::move(types); }
401 
408  // 通过 schema_element 设置数据类型。
408  void set_dtypes(schema_element types);
409 
415  // 设置压缩类型
415  void set_compression(compression_type comp_type) { _compression = comp_type; }
416 
422  // 设置要读取的字节范围的偏移量
422  void set_byte_range_offset(size_t offset) { _byte_range_offset = offset; }
423 
429  // 设置要读取的字节范围的大小
429  void set_byte_range_size(size_t size) { _byte_range_size = size; }
430 
436  // 设置用于在 JSON 行中分隔记录的分隔符。
436  void set_delimiter(char delimiter)
437  {
438  switch (delimiter) {
439  case '{'
440  case '['
441  case '}'
442  case ']'
443  case ','
444  case ':'
445  case '"'
446  case '\''
447  case '\\'
448  case ' '
449  case '\t'
450  case '\r': CUDF_FAIL("不支持的分隔符字符。", std::invalid_argument); break;
451  }
452  _delimiter = delimiter;
453  }
454 
460  // 启用/禁用 JSON 行读取
460  void enable_lines(bool val) { _lines = val; }
461 
468  // 启用/禁用将混合类型解析为字符串
468  void enable_mixed_types_as_string(bool val) { _mixed_types_as_string = val; }
469 
479  // 启用/禁用根据数据类型修剪列。
479  void enable_prune_columns(bool val) { _prune_columns = val; }
480 
489  // 启用/禁用实验性功能。
489  void enable_experimental(bool val) { _experimental = val; }
490 
496  // 启用/禁用将日期解析为 DD/MM 而非 MM/DD
496  void enable_dayfirst(bool val) { _dayfirst = val; }
497 
504  // 启用/禁用保留字符串值的引号字符
504  void enable_keep_quotes(bool val) { _keep_quotes = val; }
505 
512  // 启用/禁用规范化单引号
512  void enable_normalize_single_quotes(bool val) { _normalize_single_quotes = val; }
513 
520  // 启用/禁用规范化未加引号的空格和制表符
520  void enable_normalize_whitespace(bool val) { _normalize_whitespace = val; }
521 
527  // 设置无效 JSON 行的恢复模式
527  void set_recovery_mode(json_recovery_mode_t val) { _recovery_mode = val; }
528 
534  // 设置是否启用严格 JSON 验证
534  void set_strict_validation(bool val) { _strict_validation = val; }
535 
544  // 设置是否允许带有前导零的数值。
544  void allow_numeric_leading_zeros(bool val)
545  {
546  CUDF_EXPECTS(_strict_validation, "必须启用严格验证才能使其工作。");
547  _allow_numeric_leading_zeros = val;
548  }
549 
558  // 设置是否允许非数字。
558  void allow_nonnumeric_numbers(bool val)
559  {
560  CUDF_EXPECTS(_strict_validation, "必须启用严格验证才能使其工作。");
561  _allow_nonnumeric_numbers = val;
562  }
563 
573  // 设置是否允许未加引号的控制字符。
573  void allow_unquoted_control_chars(bool val)
574  {
575  CUDF_EXPECTS(_strict_validation, "必须启用严格验证才能使其工作。");
576  _allow_unquoted_control_chars = val;
577  }
578 
584  // 设置额外识别为 null 值的数值
584  void set_na_values(std::vector<std::string> vals) { _na_values = std::move(vals); }
585 };
586 
590 // JSON 读取器选项构建器
591  json_reader_options options;
592 
593  public
599  // 构造新的构建器实例
599  explicit json_reader_options_builder() = default;
600 
606  // 从源构造新的构建器实例
606  explicit json_reader_options_builder(source_info src) : options{std::move(src)} {}
607 
614  // 设置数据类型
614  json_reader_options_builder& dtypes(std::vector<data_type> types)
615  {
616  options._dtypes = std::move(types);
617  return *this;
618  }
619 
626  // 设置数据类型
626  json_reader_options_builder& dtypes(std::map<std::string, data_type> types)
627  {
628  options._dtypes = std::move(types);
629  return *this;
630  }
631 
638  // 设置数据类型
638  json_reader_options_builder& dtypes(std::map<std::string, schema_element> types)
639  {
640  options._dtypes = std::move(types);
641  return *this;
642  }
643 
650  // 设置数据类型
651  {
652  options.set_dtypes(std::move(types));
653  return *this;
654  }
655 
662  // 设置压缩类型
663  {
664  options._compression = comp_type;
665  return *this;
666  }
667 
674  // 设置要读取的字节范围的偏移量
675  {
676  options._byte_range_offset = offset;
677  return *this;
678  }
679 
686  // 设置要读取的字节范围的大小
687  {
688  options._byte_range_size = size;
689  return *this;
690  }
691 
698  // 设置用于在 JSON 行中分隔记录的分隔符。
698  json_reader_options_builder& delimiter(char delimiter)
699  {
700  options.set_delimiter(delimiter);
701  return *this;
702  }
703 
710  // 启用/禁用 JSON 行读取
711  {
712  options._lines = val;
713  return *this;
714  }
715 
723  // 启用/禁用将混合类型解析为字符串
724  {
725  options._mixed_types_as_string = val;
726  return *this;
727  }
728 
739  // 启用/禁用根据数据类型修剪列。
740  {
741  options._prune_columns = val;
742  return *this;
743  }
744 
754  // 启用/禁用实验性功能。
755  {
756  options._experimental = val;
757  return *this;
758  }
759 
766  // 启用/禁用将日期解析为 DD/MM 而非 MM/DD
767  {
768  options._dayfirst = val;
769  return *this;
770  }
771 
779  // 启用/禁用保留字符串值的引号字符
780  {
781  options._keep_quotes = val;
782  return *this;
783  }
784 
792  // 启用/禁用规范化单引号
793  {
794  options._normalize_single_quotes = val;
795  return *this;
796  }
797 
805  // 启用/禁用规范化未加引号的空格和制表符
806  {
807  options._normalize_whitespace = val;
808  return *this;
809  }
810 
817  // 设置无效 JSON 行的恢复模式
818  {
819  options._recovery_mode = val;
820  return *this;
821  }
822 
829  // 设置是否启用严格 JSON 验证
830  {
831  options.set_strict_validation(val);
832  return *this;
833  }
834 
844  // 设置是否允许带有前导零的数值。
845  {
846  options.allow_numeric_leading_zeros(val);
847  return *this;
848  }
849 
860  // 设置是否允许非数字。
861  {
862  options.allow_nonnumeric_numbers(val);
863  return *this;
864  }
865 
875  // 设置是否允许未加引号的控制字符。
876  {
877  options.allow_unquoted_control_chars(val);
878  return *this;
879  }
880 
887  // 设置额外识别为 null 值的数值
887  json_reader_options_builder& na_values(std::vector<std::string> vals)
888  {
889  options.set_na_values(std::move(vals));
890  return *this;
891  }
892 
896  // 构建 json_reader_options
896  operator json_reader_options&&() { return std::move(options); }
897 
905  // 构建 json_reader_options
905  json_reader_options&& build() { return std::move(options); }
906 };
907 
925 // 将 JSON 数据读取到表中。
926  json_reader_options options,
929  // 组结束
931 
941 // JSON 写入器选项构建器
1140 
1141  public
1147  explicit json_writer_options_builder() = default;
1148 
1156  : options{sink, table}
1157  {
1158  }
1159 
1167  {
1168  options._table = tbl;
1169  return *this;
1170  }
1171 
1179  {
1180  options._compression = comptype;
1181  return *this;
1182  }
1183 
1191  {
1192  options._metadata = std::move(metadata);
1193  return *this;
1194  }
1195 
1203  {
1204  options._na_rep = std::move(val);
1205  return *this;
1206  };
1207 
1215  {
1216  options._include_nulls = val;
1217  return *this;
1218  }
1219 
1227  {
1228  options._lines = val;
1229  return *this;
1230  }
1231 
1239  {
1240  options._rows_per_chunk = val;
1241  return *this;
1242  }
1243 
1251  {
1252  options._true_value = std::move(val);
1253  return *this;
1254  }
1255 
1263  {
1264  options._false_value = std::move(val);
1265  return *this;
1266  }
1267 
1271  operator json_writer_options&&() { return std::move(options); }
1272 
1280  json_writer_options&& build() { return std::move(options); }
1281 };
1282 
1300 void write_json(json_writer_options const& options,
1302  // end of group
1304 } // namespace io
1305 } // namespace CUDF_EXPORT cudf
列中元素的逻辑数据类型的指示符。
构建用于 read_json() 的设置。
json_reader_options_builder & normalize_single_quotes(bool val)
设置读取器是否应该规范化字符串周围的单引号。
json_reader_options_builder & nonnumeric_numbers(bool val)
设置特定的未加引号的数值是否为有效的 JSON。这些值包括 NaN, +INF,...
json_reader_options_builder & keep_quotes(bool val)
设置读取器是否应保留字符串值的引号。
json_reader_options_builder & normalize_whitespace(bool val)
设置读取器是否应规范化未加引号的空白字符。
json_reader_options_builder & numeric_leading_zeros(bool val)
设置是否允许数值中包含前导零。必须启用严格验证才能使用此选项...
json_reader_options_builder & dtypes(schema_element types)
设置要读取的列的数据类型。
json_reader_options_builder & dayfirst(bool val)
设置是否将日期解析为 DD/MM 而非 MM/DD。
json_reader_options_builder & recovery_mode(json_recovery_mode_t val)
指定 JSON 读取器在遇到无效 JSON 行时的行为。
json_reader_options_builder & na_values(std::vector< std::string > vals)
设置要识别为 null 值的附加值。
json_reader_options_builder & delimiter(char delimiter)
设置 JSON 行中分隔记录的分隔符。
json_reader_options_builder & prune_columns(bool val)
设置读取时是否修剪列,根据 dtypes 选项选择。
json_reader_options_builder & experimental(bool val)
设置是否启用实验性功能。
json_reader_options_builder & lines(bool val)
设置是否按行读取文件作为 JSON 对象。
json_reader_options_builder & dtypes(std::vector< data_type > types)
设置要读取的列的数据类型。
json_reader_options && build()
一旦构建完成,移动 json_reader_options 成员。
json_reader_options_builder & mixed_types_as_string(bool val)
设置是否将混合类型解析为字符串列。还允许强制将结构体读取为字符串...
json_reader_options_builder & unquoted_control_chars(bool val)
设置在加引号的字符串中,是否允许使用 >= 0 且 < 32 的字符而无需某种形式的转义...
json_reader_options_builder & compression(compression_type comp_type)
设置压缩类型。
json_reader_options_builder(source_info src)
从 source info 构造。
json_reader_options_builder & strict_validation(bool val)
设置 JSON 验证是否应该严格。
json_reader_options_builder & byte_range_size(size_type size)
设置要读取的字节数。
json_reader_options_builder & dtypes(std::map< std::string, schema_element > types)
设置要读取的列的数据类型。
json_reader_options_builder & byte_range_offset(size_type offset)
设置从源开始跳过的字节数。
json_reader_options_builder()=default
默认构造函数。
json_reader_options_builder & dtypes(std::map< std::string, data_type > types)
设置要读取的列的数据类型。
read_json 接口的输入参数。
bool is_allowed_nonnumeric_numbers() const
是否允许未加引号的数值 NaN, +INF, -INF, +Infinity, Infinity,...
void enable_mixed_types_as_string(bool val)
设置是否将混合类型解析为字符串列。还允许强制将结构体读取为字符串...
void set_compression(compression_type comp_type)
设置压缩类型。
void set_dtypes(std::vector< data_type > types)
设置要读取的列的数据类型。
void allow_unquoted_control_chars(bool val)
设置在加引号的字符串中,是否应允许大于或等于 0 且小于 32 的字符...
void enable_normalize_single_quotes(bool val)
设置读取器是否应启用规范化字符串周围的单引号。
bool is_allowed_numeric_leading_zeros() const
数值中是否允许前导零。
void enable_prune_columns(bool val)
设置读取时是否修剪列,根据 set_dtypes 选项选择。
bool is_enabled_keep_quotes() const
读取器是否应保留字符串值的引号。
void set_dtypes(schema_element types)
为潜在的嵌套列层级设置数据类型。
void enable_normalize_whitespace(bool val)
设置读取器是否应启用规范化未加引号的空白字符。
void allow_nonnumeric_numbers(bool val)
设置是否允许未加引号的数值 NaN, +INF, -INF, +Infinity, Infinity,...
size_t get_byte_range_offset() const
返回从源开始跳过的字节数。
source_info const & get_source() const
返回源信息。
void enable_experimental(bool val)
设置是否启用实验性功能。
void set_dtypes(std::map< std::string, data_type > types)
设置要读取的列的数据类型。
bool is_enabled_prune_columns() const
读取时是否修剪列,根据 set_dtypes 选项选择。
char get_delimiter() const
返回 JSON 行中分隔记录的分隔符。
bool is_enabled_lines() const
是否按行读取文件作为 JSON 对象。
void allow_numeric_leading_zeros(bool val)
设置是否允许数值中包含前导零。必须启用严格验证才能使用此选项...
void set_strict_validation(bool val)
设置是否启用严格验证。
bool is_enabled_mixed_types_as_string() const
是否将混合类型解析为字符串列。
json_reader_options()=default
默认构造函数。
void set_na_values(std::vector< std::string > vals)
设置要识别为 null 值的附加值。
void enable_dayfirst(bool val)
设置是否将日期解析为 DD/MM 而非 MM/DD。
size_t get_byte_range_size_with_padding() const
返回带填充的要读取的字节数。
void set_recovery_mode(json_recovery_mode_t val)
指定 JSON 读取器在遇到无效 JSON 行时的行为。
bool is_enabled_normalize_whitespace() const
读取器是否应规范化未加引号的空白字符。
bool is_strict_validation() const
是否应严格执行 JSON 验证。
void set_delimiter(char delimiter)
设置 JSON 行中分隔记录的分隔符。
void set_byte_range_offset(size_t offset)
设置从源开始跳过的字节数。
void enable_lines(bool val)
设置是否按行读取文件作为 JSON 对象。
dtype_variant const & get_dtypes() const
返回列的数据类型。
void enable_keep_quotes(bool val)
设置读取器是否应保留字符串值的引号。
bool is_enabled_normalize_single_quotes() const
读取器是否应规范化字符串周围的单引号。
compression_type get_compression() const
返回源的压缩格式。
void set_dtypes(std::map< std::string, schema_element > types)
为潜在的嵌套列层级设置数据类型。
size_t get_byte_range_size() const
返回要读取的字节数。
std::variant< std::vector< data_type >, std::map< std::string, data_type >, std::map< std::string, schema_element >, schema_element > dtype_variant
保存列的 dtypes 信息的变体类型。
bool is_enabled_experimental() const
是否启用实验性功能。
json_recovery_mode_t recovery_mode() const
查询 JSON 读取器在遇到无效 JSON 行时的行为。
static json_reader_options_builder builder(source_info src)
创建将构建 json_reader_options 的 json_reader_options_builder。
bool is_enabled_dayfirst() const
是否将日期解析为 DD/MM 而非 MM/DD。
size_t get_byte_range_padding() const
返回读取时要填充的字节数。
bool is_allowed_unquoted_control_chars() const
在加引号的字符串中,是否应允许大于或等于 0 且小于 32 的字符...
std::vector< std::string > const & get_na_values() const
返回要识别为 null 值的附加值。
void set_byte_range_size(size_t size)
设置要读取的字节数。
用于构建 writer_json() 选项的构建器。
json_writer_options_builder & compression(compression_type comptype)
设置输出目标的压缩类型。
json_writer_options_builder & include_nulls(bool val)
启用/禁用将 null 作为 'null' 输出。
json_writer_options_builder & table(table_view tbl)
设置要写入输出的表。
json_writer_options_builder()=default
默认构造函数。
json_writer_options_builder & rows_per_chunk(int val)
设置每次文件写入处理的最大行数。
json_writer_options_builder & true_value(std::string val)
设置 INT8 类型中用于值 != 0 的字符串。
json_writer_options_builder & false_value(std::string val)
设置 INT8 类型中用于值 == 0 的字符串。
json_writer_options_builder(sink_info const &sink, table_view const &table)
从 sink 和 table 构造。
json_writer_options_builder & na_rep(std::string val)
设置用于 null 条目的字符串。
json_writer_options_builder & metadata(table_metadata metadata)
设置可选的元数据(包含列名)。
json_writer_options && build()
一旦构建完成,移动 json_writer_options 成员。
json_writer_options_builder & lines(bool val)
启用/禁用每条记录使用 JSON 行格式。
用于 write_json() 的设置。
void set_compression(compression_type comptype)
设置要使用的压缩类型。
compression_type get_compression() const
返回用于 sink 的压缩类型。
table_view const & get_table() const
返回将要写入输出的表。
void set_false_value(std::string val)
设置 INT8 类型中用于值 == 0 的字符串。
void enable_include_nulls(bool val)
启用/禁用将 null 作为 'null' 输出。
bool is_enabled_include_nulls() const
是否将 null 作为 'null' 输出。
void enable_lines(bool val)
启用/禁用每条记录使用 JSON 行格式。
void set_na_rep(std::string val)
设置用于 null 条目的字符串。
static json_writer_options_builder builder(sink_info const &sink, table_view const &table)
创建用于创建 json_writer_options 的构建器。
json_writer_options()=default
默认构造函数。
void set_true_value(std::string val)
设置 INT8 类型中用于值 != 0 的字符串。
sink_info const & get_sink() const
返回用于写入器输出的 sink。
void set_rows_per_chunk(size_type val)
设置每次文件写入处理的最大行数。
std::string const & get_true_value() const
返回 INT8 类型中用于值 != 0 的字符串。
void set_table(table_view tbl)
设置要写入输出的表。
std::string const & get_false_value() const
返回 INT8 类型中用于值 == 0 的字符串。
bool is_enabled_lines() const
是否为记录格式使用 JSON 行。
size_type get_rows_per_chunk() const
返回每次文件写入处理的最大行数。
std::optional< table_metadata > const & get_metadata() const
返回元数据信息。
std::string const & get_na_rep() const
返回用于 null 条目的字符串。
void set_metadata(table_metadata metadata)
设置元数据。
一组大小相同的 cudf::column_view。
一组大小相同的 cudf::column。
定义: table.hpp:40
size_type num_rows() const noexcept
返回行数。
定义: table.hpp:93
rmm::cuda_stream_view const get_default_stream()
获取当前的默认流。
table_with_metadata read_json(json_reader_options options, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
将 JSON 数据集读取到一组列中。
json_recovery_mode_t
控制 JSON 解析器的错误恢复行为。
@ RECOVER_WITH_NULL
从错误中恢复,将无效记录替换为 null。
@ FAIL
遇到无效格式时不会从错误中恢复。
compression_type
压缩算法。
void write_json(json_writer_options const &options, rmm::cuda_stream_view stream=cudf::get_default_stream())
将一组列写入 JSON 格式。
rmm::device_async_resource_ref get_current_device_resource_ref()
获取当前的设备内存资源引用。
cuda::mr::async_resource_ref< cuda::mr::device_accessible > device_async_resource_ref
#define CUDF_EXPECTS(...)
用于检查(前置)条件的宏,当条件不满足时抛出异常。
#define CUDF_FAIL(...)
指示已执行错误代码路径。
int32_t size_type
列和表的行索引类型。
定义: types.hpp:95
cuDF 接口
允许通过 json_reader_options 的 set_dtypes 方法指定嵌套 JSON 数据的目标类型。
std::optional< std::vector< std::string > > column_order
允许指定列的顺序。
data_type type
此列应转换成的类型。
std::map< std::string, schema_element > child_types
允许指定此列的子列的目标类型。
写入接口的目标信息。
读取接口的源信息。
IO 读取器返回的表元数据。
IO 读取器用于按值返回元数据的带表元数据的表。
(mutable)_table_view 的类定义。
libcudf 的类型声明。