-
Notifications
You must be signed in to change notification settings - Fork 70
feat: add file writer and manifest writer interface definition #160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| /// \file iceberg/file_writer.h | ||
| /// Writer interface for file formats like Parquet, Avro and ORC. | ||
|
|
||
| #include <functional> | ||
| #include <memory> | ||
| #include <optional> | ||
|
|
||
| #include "iceberg/arrow_c_data.h" | ||
| #include "iceberg/file_format.h" | ||
| #include "iceberg/result.h" | ||
| #include "iceberg/type_fwd.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| /// \brief Options for creating a writer. | ||
| struct ICEBERG_EXPORT WriterOptions { | ||
| /// \brief The path to the file to write. | ||
| std::string path; | ||
| /// \brief The schema of the data to write. | ||
| ArrowSchema schema; | ||
| /// \brief FileIO instance to open the file. Writer implementations should down cast it | ||
| /// to the specific FileIO implementation. By default, the `iceberg-bundle` library uses | ||
| /// `ArrowFileSystemFileIO` as the default implementation. | ||
| std::shared_ptr<class FileIO> io; | ||
| /// \brief Format-specific or implementation-specific properties. | ||
| std::unordered_map<std::string, std::string> properties; | ||
| }; | ||
|
|
||
| /// \brief Base writer class to write data from different file formats. | ||
| class ICEBERG_EXPORT Writer { | ||
| public: | ||
| virtual ~Writer() = default; | ||
| Writer() = default; | ||
| Writer(const Writer&) = delete; | ||
| Writer& operator=(const Writer&) = delete; | ||
|
|
||
| /// \brief Open the writer. | ||
| virtual Status Open(const struct WriterOptions& options) = 0; | ||
|
|
||
| /// \brief Close the writer. | ||
| virtual Status Close() = 0; | ||
|
|
||
| /// \brief Write arrow data to the file. | ||
| /// | ||
| /// \return Status of write results. | ||
| virtual Status Write(const ArrowArray& data) = 0; | ||
| }; | ||
|
|
||
| /// \brief Factory function to create a writer of a specific file format. | ||
| using WriterFactory = std::function<Result<std::unique_ptr<Writer>>()>; | ||
|
|
||
| /// \brief Registry of writer factories for different file formats. | ||
| struct ICEBERG_EXPORT WriterFactoryRegistry { | ||
| /// \brief Register a factory function for a specific file format. | ||
| WriterFactoryRegistry(FileFormatType format_type, WriterFactory factory); | ||
|
|
||
| /// \brief Get the factory function for a specific file format. | ||
| static WriterFactory& GetFactory(FileFormatType format_type); | ||
|
|
||
| /// \brief Open a writer for a specific file format. | ||
| static Result<std::unique_ptr<Writer>> Open(FileFormatType format_type, | ||
| const WriterOptions& options); | ||
| }; | ||
|
|
||
| } // namespace iceberg | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| /// \file iceberg/manifest_writer.h | ||
| /// Data writer interface for manifest files. | ||
|
|
||
| #include <memory> | ||
| #include <vector> | ||
|
|
||
| #include "iceberg/file_writer.h" | ||
| #include "iceberg/iceberg_export.h" | ||
| #include "iceberg/type_fwd.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| /// \brief Write manifest entries to a manifest file. | ||
| class ICEBERG_EXPORT ManifestWriter { | ||
| public: | ||
| virtual ~ManifestWriter() = default; | ||
| virtual Status WriteManifestEntries( | ||
| const std::vector<ManifestEntry>& entries) const = 0; | ||
|
|
||
| /// \brief Creates a writer for a manifest file. | ||
| /// \param manifest_location Path to the manifest file. | ||
| /// \param file_io File IO implementation to use. | ||
| /// \return A Result containing the writer or an error. | ||
| static Result<std::unique_ptr<ManifestWriter>> MakeWriter( | ||
| std::string_view manifest_location, std::shared_ptr<FileIO> file_io, | ||
| std::shared_ptr<Schema> partition_schema); | ||
| }; | ||
|
|
||
| /// \brief Write manifest files to a manifest list file. | ||
| class ICEBERG_EXPORT ManifestListWriter { | ||
| public: | ||
| virtual ~ManifestListWriter() = default; | ||
| virtual Status WriteManifestFiles(const std::vector<ManifestFile>& files) const = 0; | ||
|
|
||
| /// \brief Creates a writer for the manifest list. | ||
| /// \param manifest_list_location Path to the manifest list file. | ||
| /// \param file_io File IO implementation to use. | ||
| /// \return A Result containing the writer or an error. | ||
| static Result<std::unique_ptr<ManifestListWriter>> MakeWriter( | ||
| std::string_view manifest_list_location, std::shared_ptr<FileIO> file_io); | ||
| }; | ||
|
|
||
| } // namespace iceberg |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.