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#ifndef PARQUET_ARROW_SCHEMA_H
19#define PARQUET_ARROW_SCHEMA_H
20
21#include <cstdint>
22#include <memory>
23#include <vector>
24
25#include "arrow/api.h"
26
27#include "parquet/arrow/writer.h"
28#include "parquet/metadata.h"
29#include "parquet/schema.h"
30#include "parquet/util/visibility.h"
31
32namespace arrow {
33
34class Status;
35
36} // namespace arrow
37
38namespace parquet {
39
40class WriterProperties;
41
42namespace arrow {
43
44class ArrowWriterProperties;
45
46PARQUET_EXPORT
47::arrow::Status NodeToField(const schema::Node& node,
48 std::shared_ptr<::arrow::Field>* out);
49
50/// Convert parquet schema to arrow schema with selected indices
51/// \param parquet_schema to be converted
52/// \param column_indices indices of leaf nodes in parquet schema tree. Appearing ordering
53/// matters for the converted schema. Repeated indices are ignored
54/// except for the first one
55/// \param key_value_metadata optional metadata, can be nullptr
56/// \param out the corresponding arrow schema
57/// \return Status::OK() on a successful conversion.
58PARQUET_EXPORT
59::arrow::Status FromParquetSchema(
60 const SchemaDescriptor* parquet_schema, const std::vector<int>& column_indices,
61 const std::shared_ptr<const KeyValueMetadata>& key_value_metadata,
62 std::shared_ptr<::arrow::Schema>* out);
63
64// Without indices
65PARQUET_EXPORT
66::arrow::Status FromParquetSchema(
67 const SchemaDescriptor* parquet_schema,
68 const std::shared_ptr<const KeyValueMetadata>& key_value_metadata,
69 std::shared_ptr<::arrow::Schema>* out);
70
71// Without metadata
72::arrow::Status PARQUET_EXPORT FromParquetSchema(const SchemaDescriptor* parquet_schema,
73 const std::vector<int>& column_indices,
74 std::shared_ptr<::arrow::Schema>* out);
75
76// Without metadata or indices
77::arrow::Status PARQUET_EXPORT FromParquetSchema(const SchemaDescriptor* parquet_schema,
78 std::shared_ptr<::arrow::Schema>* out);
79
80::arrow::Status PARQUET_EXPORT FieldToNode(const std::shared_ptr<::arrow::Field>& field,
81 const WriterProperties& properties,
82 const ArrowWriterProperties& arrow_properties,
83 schema::NodePtr* out);
84
85::arrow::Status PARQUET_EXPORT
86ToParquetSchema(const ::arrow::Schema* arrow_schema, const WriterProperties& properties,
87 const ArrowWriterProperties& arrow_properties,
88 std::shared_ptr<SchemaDescriptor>* out);
89
90::arrow::Status PARQUET_EXPORT ToParquetSchema(const ::arrow::Schema* arrow_schema,
91 const WriterProperties& properties,
92 std::shared_ptr<SchemaDescriptor>* out);
93
94PARQUET_EXPORT
95int32_t DecimalSize(int32_t precision);
96
97} // namespace arrow
98
99} // namespace parquet
100
101#endif // PARQUET_ARROW_SCHEMA_H
102