GitHub user ryux1 closed the discussion with a comment: How to get Parquet's 
SchemaDescriptor when using parquet ArrowWriter?

`ArrowWriter::finish()` (or `close()`) returns `ParquetMetaData`, so you can 
get the descriptor from its file metadata directly. You do not need to 
reconstruct it from the Thrift `schema` field.

```rust
let metadata = writer.finish()?;
let schema = metadata.file_metadata().schema_descr();

for row_group in metadata.row_groups() {
    for (i, column) in row_group.columns().iter().enumerate() {
        let descriptor = schema.column(i);

        if let Some(statistics) = column.statistics() {
            println!("{}: {statistics:?}", descriptor.path());
            // Match on `statistics` here if you need typed min/max values.
        }
    }
}
```

The column index here is the Parquet physical leaf-column index, which is why 
iterating `row_group.columns()` and looking up `schema.column(i)` is preferable 
to indexing by top-level Arrow fields.

If you need metadata before finishing, `writer.flushed_row_groups()` exposes 
only row groups that have already been flushed; each `RowGroupMetaData` also 
has `schema_descr()`. For complete file metadata, use the value returned by 
`finish()`/`close()`.

I checked this against Arrow Rust 57.0.0 (the release current when this 
question was opened) with a small compiling writer example. Disclosure: I used 
OpenAI Codex to help inspect the relevant APIs and validate the example.


GitHub link: 
https://github.com/apache/arrow-rs/discussions/8705#discussioncomment-18340597

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]

Reply via email to