33 namespace CUDF_EXPORT
cudf {
41 class json_reader_options_builder;
94 std::variant<std::vector<data_type>,
95 std::map<std::string, data_type>,
96 std::map<std::string, schema_element>>
104 bool _mixed_types_as_string =
false;
106 char _delimiter =
'\n';
108 bool _prune_columns =
false;
111 size_t _byte_range_offset = 0;
113 size_t _byte_range_size = 0;
116 bool _dayfirst =
false;
119 bool _legacy =
false;
122 bool _keep_quotes =
false;
125 bool _normalize_single_quotes =
false;
128 bool _normalize_whitespace =
false;
170 [[nodiscard]] std::variant<std::vector<data_type>,
171 std::map<std::string, data_type>,
172 std::map<std::string, schema_element>>
const&
206 if (_byte_range_size == 0) {
209 return _byte_range_size + get_byte_range_padding();
220 auto const num_columns = std::visit([](
auto const& dtypes) {
return dtypes.size(); }, _dtypes);
222 auto const max_row_bytes = 16 * 1024;
223 auto const column_bytes = 64;
224 auto const base_padding = 1024;
226 if (num_columns == 0) {
228 return max_row_bytes;
232 return base_padding + num_columns * column_bytes;
308 void set_dtypes(std::vector<data_type> types) { _dtypes = std::move(types); }
315 void set_dtypes(std::map<std::string, data_type> types) { _dtypes = std::move(types); }
322 void set_dtypes(std::map<std::string, schema_element> types) { _dtypes = std::move(types); }
364 case '\r':
CUDF_FAIL(
"Unsupported delimiter character.", std::invalid_argument);
break;
366 _delimiter = delimiter;
463 options._dtypes = std::move(types);
475 options._dtypes = std::move(types);
487 options._dtypes = std::move(types);
499 options._compression = comp_type;
511 options._byte_range_offset = offset;
523 options._byte_range_size = size;
547 options._lines = val;
560 options._mixed_types_as_string = val;
576 options._prune_columns = val;
588 options._dayfirst = val;
601 options._keep_quotes = val;
614 options._normalize_single_quotes = val;
627 options._normalize_whitespace = val;
639 options._recovery_mode = val;
702 std::string _na_rep =
"";
704 bool _include_nulls =
false;
708 size_type _rows_per_chunk = std::numeric_limits<size_type>::max();
710 std::string _true_value = std::string{
"true"};
712 std::string _false_value = std::string{
"false"};
714 std::optional<table_metadata> _metadata;
766 [[nodiscard]] std::optional<table_metadata>
const&
get_metadata()
const {
return _metadata; }
773 [[nodiscard]] std::string
const&
get_na_rep()
const {
return _na_rep; }
831 void set_na_rep(std::string val) { _na_rep = std::move(val); }
890 : options{sink,
table}
902 options._table = tbl;
914 options._metadata = std::move(metadata);
926 options._na_rep = std::move(val);
938 options._include_nulls = val;
950 options._lines = val;
962 options._rows_per_chunk = val;
974 options._true_value = std::move(val);
986 options._false_value = std::move(val);
Indicator for the logical data type of an element in a column.
Builds settings to use for read_json().
json_reader_options_builder & normalize_single_quotes(bool val)
Set whether the reader should normalize single quotes around strings.
json_reader_options_builder & keep_quotes(bool val)
Set whether the reader should keep quotes of string values.
json_reader_options_builder & normalize_whitespace(bool val)
Set whether the reader should normalize unquoted whitespace.
json_reader_options_builder & dayfirst(bool val)
Set whether to parse dates as DD/MM versus MM/DD.
json_reader_options_builder & recovery_mode(json_recovery_mode_t val)
Specifies the JSON reader's behavior on invalid JSON lines.
json_reader_options_builder & delimiter(char delimiter)
Set delimiter separating records in JSON lines.
json_reader_options_builder & prune_columns(bool val)
Set whether to prune columns on read, selected based on the dtypes option.
json_reader_options_builder & lines(bool val)
Set whether to read the file as a json object per line.
json_reader_options_builder & dtypes(std::vector< data_type > types)
Set data types for columns to be read.
json_reader_options && build()
move json_reader_options member once it's built.
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 ...
json_reader_options_builder & compression(compression_type comp_type)
Set the compression type.
json_reader_options_builder(source_info src)
Constructor from source info.
json_reader_options_builder & byte_range_size(size_type size)
Set number of bytes to read.
json_reader_options_builder & dtypes(std::map< std::string, schema_element > types)
Set data types for columns to be read.
json_reader_options_builder & byte_range_offset(size_type offset)
Set number of bytes to skip from source start.
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.
Input arguments to the read_json interface.
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 ...
void set_compression(compression_type comp_type)
Set the compression type.
void set_dtypes(std::vector< data_type > types)
Set data types for columns to be read.
void enable_normalize_single_quotes(bool val)
Set whether the reader should enable normalization of single quotes around strings.
void enable_prune_columns(bool val)
Set whether to prune columns on read, selected based on the set_dtypes option.
bool is_enabled_keep_quotes() const
Whether the reader should keep quotes of string values.
void enable_normalize_whitespace(bool val)
Set whether the reader should enable normalization of unquoted whitespace.
size_t get_byte_range_offset() const
Returns number of bytes to skip from source start.
source_info const & get_source() const
Returns source info.
void set_dtypes(std::map< std::string, data_type > types)
Set data types for columns to be read.
bool is_enabled_prune_columns() const
Whether to prune columns on read, selected based on the set_dtypes option.
char get_delimiter() const
Returns delimiter separating records in JSON lines.
bool is_enabled_lines() const
Whether to read the file as a json object per line.
bool is_enabled_mixed_types_as_string() const
Whether to parse mixed types as a string column.
json_reader_options()=default
Default constructor.
void enable_dayfirst(bool val)
Set whether to parse dates as DD/MM versus MM/DD.
std::variant< std::vector< data_type >, std::map< std::string, data_type >, std::map< std::string, schema_element > > const & get_dtypes() const
Returns data types of the columns.
size_t get_byte_range_size_with_padding() const
Returns number of bytes to read with padding.
void set_recovery_mode(json_recovery_mode_t val)
Specifies the JSON reader's behavior on invalid JSON lines.
bool is_enabled_normalize_whitespace() const
Whether the reader should normalize unquoted whitespace characters.
void set_delimiter(char delimiter)
Set delimiter separating records in JSON lines.
void set_byte_range_offset(size_t offset)
Set number of bytes to skip from source start.
void enable_lines(bool val)
Set whether to read the file as a json object per line.
void enable_keep_quotes(bool val)
Set whether the reader should keep quotes of string values.
bool is_enabled_normalize_single_quotes() const
Whether the reader should normalize single quotes around strings.
compression_type get_compression() const
Returns compression format of the source.
void set_dtypes(std::map< std::string, schema_element > types)
Set data types for a potentially nested column hierarchy.
size_t get_byte_range_size() const
Returns number of bytes to read.
json_recovery_mode_t recovery_mode() const
Queries the JSON reader's behavior on invalid JSON lines.
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.
size_t get_byte_range_padding() const
Returns number of bytes to pad when reading.
void set_byte_range_size(size_t size)
Set number of bytes to read.
Builder to build options for writer_json()
json_writer_options_builder & include_nulls(bool val)
Enables/Disables output of nulls as 'null'.
json_writer_options_builder & table(table_view tbl)
Sets table to be written to output.
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.
json_writer_options_builder & true_value(std::string val)
Sets string used for values != 0 in INT8 types.
json_writer_options_builder & false_value(std::string val)
Sets string used for values == 0 in INT8 types.
json_writer_options_builder(sink_info const &sink, table_view const &table)
Constructor from sink and table.
json_writer_options_builder & na_rep(std::string val)
Sets string to used for null entries.
json_writer_options_builder & metadata(table_metadata metadata)
Sets optional metadata (with column names).
json_writer_options && build()
move json_writer_options member once it's built.
json_writer_options_builder & lines(bool val)
Enables/Disables JSON lines for records format.
Settings to use for write_json().
table_view const & get_table() const
Returns table that would be written to output.
void set_false_value(std::string val)
Sets string used for values == 0 in INT8 types.
void enable_include_nulls(bool val)
Enables/Disables output of nulls as 'null'.
bool is_enabled_include_nulls() const
Whether to output nulls as 'null'.
void enable_lines(bool val)
Enables/Disables JSON lines for records format.
void set_na_rep(std::string val)
Sets string to used for null entries.
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.
sink_info const & get_sink() const
Returns sink used for writer output.
void set_rows_per_chunk(size_type val)
Sets maximum number of rows to process for each file write.
std::string const & get_true_value() const
Returns string used for values != 0 in INT8 types.
void set_table(table_view tbl)
Sets table to be written to output.
std::string const & get_false_value() const
Returns string used for values == 0 in INT8 types.
bool is_enabled_lines() const
Whether to use JSON lines for records format.
size_type get_rows_per_chunk() const
Returns maximum number of rows to process for each file write.
std::optional< table_metadata > const & get_metadata() const
Returns metadata information.
std::string const & get_na_rep() const
Returns string to used for null entries.
void set_metadata(table_metadata metadata)
Sets metadata.
A set of cudf::column_view's of the same size.
A set of cudf::column's of the same size.
size_type num_rows() const noexcept
Returns the number of rows.
rmm::cuda_stream_view const get_default_stream()
Get the current 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=rmm::mr::get_current_device_resource())
Reads a JSON dataset into a set of columns.
json_recovery_mode_t
Control the error recovery behavior of the json parser.
@ 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.
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.
cuda::mr::async_resource_ref< cuda::mr::device_accessible > device_async_resource_ref
device_memory_resource * get_current_device_resource()
#define CUDF_FAIL(...)
Indicates that an erroneous code path has been taken.
int32_t size_type
Row index type for columns and tables.
Allows specifying the target types for nested JSON data via json_reader_options' set_dtypes method.
data_type type
The type that this column should be converted to.
std::map< std::string, schema_element > child_types
Allows specifying this column's child columns target type.
Destination information for write interfaces.
Source information for read interfaces.
Class definitions for (mutable)_table_view
Type declarations for libcudf.