Repository navigation
feat: add parquet_file_metadata and parquet_page_index to datafusion-cli #25640
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
Merged
kumarUjjawal
merged 1 commit into
apache:main
from
o11y-one:feat/cli-parquet-file-metadata-page-index
Oct 5, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,8 @@ use datafusion::logical_expr::ExplainFormat; | |
| use datafusion::prelude::SessionContext; | ||
| use datafusion_cli::catalog::DynamicObjectStoreCatalog; | ||
| use datafusion_cli::functions::{ | ||
| ListFilesCacheFunc, MetadataCacheFunc, ParquetMetadataFunc, StatisticsCacheFunc, | ||
| ListFilesCacheFunc, MetadataCacheFunc, ParquetFileMetadataFunc, ParquetMetadataFunc, | ||
| ParquetPageIndexFunc, StatisticsCacheFunc, | ||
| }; | ||
| use datafusion_cli::object_storage::instrumented::{ | ||
| InstrumentedObjectStoreMode, InstrumentedObjectStoreRegistry, | ||
|
|
@@ -271,6 +272,15 @@ async fn main_inner() -> Result<()> { | |
| // register `parquet_metadata` table function to get metadata from parquet files | ||
| ctx.register_udtf("parquet_metadata", Arc::new(ParquetMetadataFunc {})); | ||
|
|
||
| // register `parquet_file_metadata` table function to get file level metadata from parquet files | ||
| ctx.register_udtf( | ||
| "parquet_file_metadata", | ||
| Arc::new(ParquetFileMetadataFunc {}), | ||
| ); | ||
|
|
||
| // register `parquet_page_index` table function to get the page index of parquet files | ||
| ctx.register_udtf("parquet_page_index", Arc::new(ParquetPageIndexFunc {})); | ||
|
|
||
| // register `metadata_cache` table function to get the contents of the file metadata cache | ||
| ctx.register_udtf( | ||
| "metadata_cache", | ||
|
|
@@ -609,6 +619,72 @@ mod tests { | |
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_parquet_file_metadata_works() -> Result<(), DataFusionError> { | ||
| let ctx = SessionContext::new(); | ||
| ctx.register_udtf( | ||
| "parquet_file_metadata", | ||
| Arc::new(ParquetFileMetadataFunc {}), | ||
| ); | ||
|
|
||
| let sql = "SELECT * FROM parquet_file_metadata('../parquet-testing/data/int32_with_null_pages.parquet')"; | ||
| let df = ctx.sql(sql).await?; | ||
| let rbs = df.collect().await?; | ||
|
|
||
| assert_snapshot!(batches_to_string(&rbs), @r" | ||
| +-------------------------------------------------------+-------------------------------------------------------------------------------------+---------+----------+----------------+------------------------------+---------------+ | ||
| | filename | created_by | version | num_rows | num_row_groups | key_value_metadata | footer_length | | ||
| +-------------------------------------------------------+-------------------------------------------------------------------------------------+---------+----------+----------------+------------------------------+---------------+ | ||
| | ../parquet-testing/data/int32_with_null_pages.parquet | parquet-mr version 1.13.0-SNAPSHOT (build 433de8df33fcf31927f7b51456be9f53e64d48b9) | 1 | 1000 | 1 | {writer.model.name: example} | 273 | | ||
| +-------------------------------------------------------+-------------------------------------------------------------------------------------+---------+----------+----------------+------------------------------+---------------+ | ||
| "); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_parquet_page_index_works() -> Result<(), DataFusionError> { | ||
| let ctx = SessionContext::new(); | ||
| ctx.register_udtf("parquet_page_index", Arc::new(ParquetPageIndexFunc {})); | ||
|
|
||
| // page 2 only holds nulls, so it has no min or max | ||
| let sql = "SELECT * FROM parquet_page_index('../parquet-testing/data/int32_with_null_pages.parquet')"; | ||
| let df = ctx.sql(sql).await?; | ||
| let rbs = df.collect().await?; | ||
|
|
||
| assert_snapshot!(batches_to_string(&rbs), @r" | ||
| +-------------------------------------------------------+--------------+-----------+--------------+-----------------+--------+----------------------+-------------+------------+------------+ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is very cool -- thank you |
||
| | filename | row_group_id | column_id | page_ordinal | first_row_index | offset | compressed_page_size | min_value | max_value | null_count | | ||
| +-------------------------------------------------------+--------------+-----------+--------------+-----------------+--------+----------------------+-------------+------------+------------+ | ||
| | ../parquet-testing/data/int32_with_null_pages.parquet | 0 | 0 | 0 | 0 | 4 | 415 | -2135807632 | 2144701119 | 8 | | ||
| | ../parquet-testing/data/int32_with_null_pages.parquet | 0 | 0 | 1 | 100 | 419 | 220 | -2104090659 | 1745329571 | 55 | | ||
| | ../parquet-testing/data/int32_with_null_pages.parquet | 0 | 0 | 2 | 200 | 639 | 31 | | | 100 | | ||
| | ../parquet-testing/data/int32_with_null_pages.parquet | 0 | 0 | 3 | 300 | 670 | 228 | -2116849709 | 2077105757 | 52 | | ||
| | ../parquet-testing/data/int32_with_null_pages.parquet | 0 | 0 | 4 | 400 | 898 | 382 | -2048691758 | 2143189382 | 16 | | ||
| | ../parquet-testing/data/int32_with_null_pages.parquet | 0 | 0 | 5 | 500 | 1280 | 402 | -2017923401 | 2087827129 | 12 | | ||
| | ../parquet-testing/data/int32_with_null_pages.parquet | 0 | 0 | 6 | 600 | 1682 | 422 | -2136906554 | 2125689411 | 5 | | ||
| | ../parquet-testing/data/int32_with_null_pages.parquet | 0 | 0 | 7 | 700 | 2104 | 411 | -2113313110 | 2145722375 | 7 | | ||
| | ../parquet-testing/data/int32_with_null_pages.parquet | 0 | 0 | 8 | 800 | 2515 | 417 | -2046900272 | 2087168549 | 8 | | ||
| | ../parquet-testing/data/int32_with_null_pages.parquet | 0 | 0 | 9 | 900 | 2932 | 400 | -1941944785 | 2078586537 | 12 | | ||
| +-------------------------------------------------------+--------------+-----------+--------------+-----------------+--------+----------------------+-------------+------------+------------+ | ||
| "); | ||
|
|
||
| // min and max of UTF8 columns are shown as strings | ||
| let sql = "SELECT * FROM parquet_page_index('../parquet-testing/data/data_index_bloom_encoding_stats.parquet')"; | ||
| let df = ctx.sql(sql).await?; | ||
| let rbs = df.collect().await?; | ||
|
|
||
| assert_snapshot!(batches_to_string(&rbs), @r" | ||
| +-----------------------------------------------------------------+--------------+-----------+--------------+-----------------+--------+----------------------+-----------+-----------+------------+ | ||
| | filename | row_group_id | column_id | page_ordinal | first_row_index | offset | compressed_page_size | min_value | max_value | null_count | | ||
| +-----------------------------------------------------------------+--------------+-----------+--------------+-----------------+--------+----------------------+-----------+-----------+------------+ | ||
| | ../parquet-testing/data/data_index_bloom_encoding_stats.parquet | 0 | 0 | 0 | 0 | 4 | 152 | Hello | today | 0 | | ||
| +-----------------------------------------------------------------+--------------+-----------+--------------+-----------------+--------+----------------------+-----------+-----------+------------+ | ||
| "); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_metadata_cache() -> Result<(), DataFusionError> { | ||
| let ctx = SessionContext::new(); | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a follow on, we could also potentially use this:
https://docs.rs/parquet/latest/parquet/arrow/arrow_reader/statistics/struct.StatisticsConverter.html#method.row_group_mins
To convert the min/max values and then call the arrow cast kernel to turn them into strings
There is similar code for data page mins here:
https://docs.rs/parquet/latest/parquet/arrow/arrow_reader/statistics/struct.StatisticsConverter.html#method.data_page_mins
That would handle things like min/max dates better (I think this is just going to show the raw values rather than formatted as a date)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alamb thanks for sharing this, should I include it here? or in a follow-up PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a follow up would be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, will do, and thanks for being pro-active :)