json.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 
10 #include <cudf/detail/utilities/visitor_overload.hpp>
11 #include <cudf/io/detail/utils.hpp>
13 #include <cudf/types.hpp>
14 #include <cudf/utilities/error.hpp>
16 
17 #include <map>
18 #include <string>
19 #include <utility>
20 #include <variant>
21 #include <vector>
22 
28 namespace CUDF_EXPORT cudf {
29 namespace io {
35 class json_reader_options_builder;
36 
46 
50  std::map<std::string, schema_element> child_types;
51 
55  std::optional<std::vector<std::string>> column_order;
56 };
57 
62  FAIL,
64 };
65 
90  public:
91  using dtype_variant =
92  std::variant<std::vector<data_type>,
93  std::map<std::string, data_type>,
94  std::map<std::string, schema_element>,
96 
97  private:
98  source_info _source;
99 
100  // Data types of the column; empty to infer dtypes
101  dtype_variant _dtypes;
102  // Specify the compression format of the source or infer from file extension
103  compression_type _compression = compression_type::AUTO;
104 
105  // Read the file as a json object per line
106  bool _lines = false;
107  // Parse mixed types as a string column
108  bool _mixed_types_as_string = false;
109  // Delimiter separating records in JSON lines
110  char _delimiter = '\n';
111  // Prune columns on read, selected based on the _dtypes option
112  bool _prune_columns = false;
113  // Experimental features: new column tree construction
114  bool _experimental = false;
115 
116  // Bytes to skip from the start
117  size_t _byte_range_offset = 0;
118  // Bytes to read; always reads complete rows
119  size_t _byte_range_size = 0;
120 
121  // Whether to parse dates as DD/MM versus MM/DD
122  bool _dayfirst = false;
123 
124  // Whether to keep the quote characters of string values
125  bool _keep_quotes = false;
126 
127  // Normalize single quotes
128  bool _normalize_single_quotes = false;
129 
130  // Normalize unquoted spaces and tabs
131  bool _normalize_whitespace = false;
132 
133  // Whether to recover after an invalid JSON line
134  json_recovery_mode_t _recovery_mode = json_recovery_mode_t::FAIL;
135 
136  // Validation checks for spark
137  // Should the json validation be strict or not
138  // Note: strict validation enforces the JSON specification https://www.json.org/json-en.html
139  bool _strict_validation = false;
140  // Allow leading zeros for numeric values.
141  bool _allow_numeric_leading_zeros = true;
142  // Allow non-numeric numbers: NaN, +INF, -INF, +Infinity, Infinity, -Infinity
143  bool _allow_nonnumeric_numbers = true;
144  // Allow unquoted control characters
145  bool _allow_unquoted_control_chars = true;
146  // Additional values to recognize as null values
147  std::vector<std::string> _na_values;
148 
154  explicit json_reader_options(source_info src) : _source{std::move(src)} {}
155 
157 
158  public:
164  json_reader_options() = default;
165 
173 
179  [[nodiscard]] source_info const& get_source() const { return _source; }
180 
186  [[nodiscard]] dtype_variant const& get_dtypes() const { return _dtypes; }
187 
193  [[nodiscard]] compression_type get_compression() const { return _compression; }
194 
200  [[nodiscard]] size_t get_byte_range_offset() const { return _byte_range_offset; }
201 
207  [[nodiscard]] size_t get_byte_range_size() const { return _byte_range_size; }
208 
214  [[nodiscard]] size_t get_byte_range_size_with_padding() const
215  {
216  if (_byte_range_size == 0) {
217  return 0;
218  } else {
219  return _byte_range_size + get_byte_range_padding();
220  }
221  }
222 
228  [[nodiscard]] size_t get_byte_range_padding() const
229  {
230  auto const num_columns =
231  std::visit(cudf::detail::visitor_overload{
232  [](auto const& dtypes) { return dtypes.size(); },
233  [](schema_element const& dtypes) { return dtypes.child_types.size(); }},
234  _dtypes);
235 
236  auto const max_row_bytes = 16 * 1024; // 16KB
237  auto const column_bytes = 64;
238  auto const base_padding = 1024; // 1KB
239 
240  if (num_columns == 0) {
241  // Use flat size if the number of columns is not known
242  return max_row_bytes;
243  }
244 
245  // Expand the size based on the number of columns, if available
246  return base_padding + static_cast<size_t>(num_columns) * column_bytes;
247  }
248 
254  [[nodiscard]] char get_delimiter() const { return _delimiter; }
255 
261  [[nodiscard]] bool is_enabled_lines() const { return _lines; }
262 
268  [[nodiscard]] bool is_enabled_mixed_types_as_string() const { return _mixed_types_as_string; }
269 
280  [[nodiscard]] bool is_enabled_prune_columns() const { return _prune_columns; }
281 
289  [[nodiscard]] bool is_enabled_experimental() const { return _experimental; }
290 
296  [[nodiscard]] bool is_enabled_dayfirst() const { return _dayfirst; }
297 
303  [[nodiscard]] bool is_enabled_keep_quotes() const { return _keep_quotes; }
304 
310  [[nodiscard]] bool is_enabled_normalize_single_quotes() const { return _normalize_single_quotes; }
311 
317  [[nodiscard]] bool is_enabled_normalize_whitespace() const { return _normalize_whitespace; }
318 
324  [[nodiscard]] json_recovery_mode_t recovery_mode() const { return _recovery_mode; }
325 
331  [[nodiscard]] bool is_strict_validation() const { return _strict_validation; }
332 
340  [[nodiscard]] bool is_allowed_numeric_leading_zeros() const
341  {
342  return _allow_numeric_leading_zeros;
343  }
344 
353  [[nodiscard]] bool is_allowed_nonnumeric_numbers() const { return _allow_nonnumeric_numbers; }
354 
363  [[nodiscard]] bool is_allowed_unquoted_control_chars() const
364  {
365  return _allow_unquoted_control_chars;
366  }
367 
373  [[nodiscard]] std::vector<std::string> const& get_na_values() const { return _na_values; }
374 
380  void set_source(source_info src) { _source = std::move(src); }
381 
387  void set_dtypes(std::vector<data_type> types) { _dtypes = std::move(types); }
388 
394  void set_dtypes(std::map<std::string, data_type> types) { _dtypes = std::move(types); }
395 
401  void set_dtypes(std::map<std::string, schema_element> types) { _dtypes = std::move(types); }
402 
410 
416  void set_compression(compression_type comp_type) { _compression = comp_type; }
417 
423  void set_byte_range_offset(size_t offset) { _byte_range_offset = offset; }
424 
430  void set_byte_range_size(size_t size) { _byte_range_size = size; }
431 
437  void set_delimiter(char delimiter)
438  {
439  switch (delimiter) {
440  case '{':
441  case '[':
442  case '}':
443  case ']':
444  case ',':
445  case ':':
446  case '"':
447  case '\'':
448  case '\\':
449  case ' ':
450  case '\t':
451  case '\r': CUDF_FAIL("Unsupported delimiter character.", std::invalid_argument); break;
452  }
453  _delimiter = delimiter;
454  }
455 
461  void enable_lines(bool val) { _lines = val; }
462 
469  void enable_mixed_types_as_string(bool val) { _mixed_types_as_string = val; }
470 
480  void enable_prune_columns(bool val) { _prune_columns = val; }
481 
490  void enable_experimental(bool val) { _experimental = val; }
491 
497  void enable_dayfirst(bool val) { _dayfirst = val; }
498 
505  void enable_keep_quotes(bool val) { _keep_quotes = val; }
506 
513  void enable_normalize_single_quotes(bool val) { _normalize_single_quotes = val; }
514 
521  void enable_normalize_whitespace(bool val) { _normalize_whitespace = val; }
522 
528  void set_recovery_mode(json_recovery_mode_t val) { _recovery_mode = val; }
529 
535  void set_strict_validation(bool val) { _strict_validation = val; }
536 
546  {
547  CUDF_EXPECTS(_strict_validation, "Strict validation must be enabled for this to work.");
548  _allow_numeric_leading_zeros = val;
549  }
550 
560  {
561  CUDF_EXPECTS(_strict_validation, "Strict validation must be enabled for this to work.");
562  _allow_nonnumeric_numbers = val;
563  }
564 
575  {
576  CUDF_EXPECTS(_strict_validation, "Strict validation must be enabled for this to work.");
577  _allow_unquoted_control_chars = val;
578  }
579 
585  void set_na_values(std::vector<std::string> vals) { _na_values = std::move(vals); }
586 };
587 
592  json_reader_options options;
593 
594  public:
600  explicit json_reader_options_builder() = default;
601 
607  explicit json_reader_options_builder(source_info src) : options{std::move(src)} {}
608 
615  json_reader_options_builder& dtypes(std::vector<data_type> types)
616  {
617  options._dtypes = std::move(types);
618  return *this;
619  }
620 
627  json_reader_options_builder& dtypes(std::map<std::string, data_type> types)
628  {
629  options._dtypes = std::move(types);
630  return *this;
631  }
632 
639  json_reader_options_builder& dtypes(std::map<std::string, schema_element> types)
640  {
641  options._dtypes = std::move(types);
642  return *this;
643  }
644 
652  {
653  options.set_dtypes(std::move(types));
654  return *this;
655  }
656 
664  {
665  options._compression = comp_type;
666  return *this;
667  }
668 
676  {
677  options._byte_range_offset = offset;
678  return *this;
679  }
680 
688  {
689  options._byte_range_size = size;
690  return *this;
691  }
692 
700  {
701  options.set_delimiter(delimiter);
702  return *this;
703  }
704 
712  {
713  options._lines = val;
714  return *this;
715  }
716 
725  {
726  options._mixed_types_as_string = val;
727  return *this;
728  }
729 
741  {
742  options._prune_columns = val;
743  return *this;
744  }
745 
756  {
757  options._experimental = val;
758  return *this;
759  }
760 
768  {
769  options._dayfirst = val;
770  return *this;
771  }
772 
781  {
782  options._keep_quotes = val;
783  return *this;
784  }
785 
794  {
795  options._normalize_single_quotes = val;
796  return *this;
797  }
798 
807  {
808  options._normalize_whitespace = val;
809  return *this;
810  }
811 
819  {
820  options._recovery_mode = val;
821  return *this;
822  }
823 
831  {
832  options.set_strict_validation(val);
833  return *this;
834  }
835 
846  {
847  options.allow_numeric_leading_zeros(val);
848  return *this;
849  }
850 
862  {
863  options.allow_nonnumeric_numbers(val);
864  return *this;
865  }
866 
877  {
878  options.allow_unquoted_control_chars(val);
879  return *this;
880  }
881 
888  json_reader_options_builder& na_values(std::vector<std::string> vals)
889  {
890  options.set_na_values(std::move(vals));
891  return *this;
892  }
893 
897  operator json_reader_options&&() { return std::move(options); }
898 
906  json_reader_options&& build() { return std::move(options); }
907 };
908 
927  json_reader_options options,
930 
950  std::vector<std::string> top_level_columns_with_schema_mismatch;
951 };
952 
960 };
961 
975  std::vector<std::string> top_level_columns_with_schema_mismatch;
976 
981  std::string column_name;
982  std::vector<size_type> row_indices;
983  };
984 
994  std::vector<schema_mismatch_rows> top_level_columns_with_schema_mismatch_rows;
995 };
996 
1004 };
1005 
1022  json_reader_options options,
1025 
1042  json_reader_options options,
1045  // end of group
1047 
1057 
1062  // Specify the sink to use for writer output
1063  sink_info _sink;
1064  // Specify the compression format of the sink
1065  compression_type _compression = compression_type::NONE;
1066  // maximum number of rows to write in each chunk (limits memory use)
1067  size_type _rows_per_chunk = std::numeric_limits<size_type>::max();
1068  // Set of columns to output
1069  table_view _table;
1070  // string to use for null entries
1071  std::string _na_rep = "";
1072  // Indicates whether to output nulls as 'null' or exclude the field
1073  bool _include_nulls = false;
1074  // Indicates whether to use JSON lines for records format
1075  bool _lines = false;
1076  // string to use for values != 0 in INT8 types (default 'true')
1077  std::string _true_value = std::string{"true"};
1078  // string to use for values == 0 in INT8 types (default 'false')
1079  std::string _false_value = std::string{"false"};
1080  // Names of all columns; if empty, writer will generate column names
1081  std::optional<table_metadata> _metadata; // Optional column names
1082  // Indicates whether to escape UTF-8 characters in JSON output
1083  bool _enable_utf8_escaped = true;
1084 
1092  : _sink(std::move(sink)), _rows_per_chunk(table.num_rows()), _table(std::move(table))
1093  {
1094  }
1095 
1097 
1098  public:
1104  explicit json_writer_options() = default;
1105 
1115 
1121  [[nodiscard]] sink_info const& get_sink() const { return _sink; }
1122 
1128  [[nodiscard]] table_view const& get_table() const { return _table; }
1129 
1135  [[nodiscard]] std::optional<table_metadata> const& get_metadata() const { return _metadata; }
1136 
1142  [[nodiscard]] std::string const& get_na_rep() const { return _na_rep; }
1143 
1149  [[nodiscard]] compression_type get_compression() const { return _compression; }
1150 
1156  [[nodiscard]] bool is_enabled_include_nulls() const { return _include_nulls; }
1157 
1163  [[nodiscard]] bool is_enabled_lines() const { return _lines; }
1164 
1176  void enable_utf8_escaped(bool val) { _enable_utf8_escaped = val; }
1177 
1183  [[nodiscard]] bool is_enabled_utf8_escaped() const { return _enable_utf8_escaped; }
1184 
1190  [[nodiscard]] size_type get_rows_per_chunk() const { return _rows_per_chunk; }
1191 
1197  [[nodiscard]] std::string const& get_true_value() const { return _true_value; }
1198 
1204  [[nodiscard]] std::string const& get_false_value() const { return _false_value; }
1205 
1206  // Setter
1207 
1213  void set_table(table_view tbl) { _table = tbl; }
1214 
1220  void set_compression(compression_type comptype) { _compression = comptype; }
1221 
1227  void set_metadata(table_metadata metadata) { _metadata = std::move(metadata); }
1228 
1234  void set_na_rep(std::string val) { _na_rep = std::move(val); }
1235 
1241  void enable_include_nulls(bool val) { _include_nulls = val; }
1242 
1248  void enable_lines(bool val) { _lines = val; }
1249 
1255  void set_rows_per_chunk(size_type val) { _rows_per_chunk = val; }
1256 
1262  void set_true_value(std::string val) { _true_value = std::move(val); }
1263 
1269  void set_false_value(std::string val) { _false_value = std::move(val); }
1270 };
1271 
1276  json_writer_options options;
1277 
1278  public:
1284  explicit json_writer_options_builder() = default;
1285 
1293  : options{sink, table}
1294  {
1295  }
1296 
1304  {
1305  options._table = tbl;
1306  return *this;
1307  }
1308 
1316  {
1317  options._compression = comptype;
1318  return *this;
1319  }
1320 
1328  {
1329  options._metadata = std::move(metadata);
1330  return *this;
1331  }
1332 
1340  {
1341  options._na_rep = std::move(val);
1342  return *this;
1343  };
1344 
1352  {
1353  options._include_nulls = val;
1354  return *this;
1355  }
1356 
1366  {
1367  options._enable_utf8_escaped = val;
1368  return *this;
1369  }
1370 
1378  {
1379  options._lines = val;
1380  return *this;
1381  }
1382 
1390  {
1391  options._rows_per_chunk = val;
1392  return *this;
1393  }
1394 
1402  {
1403  options._true_value = std::move(val);
1404  return *this;
1405  }
1406 
1414  {
1415  options._false_value = std::move(val);
1416  return *this;
1417  }
1418 
1422  operator json_writer_options&&() { return std::move(options); }
1423 
1431  json_writer_options&& build() { return std::move(options); }
1432 };
1433 
1451 void write_json(json_writer_options const& options,
1453 
1455 struct is_supported_json_write_type_fn {
1456  template <typename T>
1457  constexpr bool operator()() const
1458  {
1459  return cudf::io::detail::is_convertible_to_string_column<T>();
1460  }
1461 };
1463 
1471 {
1472  return cudf::type_dispatcher(type, is_supported_json_write_type_fn{});
1473 }
1474  // end of group
1476 } // namespace io
1477 } // namespace CUDF_EXPORT cudf
Indicator for the logical data type of an element in a column.
Definition: types.hpp:286
Builds settings to use for read_json().
Definition: json.hpp:591
json_reader_options_builder & normalize_single_quotes(bool val)
Set whether the reader should normalize single quotes around strings.
Definition: json.hpp:793
json_reader_options_builder & nonnumeric_numbers(bool val)
Set whether specific unquoted number values are valid JSON. The values are NaN, +INF,...
Definition: json.hpp:861
json_reader_options_builder & keep_quotes(bool val)
Set whether the reader should keep quotes of string values.
Definition: json.hpp:780
json_reader_options_builder & normalize_whitespace(bool val)
Set whether the reader should normalize unquoted whitespace.
Definition: json.hpp:806
json_reader_options_builder & numeric_leading_zeros(bool val)
Set Whether leading zeros are allowed in numeric values. Strict validation must be enabled for this t...
Definition: json.hpp:845
json_reader_options_builder & dtypes(schema_element types)
Set data types for columns to be read.
Definition: json.hpp:651
json_reader_options_builder & dayfirst(bool val)
Set whether to parse dates as DD/MM versus MM/DD.
Definition: json.hpp:767
json_reader_options_builder & recovery_mode(json_recovery_mode_t val)
Specifies the JSON reader's behavior on invalid JSON lines.
Definition: json.hpp:818
json_reader_options_builder & na_values(std::vector< std::string > vals)
Sets additional values to recognize as null values.
Definition: json.hpp:888
json_reader_options_builder & delimiter(char delimiter)
Set delimiter separating records in JSON lines.
Definition: json.hpp:699
json_reader_options_builder & prune_columns(bool val)
Set whether to prune columns on read, selected based on the dtypes option.
Definition: json.hpp:740
json_reader_options_builder & experimental(bool val)
Set whether to enable experimental features.
Definition: json.hpp:755
json_reader_options_builder & lines(bool val)
Set whether to read the file as a json object per line.
Definition: json.hpp:711
json_reader_options_builder & dtypes(std::vector< data_type > types)
Set data types for columns to be read.
Definition: json.hpp:615
json_reader_options && build()
move json_reader_options member once it's built.
Definition: json.hpp:906
json_reader_options_builder & mixed_types_as_string(bool val)
Set whether to parse mixed types as a string column. Also enables forcing to read a struct as string ...
Definition: json.hpp:724
json_reader_options_builder & unquoted_control_chars(bool val)
Set whether chars >= 0 and < 32 are allowed in a quoted string without some form of escaping....
Definition: json.hpp:876
json_reader_options_builder & compression(compression_type comp_type)
Set the compression type.
Definition: json.hpp:663
json_reader_options_builder(source_info src)
Constructor from source info.
Definition: json.hpp:607
json_reader_options_builder & strict_validation(bool val)
Set whether json validation should be strict or not.
Definition: json.hpp:830
json_reader_options_builder & byte_range_size(size_type size)
Set number of bytes to read.
Definition: json.hpp:687
json_reader_options_builder & dtypes(std::map< std::string, schema_element > types)
Set data types for columns to be read.
Definition: json.hpp:639
json_reader_options_builder & byte_range_offset(size_type offset)
Set number of bytes to skip from source start.
Definition: json.hpp:675
json_reader_options_builder()=default
Default constructor.
json_reader_options_builder & dtypes(std::map< std::string, data_type > types)
Set data types for columns to be read.
Definition: json.hpp:627
Input arguments to the read_json interface.
Definition: json.hpp:89
bool is_allowed_nonnumeric_numbers() const
Whether unquoted number values should be allowed NaN, +INF, -INF, +Infinity, Infinity,...
Definition: json.hpp:353
void enable_mixed_types_as_string(bool val)
Set whether to parse mixed types as a string column. Also enables forcing to read a struct as string ...
Definition: json.hpp:469
void set_compression(compression_type comp_type)
Set the compression type.
Definition: json.hpp:416
void set_dtypes(std::vector< data_type > types)
Set data types for columns to be read.
Definition: json.hpp:387
void allow_unquoted_control_chars(bool val)
Set whether in a quoted string should characters greater than or equal to 0 and less than 32 be allow...
Definition: json.hpp:574
void set_source(source_info src)
Sets source info.
Definition: json.hpp:380
void enable_normalize_single_quotes(bool val)
Set whether the reader should enable normalization of single quotes around strings.
Definition: json.hpp:513
bool is_allowed_numeric_leading_zeros() const
Whether leading zeros are allowed in numeric values.
Definition: json.hpp:340
void enable_prune_columns(bool val)
Set whether to prune columns on read, selected based on the set_dtypes option.
Definition: json.hpp:480
bool is_enabled_keep_quotes() const
Whether the reader should keep quotes of string values.
Definition: json.hpp:303
void set_dtypes(schema_element types)
Set data types for a potentially nested column hierarchy.
void enable_normalize_whitespace(bool val)
Set whether the reader should enable normalization of unquoted whitespace.
Definition: json.hpp:521
void allow_nonnumeric_numbers(bool val)
Set whether unquoted number values should be allowed NaN, +INF, -INF, +Infinity, Infinity,...
Definition: json.hpp:559
size_t get_byte_range_offset() const
Returns number of bytes to skip from source start.
Definition: json.hpp:200
source_info const & get_source() const
Returns source info.
Definition: json.hpp:179
void enable_experimental(bool val)
Set whether to enable experimental features.
Definition: json.hpp:490
void set_dtypes(std::map< std::string, data_type > types)
Set data types for columns to be read.
Definition: json.hpp:394
bool is_enabled_prune_columns() const
Whether to prune columns on read, selected based on the set_dtypes option.
Definition: json.hpp:280
char get_delimiter() const
Returns delimiter separating records in JSON lines.
Definition: json.hpp:254
bool is_enabled_lines() const
Whether to read the file as a json object per line.
Definition: json.hpp:261
void allow_numeric_leading_zeros(bool val)
Set whether leading zeros are allowed in numeric values. Strict validation must be enabled for this t...
Definition: json.hpp:545
void set_strict_validation(bool val)
Set whether strict validation is enabled or not.
Definition: json.hpp:535
bool is_enabled_mixed_types_as_string() const
Whether to parse mixed types as a string column.
Definition: json.hpp:268
json_reader_options()=default
Default constructor.
void set_na_values(std::vector< std::string > vals)
Sets additional values to recognize as null values.
Definition: json.hpp:585
void enable_dayfirst(bool val)
Set whether to parse dates as DD/MM versus MM/DD.
Definition: json.hpp:497
size_t get_byte_range_size_with_padding() const
Returns number of bytes to read with padding.
Definition: json.hpp:214
void set_recovery_mode(json_recovery_mode_t val)
Specifies the JSON reader's behavior on invalid JSON lines.
Definition: json.hpp:528
bool is_enabled_normalize_whitespace() const
Whether the reader should normalize unquoted whitespace characters.
Definition: json.hpp:317
bool is_strict_validation() const
Whether json validation should be enforced strictly or not.
Definition: json.hpp:331
void set_delimiter(char delimiter)
Set delimiter separating records in JSON lines.
Definition: json.hpp:437
void set_byte_range_offset(size_t offset)
Set number of bytes to skip from source start.
Definition: json.hpp:423
void enable_lines(bool val)
Set whether to read the file as a json object per line.
Definition: json.hpp:461
dtype_variant const & get_dtypes() const
Returns data types of the columns.
Definition: json.hpp:186
void enable_keep_quotes(bool val)
Set whether the reader should keep quotes of string values.
Definition: json.hpp:505
bool is_enabled_normalize_single_quotes() const
Whether the reader should normalize single quotes around strings.
Definition: json.hpp:310
compression_type get_compression() const
Returns compression format of the source.
Definition: json.hpp:193
void set_dtypes(std::map< std::string, schema_element > types)
Set data types for a potentially nested column hierarchy.
Definition: json.hpp:401
size_t get_byte_range_size() const
Returns number of bytes to read.
Definition: json.hpp:207
std::variant< std::vector< data_type >, std::map< std::string, data_type >, std::map< std::string, schema_element >, schema_element > dtype_variant
Variant type holding dtypes information for the columns.
Definition: json.hpp:95
bool is_enabled_experimental() const
Whether to enable experimental features.
Definition: json.hpp:289
json_recovery_mode_t recovery_mode() const
Queries the JSON reader's behavior on invalid JSON lines.
Definition: json.hpp:324
static json_reader_options_builder builder(source_info src)
create json_reader_options_builder which will build json_reader_options.
bool is_enabled_dayfirst() const
Whether to parse dates as DD/MM versus MM/DD.
Definition: json.hpp:296
size_t get_byte_range_padding() const
Returns number of bytes to pad when reading.
Definition: json.hpp:228
bool is_allowed_unquoted_control_chars() const
Whether in a quoted string should characters greater than or equal to 0 and less than 32 be allowed w...
Definition: json.hpp:363
std::vector< std::string > const & get_na_values() const
Returns additional values to recognize as null values.
Definition: json.hpp:373
void set_byte_range_size(size_t size)
Set number of bytes to read.
Definition: json.hpp:430
Builder to build options for writer_json()
Definition: json.hpp:1275
json_writer_options_builder & compression(compression_type comptype)
Sets compression type of output sink.
Definition: json.hpp:1315
json_writer_options_builder & include_nulls(bool val)
Enables/Disables output of nulls as 'null'.
Definition: json.hpp:1351
json_writer_options_builder & table(table_view tbl)
Sets table to be written to output.
Definition: json.hpp:1303
json_writer_options_builder()=default
Default constructor.
json_writer_options_builder & rows_per_chunk(int val)
Sets maximum number of rows to process for each file write.
Definition: json.hpp:1389
json_writer_options_builder & utf8_escaped(bool val)
Enables/Disable UTF-8 escaped output for string fields.
Definition: json.hpp:1365
json_writer_options_builder & true_value(std::string val)
Sets string used for values != 0 in INT8 types.
Definition: json.hpp:1401
json_writer_options_builder & false_value(std::string val)
Sets string used for values == 0 in INT8 types.
Definition: json.hpp:1413
json_writer_options_builder(sink_info const &sink, table_view const &table)
Constructor from sink and table.
Definition: json.hpp:1292
json_writer_options_builder & na_rep(std::string val)
Sets string to used for null entries.
Definition: json.hpp:1339
json_writer_options_builder & metadata(table_metadata metadata)
Sets optional metadata (with column names).
Definition: json.hpp:1327
json_writer_options && build()
move json_writer_options member once it's built.
Definition: json.hpp:1431
json_writer_options_builder & lines(bool val)
Enables/Disables JSON lines for records format.
Definition: json.hpp:1377
Settings to use for write_json().
Definition: json.hpp:1061
void set_compression(compression_type comptype)
Sets compression type to be used.
Definition: json.hpp:1220
compression_type get_compression() const
Returns compression type used for sink.
Definition: json.hpp:1149
table_view const & get_table() const
Returns table that would be written to output.
Definition: json.hpp:1128
void set_false_value(std::string val)
Sets string used for values == 0 in INT8 types.
Definition: json.hpp:1269
void enable_include_nulls(bool val)
Enables/Disables output of nulls as 'null'.
Definition: json.hpp:1241
bool is_enabled_include_nulls() const
Whether to output nulls as 'null'.
Definition: json.hpp:1156
void enable_lines(bool val)
Enables/Disables JSON lines for records format.
Definition: json.hpp:1248
void set_na_rep(std::string val)
Sets string to used for null entries.
Definition: json.hpp:1234
static json_writer_options_builder builder(sink_info const &sink, table_view const &table)
Create builder to create json_writer_options.
json_writer_options()=default
Default constructor.
void set_true_value(std::string val)
Sets string used for values != 0 in INT8 types.
Definition: json.hpp:1262
sink_info const & get_sink() const
Returns sink used for writer output.
Definition: json.hpp:1121
void enable_utf8_escaped(bool val)
Enable or disable writing escaped UTF-8 characters in JSON output.
Definition: json.hpp:1176
void set_rows_per_chunk(size_type val)
Sets maximum number of rows to process for each file write.
Definition: json.hpp:1255
std::string const & get_true_value() const
Returns string used for values != 0 in INT8 types.
Definition: json.hpp:1197
void set_table(table_view tbl)
Sets table to be written to output.
Definition: json.hpp:1213
std::string const & get_false_value() const
Returns string used for values == 0 in INT8 types.
Definition: json.hpp:1204
bool is_enabled_lines() const
Whether to use JSON lines for records format.
Definition: json.hpp:1163
bool is_enabled_utf8_escaped() const
Check whether UTF-8 escaped output is enabled.
Definition: json.hpp:1183
size_type get_rows_per_chunk() const
Returns maximum number of rows to process for each file write.
Definition: json.hpp:1190
std::optional< table_metadata > const & get_metadata() const
Returns metadata information.
Definition: json.hpp:1135
std::string const & get_na_rep() const
Returns string to used for null entries.
Definition: json.hpp:1142
void set_metadata(table_metadata metadata)
Sets metadata.
Definition: json.hpp:1227
A set of cudf::column_view's of the same size.
Definition: table_view.hpp:206
A set of cudf::column's of the same size.
Definition: table.hpp:31
size_type num_rows() const noexcept
Returns the number of rows.
Definition: table.hpp:103
Exception types and error-checking macros used throughout libcudf.
rmm::cuda_stream_view const get_default_stream()
Get the current default stream.
json_reader_result read_json_with_diagnostics(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())
Reads a JSON dataset into a set of columns, additionally reporting reader diagnostics that do not bel...
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())
Reads a JSON dataset into a set of columns.
json_reader_result_with_row_diagnostics read_json_with_row_diagnostics(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())
Reads a JSON dataset into a set of columns, additionally reporting reader diagnostics with row-level ...
json_recovery_mode_t
Control the error recovery behavior of the json parser.
Definition: json.hpp:61
@ RECOVER_WITH_NULL
Recovers from an error, replacing invalid records with null.
@ FAIL
Does not recover from an error when encountering an invalid format.
compression_type
Compression algorithms.
Definition: types.hpp:46
void write_json(json_writer_options const &options, rmm::cuda_stream_view stream=cudf::get_default_stream())
Writes a set of columns to JSON format.
constexpr bool is_supported_write_json(data_type type)
Checks if a cudf::data_type is supported for JSON writing.
Definition: json.hpp:1470
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
CUDF_HOST_DEVICE constexpr decltype(auto) __forceinline__ type_dispatcher(cudf::data_type dtype, Functor f, Ts &&... args)
Invokes an operator() template with the type instantiation based on the specified cudf::data_type's i...
#define CUDF_EXPECTS(...)
Macro for checking (pre-)conditions that throws an exception when a condition is violated.
Definition: error.hpp:182
#define CUDF_FAIL(...)
Indicates that an erroneous code path has been taken.
Definition: error.hpp:223
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
Optional diagnostics produced by read_json_with_diagnostics.
Definition: json.hpp:939
std::vector< std::string > top_level_columns_with_schema_mismatch
Top-level column names whose value tree contained at least one JSON node whose category (NC_STRUCT / ...
Definition: json.hpp:950
Result of read_json_with_row_diagnostics: the parsed table together with reader-specific row-level di...
Definition: json.hpp:1001
json_reader_row_diagnostics diagnostics
Reader-specific row-level diagnostics.
Definition: json.hpp:1003
table_with_metadata data
Parsed table and standard table metadata.
Definition: json.hpp:1002
Result of read_json_with_diagnostics: the parsed table together with reader-specific diagnostics.
Definition: json.hpp:957
json_reader_diagnostics diagnostics
Reader-specific diagnostics.
Definition: json.hpp:959
table_with_metadata data
Parsed table and standard table metadata.
Definition: json.hpp:958
Row indices for one top-level column that had schema mismatches.
Definition: json.hpp:980
std::string column_name
Top-level output column name.
Definition: json.hpp:981
std::vector< size_type > row_indices
Rows whose depth-1 ancestor should be nulled.
Definition: json.hpp:982
Optional row-level diagnostics produced by read_json_with_row_diagnostics.
Definition: json.hpp:968
std::vector< std::string > top_level_columns_with_schema_mismatch
Top-level column names whose value tree contained at least one JSON node whose category (NC_STRUCT / ...
Definition: json.hpp:975
std::vector< schema_mismatch_rows > top_level_columns_with_schema_mismatch_rows
Row indices grouped by top-level output column for schema mismatches.
Definition: json.hpp:994
Allows specifying the target types for nested JSON data via json_reader_options' set_dtypes method.
Definition: json.hpp:41
std::optional< std::vector< std::string > > column_order
Allows specifying the order of the columns.
Definition: json.hpp:55
data_type type
The type that this column should be converted to.
Definition: json.hpp:45
std::map< std::string, schema_element > child_types
Allows specifying this column's child columns target type.
Definition: json.hpp:50
Destination information for write interfaces.
Definition: types.hpp:493
Source information for read interfaces.
Definition: types.hpp:306
Table metadata returned by IO readers.
Definition: types.hpp:245
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.