Skip to content

Commit

Permalink
use unordered_map; transform
Browse files Browse the repository at this point in the history
  • Loading branch information
vuule committed May 6, 2022
1 parent 4a4bda7 commit 88b08a2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cpp/include/cudf/io/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ struct table_metadata {
schema_info; //!< Detailed name information for the entire output hierarchy
std::map<std::string, std::string> user_data; //!< Format-dependent metadata of the first input
//!< file as key-values pairs (deprecated)
std::vector<std::map<std::string, std::string>>
std::vector<std::unordered_map<std::string, std::string>>
per_file_user_data; //!< Per file format-dependent metadata as key-values pairs
};

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/io/avro/reader_impl.cu
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ table_with_metadata read_avro(std::unique_ptr<cudf::io::datasource>&& source,
}
// Return user metadata
metadata_out.user_data = meta.user_data;
metadata_out.per_file_user_data = {meta.user_data};
metadata_out.per_file_user_data = {{meta.user_data.begin(), meta.user_data.end()}};

return {std::make_unique<table>(std::move(out_columns)), std::move(metadata_out)};
}
Expand Down
14 changes: 9 additions & 5 deletions cpp/src/io/orc/reader_impl.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1266,13 +1266,17 @@ table_with_metadata reader::impl::read(size_type skip_rows,
_metadata.per_file_metadata.cend(),
std::back_inserter(out_metadata.per_file_user_data),
[](auto& meta) {
std::map<std::string, std::string> kv_map;
for (auto& kv : meta.ff.metadata) {
kv_map[kv.name] = kv.value;
}
std::unordered_map<std::string, std::string> kv_map;
std::transform(meta.ff.metadata.cbegin(),
meta.ff.metadata.cend(),
std::inserter(kv_map, kv_map.end()),
[](auto const& kv) {
return std::pair{kv.name, kv.value};
});
return kv_map;
});
out_metadata.user_data = out_metadata.per_file_user_data[0];
out_metadata.user_data = {out_metadata.per_file_user_data[0].begin(),
out_metadata.per_file_user_data[0].end()};

return {std::make_unique<table>(std::move(out_columns)), std::move(out_metadata)};
}
Expand Down
9 changes: 5 additions & 4 deletions cpp/src/io/parquet/reader_impl.cu
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ struct metadata : public FileMetaData {

class aggregate_reader_metadata {
std::vector<metadata> per_file_metadata;
std::vector<std::map<std::string, std::string>> keyval_maps;
std::vector<std::unordered_map<std::string, std::string>> keyval_maps;
size_type num_rows;
size_type num_row_groups;
/**
Expand All @@ -339,12 +339,12 @@ class aggregate_reader_metadata {
*/
[[nodiscard]] auto collect_keyval_metadata()
{
std::vector<std::map<std::string, std::string>> kv_maps;
std::vector<std::unordered_map<std::string, std::string>> kv_maps;
std::transform(per_file_metadata.cbegin(),
per_file_metadata.cend(),
std::back_inserter(kv_maps),
[](auto const& pfm) {
std::map<std::string, std::string> kv_map;
std::unordered_map<std::string, std::string> kv_map;
std::transform(pfm.key_value_metadata.cbegin(),
pfm.key_value_metadata.cend(),
std::inserter(kv_map, kv_map.end()),
Expand Down Expand Up @@ -1770,7 +1770,8 @@ table_with_metadata reader::impl::read(size_type skip_rows,

// Return user metadata
out_metadata.per_file_user_data = _metadata->get_key_value_metadata();
out_metadata.user_data = out_metadata.per_file_user_data[0];
out_metadata.user_data = {out_metadata.per_file_user_data[0].begin(),
out_metadata.per_file_user_data[0].end()};

return {std::make_unique<table>(std::move(out_columns)), std::move(out_metadata)};
}
Expand Down

0 comments on commit 88b08a2

Please sign in to comment.