Copilot commented on code in PR #959:
URL: https://github.com/apache/iceberg-rust/pull/959#discussion_r2021056114


##########
crates/iceberg/src/puffin/writer.rs:
##########
@@ -0,0 +1,394 @@
+// 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.
+
+use std::collections::{HashMap, HashSet};
+
+use bytes::Bytes;
+use futures::lock::Mutex;
+
+use crate::io::{FileWrite, OutputFile};
+use crate::puffin::blob::Blob;
+use crate::puffin::compression::CompressionCodec;
+use crate::puffin::metadata::{BlobMetadata, FileMetadata, Flag};
+use crate::Result;
+
+struct WriterState {
+    writer: Box<dyn FileWrite>,
+    is_header_written: bool,
+    num_bytes_written: u64,
+}
+
+/// Puffin writer
+pub(crate) struct PuffinWriter {
+    writer_state: Mutex<WriterState>,
+    written_blobs_metadata: Vec<BlobMetadata>,
+    properties: HashMap<String, String>,
+    footer_compression_codec: CompressionCodec,
+    flags: HashSet<Flag>,
+}
+
+impl PuffinWriter {
+    /// Returns a new Puffin writer
+    pub(crate) async fn new(
+        output_file: &OutputFile,
+        properties: HashMap<String, String>,
+        compress_footer: bool,
+    ) -> Result<Self> {
+        let mut flags = HashSet::<Flag>::new();
+        let footer_compression_codec = if compress_footer {
+            flags.insert(Flag::FooterPayloadCompressed);
+            CompressionCodec::Lz4
+        } else {
+            CompressionCodec::None
+        };
+
+        let initial_state = WriterState {
+            writer: output_file.writer().await?,
+            is_header_written: false,
+            num_bytes_written: 0,
+        };
+
+        Ok(Self {
+            writer_state: Mutex::new(initial_state),
+            written_blobs_metadata: Vec::new(),
+            properties,
+            footer_compression_codec,
+            flags,
+        })
+    }
+
+    /// Adds blob to Puffin file
+    pub(crate) async fn add(

Review Comment:
   The add method does not explicitly check whether the writer has been closed 
before proceeding, relying instead on subsequent io errors. Consider adding a 
dedicated closed state check to return a clear and specific error if add is 
called after close.



-- 
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