libcudf  24.02.00
parquet_metadata.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023, 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 
26 #include <optional>
27 #include <string_view>
28 #include <variant>
29 #include <vector>
30 
31 namespace cudf {
32 namespace io {
40 namespace parquet {
44 enum class TypeKind : int8_t {
45  UNDEFINED_TYPE = -1, // Undefined for non-leaf nodes
46  BOOLEAN = 0,
47  INT32 = 1,
48  INT64 = 2,
49  INT96 = 3, // Deprecated
50  FLOAT = 4,
51  DOUBLE = 5,
52  BYTE_ARRAY = 6,
53  FIXED_LEN_BYTE_ARRAY = 7,
54 };
55 } // namespace parquet
56 
61  public:
69  parquet_column_schema(std::string_view name,
70  parquet::TypeKind type,
71  std::vector<parquet_column_schema> children)
72  : _name{name}, _type_kind{type}, _children{std::move(children)}
73  {
74  }
75 
81  [[nodiscard]] auto name() const { return _name; }
82 
88  [[nodiscard]] auto type_kind() const { return _type_kind; }
89 
95  [[nodiscard]] auto const& children() const& { return _children; }
96 
101  [[nodiscard]] auto children() && { return std::move(_children); }
102 
110  [[nodiscard]] auto const& child(int idx) const& { return children().at(idx); }
111 
116  [[nodiscard]] auto child(int idx) && { return std::move(children().at(idx)); }
117 
123  [[nodiscard]] auto num_children() const { return children().size(); }
124 
125  private:
126  std::string _name;
127  // 3 types available: Physical, Converted, Logical.
128  parquet::TypeKind _type_kind; // Physical
129  std::vector<parquet_column_schema> _children;
130 };
131 
136  public:
142  parquet_schema(parquet_column_schema root_column_schema) : _root{std::move(root_column_schema)} {}
143 
149  [[nodiscard]] auto const& root() const& { return _root; }
150 
155  [[nodiscard]] auto root() && { return std::move(_root); }
156 
157  private:
158  parquet_column_schema _root;
159 };
160 
165  public:
167  using key_value_metadata = std::unordered_map<std::string, std::string>;
168 
178  int64_t num_rows,
180  key_value_metadata file_metadata)
181  : _schema{std::move(schema)},
182  _num_rows{num_rows},
183  _num_rowgroups{num_rowgroups},
184  _file_metadata{std::move(file_metadata)}
185  {
186  }
187 
193  [[nodiscard]] auto const& schema() const { return _schema; }
194 
202  [[nodiscard]] auto num_rows() const { return _num_rows; }
203 
209  [[nodiscard]] auto num_rowgroups() const { return _num_rowgroups; }
215  [[nodiscard]] auto const& metadata() const { return _file_metadata; }
216 
217  private:
218  parquet_schema _schema;
219  int64_t _num_rows;
220  size_type _num_rowgroups;
221  key_value_metadata _file_metadata;
222 };
223 
235  // end of group
237 } // namespace io
238 } // namespace cudf
Information about content of a parquet file.
auto const & schema() const
Returns the parquet schema.
auto const & metadata() const
Returns the Key value metadata in the file footer.
auto num_rowgroups() const
Returns the number of rowgroups in the file.
parquet_metadata(parquet_schema schema, int64_t num_rows, size_type num_rowgroups, key_value_metadata file_metadata)
constructor
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:93
cuDF-IO API type definitions
TypeKind
Basic data types in Parquet, determines how data is physically stored.
cuDF interfaces
Definition: aggregation.hpp:34
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.
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.
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:294