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

expose row-group flush in public api #1634

Merged
merged 3 commits into from
May 2, 2022
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
13 changes: 8 additions & 5 deletions parquet/src/arrow/arrow_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ impl<W: 'static + ParquetWriter> ArrowWriter<W> {
}

self.buffered_rows += batch.num_rows();

self.flush_completed()?;

Ok(())
Expand All @@ -122,13 +121,18 @@ impl<W: 'static + ParquetWriter> ArrowWriter<W> {
/// Flushes buffered data until there are less than `max_row_group_size` rows buffered
fn flush_completed(&mut self) -> Result<()> {
while self.buffered_rows >= self.max_row_group_size {
self.flush_row_group(self.max_row_group_size)?;
self.flush_rows(self.max_row_group_size)?;
}
Ok(())
}

/// Flushes all buffered rows into a new row group
pub fn flush(&mut self) -> Result<()> {
self.flush_rows(self.buffered_rows)
}

/// Flushes `num_rows` from the buffer into a new row group
fn flush_row_group(&mut self, num_rows: usize) -> Result<()> {
fn flush_rows(&mut self, num_rows: usize) -> Result<()> {
if num_rows == 0 {
return Ok(());
}
Expand Down Expand Up @@ -192,8 +196,7 @@ impl<W: 'static + ParquetWriter> ArrowWriter<W> {

/// Close and finalize the underlying Parquet writer
pub fn close(&mut self) -> Result<parquet_format::FileMetaData> {
self.flush_completed()?;
self.flush_row_group(self.buffered_rows)?;
self.flush()?;
self.writer.close()
}
}
Expand Down