Closed
Description
Look at this example:
std::string const json_string = R"({"data": [1, 2, 3], "data": [4, 5, 6]})";
std::map<std::string, cudf::io::schema_element> dtype_schema;
dtype_schema["data"] = cudf::io::schema_element{cudf::data_type{cudf::type_id::STRUCT}, {}};
auto& child_schema = dtype_schema["data"].child_types;
child_schema["a"] = cudf::io::schema_element{cudf::data_type{cudf::type_id::INT64}, {}};
child_schema["b"] = cudf::io::schema_element{cudf::data_type{cudf::type_id::INT64}, {}};
cudf::io::json_reader_options json_lines_options =
cudf::io::json_reader_options::builder(
cudf::io::source_info{json_string.c_str(), json_string.size()})
.dtypes(dtype_schema)
.lines(true);
auto const table = cudf::io::read_json(json_lines_options);
cudf::test::print(table.tbl->get_column(0).view());
Output:
cudf::list_view<int64_t>:
Length : 1
Offsets : 0, 3
1, 2, 3, 4, 5, 6
Notice that the input schema in the example above is "data": STRUCT<"a": INT64, "b": INT64>
. On the other hand, the data
field in the input JSON is an array instead. We can observe that the data
column after parsing (which is a lists column) is just gathered for generating the output. The desired output here should be all nulls instead, and the correct behavior here should be to make sure the output columns have the right types/structures that we are looking for as specified in the input schema.