Skip to content
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

Add finish to AsyncArrowWriter::finish #6543

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion parquet/src/arrow/async_writer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ impl<W: AsyncFileWriter> AsyncArrowWriter<W> {
/// Close and finalize the writer.
///
/// All the data in the inner buffer will be force flushed.
pub async fn close(mut self) -> Result<FileMetaData> {
///
/// Unlike [`Self::close`] this does not consume self
///
/// Attempting to write after calling finish will result in an error
pub async fn finish(&mut self) -> Result<FileMetaData> {
let metadata = self.sync_writer.finish()?;

// Force to flush the remaining data.
Expand All @@ -249,6 +253,13 @@ impl<W: AsyncFileWriter> AsyncArrowWriter<W> {
Ok(metadata)
}

/// Close and finalize the writer.
///
/// All the data in the inner buffer will be force flushed.
pub async fn close(mut self) -> Result<FileMetaData> {
self.finish().await
}

/// Flush the data written by `sync_writer` into the `async_writer`
///
/// # Notes
Expand Down Expand Up @@ -385,6 +396,28 @@ mod tests {
}
}

#[tokio::test]
async fn test_async_writer_bytes_written() {
let col = Arc::new(Int64Array::from_iter_values([1, 2, 3])) as ArrayRef;
let to_write = RecordBatch::try_from_iter([("col", col)]).unwrap();

let temp = tempfile::tempfile().unwrap();

let file = tokio::fs::File::from_std(temp.try_clone().unwrap());
let mut writer =
AsyncArrowWriter::try_new(file.try_clone().await.unwrap(), to_write.schema(), None)
.unwrap();
writer.write(&to_write).await.unwrap();
let _metadata = writer.finish().await.unwrap();
// After `finish` this should include the metadata and footer
let reported = writer.bytes_written();

// Get actual size from file metadata
let actual = file.metadata().await.unwrap().len() as usize;

assert_eq!(reported, actual);
}

#[tokio::test]
async fn test_async_writer_file() {
let col = Arc::new(Int64Array::from_iter_values([1, 2, 3])) as ArrayRef;
Expand Down
Loading