parquet_metadata.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023-2024, 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 
24 #include <cudf/io/types.hpp>
25 #include <cudf/utilities/export.hpp>
26 
27 #include <optional>
28 #include <string_view>
29 #include <variant>
30 #include <vector>
31 
32 namespace CUDF_EXPORT cudf {
33 namespace io {
41 namespace parquet {
45 enum class TypeKind : int8_t {
46  UNDEFINED_TYPE = -1, // Undefined for non-leaf nodes
47  BOOLEAN = 0,
48  INT32 = 1,
49  INT64 = 2,
50  INT96 = 3, // Deprecated
51  FLOAT = 4,
52  DOUBLE = 5,
53  BYTE_ARRAY = 6,
54  FIXED_LEN_BYTE_ARRAY = 7,
55 };
56 } // namespace parquet
57 
62  public:
68  explicit parquet_column_schema() = default;
69 
77  parquet_column_schema(std::string_view name,
78  parquet::TypeKind type,
79  std::vector<parquet_column_schema> children)
80  : _name{name}, _type_kind{type}, _children{std::move(children)}
81  {
82  }
83 
89  [[nodiscard]] auto name() const { return _name; }
90 
96  [[nodiscard]] auto type_kind() const { return _type_kind; }
97 
103  [[nodiscard]] auto const& children() const& { return _children; }
104 
109  [[nodiscard]] auto children() && { return std::move(_children); }
110 
118  [[nodiscard]] auto const& child(int idx) const& { return children().at(idx); }
119 
124  [[nodiscard]] auto child(int idx) && { return std::move(children().at(idx)); }
125 
131  [[nodiscard]] auto num_children() const { return children().size(); }
132 
133  private:
134  std::string _name;
135  // 3 types available: Physical, Converted, Logical.
136  parquet::TypeKind _type_kind; // Physical
137  std::vector<parquet_column_schema> _children;
138 };
139 
144  public:
150  explicit parquet_schema() = default;
151 
157  parquet_schema(parquet_column_schema root_column_schema) : _root{std::move(root_column_schema)} {}
158 
164  [[nodiscard]] auto const& root() const& { return _root; }
165 
170  [[nodiscard]] auto root() && { return std::move(_root); }
171 
172  private:
173  parquet_column_schema _root;
174 };
175 
180  public:
182  using key_value_metadata = std::unordered_map<std::string, std::string>;
184  using row_group_metadata = std::unordered_map<std::string, int64_t>;
185 
191  explicit parquet_metadata() = default;
192 
203  int64_t num_rows,
204  size_type num_rowgroups,
205  key_value_metadata file_metadata,
206  std::vector<row_group_metadata> rg_metadata)
207  : _schema{std::move(schema)},
208  _num_rows{num_rows},
209  _num_rowgroups{num_rowgroups},
210  _file_metadata{std::move(file_metadata)},
211  _rowgroup_metadata{std::move(rg_metadata)}
212  {
213  }
214 
220  [[nodiscard]] auto const& schema() const { return _schema; }
221 
229  [[nodiscard]] auto num_rows() const { return _num_rows; }
230 
236  [[nodiscard]] auto num_rowgroups() const { return _num_rowgroups; }
237 
243  [[nodiscard]] auto const& metadata() const { return _file_metadata; }
244 
250  [[nodiscard]] auto const& rowgroup_metadata() const { return _rowgroup_metadata; }
251 
252  private:
253  parquet_schema _schema;
254  int64_t _num_rows;
255  size_type _num_rowgroups;
256  key_value_metadata _file_metadata;
257  std::vector<row_group_metadata> _rowgroup_metadata;
258 };
259 
271  // end of group
273 } // namespace io
274 } // 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(parquet_schema schema, int64_t num_rows, size_type num_rowgroups, key_value_metadata file_metadata, std::vector< row_group_metadata > rg_metadata)
constructor
parquet_metadata()=default
Default constructor.
auto num_rowgroups() const
Returns the number of rowgroups in the file.
std::unordered_map< std::string, int64_t > row_group_metadata
row group metadata from each RowGroup element.
auto num_rows() const
Returns the number of rows of the root column.
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.
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:95
cuDF-IO API type definitions
TypeKind
Basic data types in Parquet, determines how data is physically stored.
cuDF interfaces
Definition: aggregation.hpp:35
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 children() &&
Returns schemas of all child columns.
auto num_children() const
Returns the number of child columns.
auto type_kind() const
Returns parquet type of the column.
parquet_column_schema()=default
Default constructor.
auto child(int idx) &&
Returns schema of the child with the given index.
parquet_column_schema(std::string_view name, parquet::TypeKind type, std::vector< parquet_column_schema > children)
constructor
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:337