1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18// This module contains the logical parquet-cpp types (independent of Thrift
19// structures), schema nodes, and related type tools
20
21#ifndef PARQUET_SCHEMA_INTERNAL_H
22#define PARQUET_SCHEMA_INTERNAL_H
23
24#include <cstdint>
25#include <memory>
26#include <vector>
27
28#include "parquet/schema.h"
29#include "parquet/types.h"
30#include "parquet/util/macros.h"
31
32namespace parquet {
33
34namespace format {
35class SchemaElement;
36}
37
38namespace schema {
39
40// ----------------------------------------------------------------------
41// Conversion from Parquet Thrift metadata
42
43std::shared_ptr<SchemaDescriptor> FromParquet(
44 const std::vector<format::SchemaElement>& schema);
45
46class FlatSchemaConverter {
47 public:
48 FlatSchemaConverter(const format::SchemaElement* elements, int length)
49 : elements_(elements), length_(length), pos_(0), current_id_(0) {}
50
51 std::unique_ptr<Node> Convert();
52
53 private:
54 const format::SchemaElement* elements_;
55 int length_;
56 int pos_;
57 int current_id_;
58
59 int next_id() { return current_id_++; }
60
61 const format::SchemaElement& Next();
62
63 std::unique_ptr<Node> NextNode();
64};
65
66// ----------------------------------------------------------------------
67// Conversion to Parquet Thrift metadata
68
69void ToParquet(const GroupNode* schema, std::vector<format::SchemaElement>* out);
70
71// Converts nested parquet schema back to a flat vector of Thrift structs
72class SchemaFlattener {
73 public:
74 SchemaFlattener(const GroupNode* schema, std::vector<format::SchemaElement>* out);
75
76 void Flatten();
77
78 private:
79 const GroupNode* root_;
80 std::vector<format::SchemaElement>* elements_;
81};
82
83} // namespace schema
84} // namespace parquet
85
86#endif // PARQUET_SCHEMA_INTERNAL_H
87