Skip to content

Commit

Permalink
Write Page Offset Index For All-Nan Pages (#4567)
Browse files Browse the repository at this point in the history
* fix offset index none

* add test

* add test

* Cleanup

---------

Co-authored-by: guojie.lgj <guojie.lgj@antfin.com>
Co-authored-by: Raphael Taylor-Davies <r.taylordavies@googlemail.com>
  • Loading branch information
3 people authored Jul 28, 2023
1 parent fba19b0 commit 8c85d34
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
21 changes: 21 additions & 0 deletions parquet/src/arrow/arrow_writer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,27 @@ mod tests {
writer.close().unwrap();
}

#[test]
fn check_page_offset_index_with_nan() {
let values = Arc::new(Float64Array::from(vec![f64::NAN; 10]));
let schema = Schema::new(vec![Field::new("col", DataType::Float64, true)]);
let batch = RecordBatch::try_new(Arc::new(schema), vec![values]).unwrap();

let mut out = Vec::with_capacity(1024);
let mut writer = ArrowWriter::try_new(&mut out, batch.schema(), None)
.expect("Unable to write file");
writer.write(&batch).unwrap();
let file_meta_data = writer.close().unwrap();
for row_group in file_meta_data.row_groups {
for column in row_group.columns {
assert!(column.offset_index_offset.is_some());
assert!(column.offset_index_length.is_some());
assert!(column.column_index_offset.is_none());
assert!(column.column_index_length.is_none());
}
}
}

#[test]
fn i8_single_column() {
required_and_optional::<Int8Array, _>(0..SMALL_SIZE as i8);
Expand Down
13 changes: 5 additions & 8 deletions parquet/src/column/writer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,14 +500,11 @@ impl<'a, E: ColumnValueEncoder> GenericColumnWriter<'a, E> {
let metadata = self.write_column_metadata()?;
self.page_writer.close()?;

let (column_index, offset_index) = if self.column_index_builder.valid() {
// build the column and offset index
let column_index = self.column_index_builder.build_to_thrift();
let offset_index = self.offset_index_builder.build_to_thrift();
(Some(column_index), Some(offset_index))
} else {
(None, None)
};
let column_index = self
.column_index_builder
.valid()
.then(|| self.column_index_builder.build_to_thrift());
let offset_index = Some(self.offset_index_builder.build_to_thrift());

Ok(ColumnCloseResult {
bytes_written: self.column_metrics.total_bytes_written,
Expand Down

0 comments on commit 8c85d34

Please sign in to comment.