wgtmac commented on PR #176:
URL: https://github.com/apache/iceberg-cpp/pull/176#issuecomment-3201178924

   What about this? `ManifestListWriter` does not need to be an abstract class. 
Only `ManifestFileAdapter` should have subclasses from v1 ~ v4 to deal with 
different schemas and value-filling logics. @dongxiao1198 @HeartLinked 
   
   ```cpp
   // Implemented by different versions with different schemas to
   // append a list of `ManifestFile`s to an `ArrowArray`.
   class ManifestFileAdapter {
    public:
     virtual Status StartAppending() const = 0;
     virtual Status Append(const ManifestFile& file) const = 0;
     virtual Result<ArrowArray> FinishAppending() const = 0;
     int64_t size() const { return size_; }
   
    private:
     std::shared_ptr<Schema> manifest_list_schema_;
     ArrowSchema schema_;  // converted from manifest_list_schema_
     ArrowArray array_;    // array to append `ManifestFile`s
     int64_t size_;
   };
   
   class ICEBERG_EXPORT ManifestListWriter {
    public:
     static Result<std::unique_ptr<ManifestListWriter>> Make(
         std::string_view manifest_list_location, std::shared_ptr<FileIO> 
file_io,
         const std::unordered_map<std::string, std::string>& meta);
   
     Status AddAll(const std::vector<ManifestFile>& files) const {
       for (const auto& file : files) {
         Add(file);
       }
       return {};
     }
   
     Status Add(const ManifestFile& file) const {
       if (adapter_->size() >= kBatchSize) {
         ICEBERG_ASSIGN_OR_RAISE(auto array, adapter_->FinishAppending());
         ICEBERG_RETURN_UNEXPECTED(writer_->Write(array));
         ICEBERG_RETURN_UNEXPECTED(adapter_->StartAppending());
       }
       return adapter_->Append(file);
     }
   
     Status Close() const;
   
    private:
     static constexpr int64_t kBatchSize = 1024;
     std::unique_ptr<Writer> writer_;
     std::unique_ptr<ManifestFileAdapter> adapter_;
   };
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to