parquet_metadata.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023-2025, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
22 #pragma once
23 
25 #include <cudf/io/types.hpp>
26 #include <cudf/utilities/export.hpp>
27 
28 #include <string_view>
29 #include <vector>
30 
31 namespace CUDF_EXPORT cudf {
32 namespace io {
41 
46  public:
52  explicit parquet_column_schema() = default;
53 
61  parquet_column_schema(std::string_view name,
62  Type type,
63  std::vector<parquet_column_schema> children)
64  : _name{name}, _type{type}, _children{std::move(children)}
65  {
66  }
67 
73  [[nodiscard]] auto name() const { return _name; }
74 
80  [[nodiscard]] auto type() const { return _type; }
81 
87  [[nodiscard]] auto const& children() const& { return _children; }
88 
93  [[nodiscard]] auto children() && { return std::move(_children); }
94 
102  [[nodiscard]] auto const& child(int idx) const& { return children().at(idx); }
103 
108  [[nodiscard]] auto child(int idx) && { return std::move(children().at(idx)); }
109 
115  [[nodiscard]] auto num_children() const { return children().size(); }
116 
117  private:
118  std::string _name;
119  // 3 types available: Physical, Converted, Logical
120  Type _type; // Physical type
121  std::vector<parquet_column_schema> _children;
122 };
123 
128  public:
134  explicit parquet_schema() = default;
135 
141  parquet_schema(parquet_column_schema root_column_schema) : _root{std::move(root_column_schema)} {}
142 
148  [[nodiscard]] auto const& root() const& { return _root; }
149 
154  [[nodiscard]] auto root() && { return std::move(_root); }
155 
156  private:
157  parquet_column_schema _root;
158 };
159 
164  public:
166  using key_value_metadata = std::unordered_map<std::string, std::string>;
168  using row_group_metadata = std::unordered_map<std::string, int64_t>;
170  using column_chunk_metadata = std::unordered_map<std::string, std::vector<int64_t>>;
171 
177  explicit parquet_metadata() = default;
178 
192  int64_t num_rows,
193  size_type num_rowgroups,
194  std::vector<size_type> num_rowgroups_per_file,
195  key_value_metadata file_metadata,
196  std::vector<row_group_metadata> rg_metadata,
198  : _schema{std::move(schema)},
199  _num_rows{num_rows},
200  _num_rowgroups{num_rowgroups},
201  _num_rowgroups_per_file{std::move(num_rowgroups_per_file)},
202  _file_metadata{std::move(file_metadata)},
203  _rowgroup_metadata{std::move(rg_metadata)},
204  _column_chunk_metadata{std::move(column_chunk_metadata)}
205  {
206  }
207 
213  [[nodiscard]] auto const& schema() const { return _schema; }
214 
222  [[nodiscard]] auto num_rows() const { return _num_rows; }
223 
229  [[nodiscard]] auto num_rowgroups() const { return _num_rowgroups; }
230 
236  [[nodiscard]] auto const& num_rowgroups_per_file() const { return _num_rowgroups_per_file; }
237 
243  [[nodiscard]] auto const& metadata() const { return _file_metadata; }
244 
250  [[nodiscard]] auto const& rowgroup_metadata() const { return _rowgroup_metadata; }
251 
259  [[nodiscard]] auto const& columnchunk_metadata() const { return _column_chunk_metadata; }
260 
261  private:
262  parquet_schema _schema;
263  int64_t _num_rows;
264  size_type _num_rowgroups;
265  std::vector<size_type> _num_rowgroups_per_file;
266  key_value_metadata _file_metadata;
267  std::vector<row_group_metadata> _rowgroup_metadata;
268  column_chunk_metadata _column_chunk_metadata;
269 };
270 
282  // end of group
284 } // namespace io
285 } // namespace CUDF_EXPORT cudf
Information about content of a parquet file.
auto const & schema() const
Returns the parquet schema.
auto const & rowgroup_metadata() const
Returns the row group metadata in the file footer.
auto const & metadata() const
Returns the Key value metadata in the file footer.
parquet_metadata()=default
Default constructor.
parquet_metadata(parquet_schema schema, int64_t num_rows, size_type num_rowgroups, std::vector< size_type > num_rowgroups_per_file, key_value_metadata file_metadata, std::vector< row_group_metadata > rg_metadata, column_chunk_metadata column_chunk_metadata)
constructor
auto num_rowgroups() const
Returns the total number of rowgroups.
std::unordered_map< std::string, std::vector< int64_t > > column_chunk_metadata
Column chunk metadata from each ColumnChunkMetaData element.
std::unordered_map< std::string, int64_t > row_group_metadata
Row group metadata from each RowGroup element.
auto const & columnchunk_metadata() const
Returns a map of column names to vectors of total_uncompressed_size metadata from all their column ch...
auto num_rows() const
Returns the number of rows of the root column.
auto const & num_rowgroups_per_file() const
Returns the number of rowgroups in each file.
std::unordered_map< std::string, std::string > key_value_metadata
Key-value metadata in the file footer.
parquet_metadata read_parquet_metadata(source_info const &src_info)
Reads metadata of parquet dataset.
Type
Basic data types in Parquet, determines how data is physically stored.
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:95
cuDF-IO API type definitions
cuDF interfaces
Definition: host_udf.hpp:37
Parquet footer schema structs.
Schema of a parquet column, including the nested columns.
auto const & child(int idx) const &
Returns schema of the child with the given index.
auto name() const
Returns parquet column name; can be empty.
auto const & children() const &
Returns schemas of all child columns.
auto type() const
Returns parquet physical type of the column.
auto children() &&
Returns schemas of all child columns.
auto num_children() const
Returns the number of child columns.
parquet_column_schema()=default
Default constructor.
parquet_column_schema(std::string_view name, Type type, std::vector< parquet_column_schema > children)
constructor
auto child(int idx) &&
Returns schema of the child with the given index.
Schema of a parquet file.
parquet_schema()=default
Default constructor.
auto root() &&
Returns the schema of the struct column that contains all columns as fields.
auto const & root() const &
Returns the schema of the struct column that contains all columns as fields.
parquet_schema(parquet_column_schema root_column_schema)
constructor
Source information for read interfaces.
Definition: io/types.hpp:327