Skip to content
Merged
Show file tree
Hide file tree
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
45 changes: 45 additions & 0 deletions parquet/src/arrow/arrow_writer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,7 @@ mod tests {

use crate::arrow::arrow_reader::{ParquetRecordBatchReader, ParquetRecordBatchReaderBuilder};
use crate::arrow::ARROW_SCHEMA_META_KEY;
use crate::file::page_encoding_stats::PageEncodingStats;
use crate::format::PageHeader;
use crate::thrift::TCompactSliceInputProtocol;
use arrow::datatypes::ToByteSlice;
Expand Down Expand Up @@ -3835,4 +3836,48 @@ mod tests {
assert_eq!(stats.max_value.unwrap(), "Bm".as_bytes());
assert_eq!(stats.min_value.unwrap(), "Bl".as_bytes());
}

#[test]
fn test_page_encoding_statistics_roundtrip() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now when I run this test without the code change it fails like this (as expected)


assertion failed: chunk_meta.encoding_stats.is_some()
thread 'arrow::arrow_writer::tests::test_page_encoding_statistics_roundtrip' panicked at parquet/src/arrow/arrow_writer/mod.rs:3865:9:
assertion failed: chunk_meta.encoding_stats.is_some()
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/panicking.rs:697:5
   1: core::panicking::panic_fmt
             at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/panicking.rs:75:14
   2: core::panicking::panic
             at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/panicking.rs:145:5
   3: parquet::arrow::arrow_writer::tests::test_page_encoding_statistics_roundtrip
             at ./src/arrow/arrow_writer/mod.rs:3865:9
   4: parquet::arrow::arrow_writer::tests::test_page_encoding_statistics_roundtrip::{{closure}}
             at ./src/arrow/arrow_writer/mod.rs:3841:49
   5: core::ops::function::FnOnce::call_once
             at /Users/andrewlamb/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
   6: core::ops::function::FnOnce::call_once
             at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

👍

let batch_schema = Schema::new(vec![Field::new(
"int32",
arrow_schema::DataType::Int32,
false,
)]);

let batch = RecordBatch::try_new(
Arc::new(batch_schema.clone()),
vec![Arc::new(Int32Array::from(vec![1, 2, 3, 4])) as _],
)
.unwrap();

let mut file: File = tempfile::tempfile().unwrap();
let mut writer = ArrowWriter::try_new(&mut file, Arc::new(batch_schema), None).unwrap();
writer.write(&batch).unwrap();
let file_metadata = writer.close().unwrap();

assert_eq!(file_metadata.row_groups.len(), 1);
assert_eq!(file_metadata.row_groups[0].columns.len(), 1);
let chunk_meta = file_metadata.row_groups[0].columns[0]
.meta_data
.as_ref()
.expect("column metadata missing");
assert!(chunk_meta.encoding_stats.is_some());
let chunk_page_stats = chunk_meta.encoding_stats.as_ref().unwrap();

// check that the read metadata is also correct
let options = ReadOptionsBuilder::new().with_page_index().build();
let reader = SerializedFileReader::new_with_options(file, options).unwrap();

let rowgroup = reader.get_row_group(0).expect("row group missing");
assert_eq!(rowgroup.num_columns(), 1);
let column = rowgroup.metadata().column(0);
assert!(column.page_encoding_stats().is_some());
let file_page_stats = column.page_encoding_stats().unwrap();
let chunk_stats: Vec<PageEncodingStats> = chunk_page_stats
.iter()
.map(|x| crate::file::page_encoding_stats::try_from_thrift(x).unwrap())
.collect();
assert_eq!(&chunk_stats, file_page_stats);
}
}
2 changes: 1 addition & 1 deletion parquet/src/arrow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ mod test {
.unwrap();
assert_eq!(
err.to_string(),
"EOF: Parquet file too small. Page index range 82..115 overlaps with file metadata 0..341"
"EOF: Parquet file too small. Page index range 82..115 overlaps with file metadata 0..357"
);
}

Expand Down
3 changes: 3 additions & 0 deletions parquet/src/file/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,9 @@ impl<'a, W: Write + Send> SerializedRowGroupWriter<'a, W> {
if let Some(statistics) = metadata.statistics() {
builder = builder.set_statistics(statistics.clone())
}
if let Some(page_encoding_stats) = metadata.page_encoding_stats() {
builder = builder.set_page_encoding_stats(page_encoding_stats.clone())
}
builder = self.set_column_crypto_metadata(builder, &metadata);
close.metadata = builder.build()?;

Expand Down
Loading