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

parquet writer: Raise an error when the row_group_index overflows i16 #6378

Merged
merged 1 commit into from
Sep 13, 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
17 changes: 14 additions & 3 deletions parquet/src/file/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,25 @@ impl<W: Write + Send> SerializedFileWriter<W> {
/// Creates new row group from this file writer.
/// In case of IO error or Thrift error, returns `Err`.
///
/// There is no limit on a number of row groups in a file; however, row groups have
/// There can be at most 2^15 row groups in a file; and row groups have
/// to be written sequentially. Every time the next row group is requested, the
/// previous row group must be finalised and closed using `RowGroupWriter::close` method.
pub fn next_row_group(&mut self) -> Result<SerializedRowGroupWriter<'_, W>> {
self.assert_previous_writer_closed()?;
let ordinal = self.row_group_index;

self.row_group_index += 1;
let ordinal: i16 = ordinal.try_into().map_err(|_| {
ParquetError::General(format!(
"Parquet does not support more than {} row groups per file (currently: {})",
i16::MAX,
ordinal
))
})?;

self.row_group_index = self
.row_group_index
.checked_add(1)
.expect("SerializedFileWriter::row_group_index overflowed");

let bloom_filter_position = self.properties().bloom_filter_position();
let row_groups = &mut self.row_groups;
Expand Down Expand Up @@ -227,7 +238,7 @@ impl<W: Write + Send> SerializedFileWriter<W> {
self.descr.clone(),
self.props.clone(),
&mut self.buf,
ordinal as i16,
ordinal,
Some(Box::new(on_close)),
);
Ok(row_group_writer)
Expand Down
Loading