|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +#include "iceberg/manifest_reader.h" |
| 21 | + |
| 22 | +#include "iceberg/manifest_entry.h" |
| 23 | +#include "iceberg/manifest_list.h" |
| 24 | +#include "iceberg/manifest_reader_internal.h" |
| 25 | +#include "iceberg/schema.h" |
| 26 | +#include "iceberg/util/macros.h" |
| 27 | + |
| 28 | +namespace iceberg { |
| 29 | + |
| 30 | +Result<std::unique_ptr<ManifestReader>> ManifestReader::MakeReader( |
| 31 | + std::string_view manifest_location, std::shared_ptr<FileIO> file_io, |
| 32 | + std::shared_ptr<Schema> partition_schema) { |
| 33 | + auto manifest_entry_schema = ManifestEntry::TypeFromPartitionType(partition_schema); |
| 34 | + auto fields_span = manifest_entry_schema->fields(); |
| 35 | + std::vector<SchemaField> fields(fields_span.begin(), fields_span.end()); |
| 36 | + auto schema = std::make_shared<Schema>(fields); |
| 37 | + ICEBERG_ASSIGN_OR_RAISE( |
| 38 | + auto reader, ReaderFactoryRegistry::Open(FileFormatType::kAvro, |
| 39 | + {.path = std::string(manifest_location), |
| 40 | + .io = std::move(file_io), |
| 41 | + .projection = schema})); |
| 42 | + return std::make_unique<ManifestReaderImpl>(std::move(reader), std::move(schema)); |
| 43 | +} |
| 44 | + |
| 45 | +Result<std::unique_ptr<ManifestListReader>> ManifestListReader::MakeReader( |
| 46 | + std::string_view manifest_list_location, std::shared_ptr<FileIO> file_io) { |
| 47 | + std::vector<SchemaField> fields(ManifestFile::Type().fields().begin(), |
| 48 | + ManifestFile::Type().fields().end()); |
| 49 | + auto schema = std::make_shared<Schema>(fields); |
| 50 | + ICEBERG_ASSIGN_OR_RAISE(auto reader, ReaderFactoryRegistry::Open( |
| 51 | + FileFormatType::kAvro, |
| 52 | + {.path = std::string(manifest_list_location), |
| 53 | + .io = std::move(file_io), |
| 54 | + .projection = schema})); |
| 55 | + return std::make_unique<ManifestListReaderImpl>(std::move(reader), std::move(schema)); |
| 56 | +} |
| 57 | + |
| 58 | +} // namespace iceberg |
0 commit comments