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#include <iostream>
19
20#include "parquet/api/reader.h"
21#include "parquet/api/schema.h"
22
23int main(int argc, char** argv) {
24 bool help_flag = false;
25 std::string filename;
26
27 for (int i = 1; i < argc; i++) {
28 if (!std::strcmp(argv[i], "-?") || !std::strcmp(argv[i], "-h") ||
29 !std::strcmp(argv[i], "--help")) {
30 help_flag = true;
31 } else {
32 filename = argv[i];
33 }
34 }
35
36 if (argc != 2 || help_flag) {
37 std::cerr << "Usage: parquet-dump-schema [-h] [--help]"
38 << " <filename>" << std::endl;
39 return -1;
40 }
41
42 try {
43 std::unique_ptr<parquet::ParquetFileReader> reader =
44 parquet::ParquetFileReader::OpenFile(filename);
45 PrintSchema(reader->metadata()->schema()->schema_root().get(), std::cout);
46 } catch (const std::exception& e) {
47 std::cerr << "Parquet error: " << e.what() << std::endl;
48 return -1;
49 }
50
51 return 0;
52}
53