Repository navigation
JSON Column creation in GPU - #11714
Conversation
…eric-type-casting
…f-column-type-conversion
…n-explicit-schema
…f-column-type-conversion
…f into fea-json-column-gpu
upsj
left a comment
There was a problem hiding this comment.
flushing my first comments, only json_column_to_cudf_colum2 and make_json_column2 to go. Looks really good so far
| // Map of child columns, if applicable. | ||
| // Following "element" as the default child column's name of a list column | ||
| // Using the struct's field names | ||
| std::map<std::string, d_json_column> child_columns; |
There was a problem hiding this comment.
Since you keep the order in column_order:
| std::map<std::string, d_json_column> child_columns; | |
| std::unordered_map<std::string, d_json_column> child_columns; |
There was a problem hiding this comment.
I followed the same types used in json_column. will optimize this in a follow up PR.
| thrust::reduce_by_key(rmm::exec_policy(stream), | ||
| col_ids.begin(), | ||
| col_ids.end(), | ||
| row_offsets.begin(), | ||
| unique_col_ids.begin(), | ||
| max_row_offsets.begin(), | ||
| thrust::equal_to<size_type>(), | ||
| thrust::maximum<size_type>()); | ||
| // 3. reduce_by_key {col_id}, {node_categories} - custom opp (*+v=*, v+v=v, *+#=E) | ||
| rmm::device_uvector<NodeT> column_categories(num_columns, stream); | ||
| thrust::reduce_by_key( |
There was a problem hiding this comment.
These two could be fused, though I'm not sure it's worth the effort
| static_cast<size_type>(thrust::get<1>(offsets) - thrust::get<0>(offsets))); | ||
| }); | ||
| auto d_column_names = cudf::make_strings_column(string_views, stream); | ||
| auto to_host = [](auto const& col) { |
There was a problem hiding this comment.
nit: This (almost) IIFE seems redundant, if you return its result from the function again.
There was a problem hiding this comment.
This is mostly for readability, and modularity.
| // build std::string vector from chars and offsets | ||
| std::vector<std::string> host_data; | ||
| host_data.reserve(col.size()); | ||
| std::transform( |
There was a problem hiding this comment.
nice! I wasn't aware of the two-range version of this algorithm
upsj
left a comment
There was a problem hiding this comment.
there are some details of the columnar layout I'm not familiar enough with to evaluate them, but the rest (algorithms, code) looks really good!
| parent_col_ids = parent_col_ids.begin(), | ||
| max_row_offsets = max_row_offsets.begin()] __device__(size_type col_id) { | ||
| auto parent_col_id = parent_col_ids[col_id]; | ||
| while (parent_col_id != parent_node_sentinel and |
There was a problem hiding this comment.
If this ever became a performance issue for complex structs, you could consider caching the struct roots with a parallel path compression-like approach.
There was a problem hiding this comment.
won't it be susceptible to RAW, WAR race conditions? (In this case, it may not matter since the path will end up correct anyway.)
Also, will do it in another PR for optimizations.
There was a problem hiding this comment.
Yes, you'd probably need atomic loads/stores to do it safely. But this may not be worth the effort anyways, just a random idea :)
| d_columns_data[original_col_ids[parent_node_id]] | ||
| .child_offsets[row_offsets[parent_node_id]] = ordered_row_offsets[i]; | ||
| } | ||
| // TODO: verify if this code is right. check with more test cases. |
There was a problem hiding this comment.
This should be correct if the ordered_parent_node_ids are also grouped together (not necessarily sorted, but all equal elements in the same range). I'd assume this is the case, but maybe you can confirm.
|
rerun tests |
1 similar comment
|
rerun tests |
vuule
left a comment
There was a problem hiding this comment.
Great stuff 🔥
I have one major suggestion (fallback to CPU code) and a bunch of non-blocking nitpicks.
| auto data = host_span<char const>(reinterpret_cast<char const*>(buffer.data()), buffer.size()); | ||
|
|
||
| return cudf::io::json::detail::parse_nested_json(data, reader_opts, stream, mr); | ||
| return cudf::io::json::detail::parse_nested_json2(data, reader_opts, stream, mr); |
There was a problem hiding this comment.
Would something like this make sense?
| return cudf::io::json::detail::parse_nested_json2(data, reader_opts, stream, mr); | |
| try { | |
| return cudf::io::json::detail::parse_nested_json2(data, reader_opts, stream, mr); | |
| } catch (cudf::logic_error const& err) { | |
| return cudf::io::json::detail::parse_nested_json(data, reader_opts, stream, mr); | |
| } |
There was a problem hiding this comment.
added a print to stdout about fallback.
|
@gpucibot merge |
Description
This PR generates json column creation from the traversed json tree. It has following parts
reduce_to_column_tree- Reduce node tree into column tree by aggregating each property of each column and number of rows in each column.make_json_column2- creates the GPU json column tree structure from tree and column infojson_column_to_cudf_column2- converts this GPU json column to cudf column.parse_nested_json2- combines all json tokenizer, json tree generation, traversal, json column creation, cudf column conversion together. All steps run on device.Depends on PR #11518 #11610
For code-review, use PR karthikeyann#5 which contains only this tree changes.
Overview
cudf::columnJSON has 5 categories of nodes. STRUCT, LIST, FIELD, VALUE, STRING,
STRUCT, LIST are nested types.
FIELD nodes are struct columns' keys.
VALUE node is similar to STRING column but without double quotes. Actual datatype conversion happens in
json_column_to_cudf_column2Tree Representation
tree_meta_thas 4 data members.Currently supported JSON formats are records orient, and JSON lines.
This PR - Detailed explanation
This PR has 3 steps.
reduce_to_column_treetree_meta_tdata members for column.make_json_column2d_json_columnfor non-field columns.d_json_columnis nested, and contains offsets, validity bits, unparsed unconverted string information.json_column_to_cudf_column2- converts this GPU json column to cudf column.d_json_columnand converts tocudf::columnby inferring the type, parsing the string to type, and setting validity bits further.parse_nested_json2- combines all json tokenizer, json tree generation, traversal, json column creation, cudf column conversion together. All steps run on device.Checklist