Skip to main content

parse parquet metadata including page headers

Project description

Parquet-Pages

reads a parquet files' metadata information, including each individual data-page headers. Exposes them directly as thrift structs deserialised in accordance with apache's parquet.thrift. That file has extensive comments describing the precise meaning of each field (and the lack thereof, if it is deprecated) These structs include:

  • FileMetaData
    • RowGroup (s)
      • ColumnChunk (s)
        • ColumnMetaData
        • OffsetIndex (if present)
        • ColumnIndex (if present)
        • PageHeader (s)

(.. etc)

The intended way is to invoke this package as a module to get an interactive TUI that displays this information with collapsible sections. But, one may also instead read it into a FileMetaData object inside a script (see details below), in which case the above thrift-generated classes are also exposed via:

from parquet_pages import ttypes
ttypes.FileMetaData
ttypes.ColumnMetaData # etc

NOTE

From a thrift spec perspective, OffsetIndex and ColumnIndex (when present) are not actually a part of ColumnChunk, but are located separately before the rest of the metadata footer. PageHeader is not in the footer at all (more details below). But they are presented in the above hierarchy for ease.

Usage Examples

% python -m parquet_pages -h                                    
usage: python -m parquet_pages [-h] -f FILEPATHS [FILEPATHS ...] [--expand] [--eager] [--show-None] [--raw] [--template TEMPLATE]

reads given parquet's FileMetaData and displays it in an interactive TUI with collapsible sections

options:
  -h, --help            show this help message and exit
  -f, --filepaths FILEPATHS [FILEPATHS ...]
                        Path(s)/glob-pattern(s) to parquet file(s)
  --expand              [TUI only] expand all collapsible sections at start
  --eager               eagerly load all page headers at start. default is to lazy load on click (or to not load at all incase of --raw)
  --show-None           show `None` attributes as well
  --raw                 disable TUI and dump formatted repr directly to stdout
  --template TEMPLATE   jinja2 template to filter metadata info
  • optionally, can also instead dump repr(metadata) to stdout without any TUI, with readable indentation (--raw)
  • by default, we lazy-load the PageHeaders (only read them from the file when requested).
    • this can be changed with the --eager flag
    • This is lazy-loaded because all the other thrift-serialised-structs (except PageHeaders) are together in the file's footer, but the page-headers (which are before every page's payload) would be scattered all over the file. Eagerly loading them all might end up doing significant I/O if the parquet file is large enough.
      • but since we are only reading the headers and not the payload as well, it wouldn't be more work than reading the entire file contents, for perspective. In most cases eager loading shouldn't feel any slower at all.

TUI Example

  • example jinja2 templates:
    • --template "metadata.row_groups | map(attribute='total_compressed_size') | list"
      • size of each row-group in the file
    • --template "metadata.row_groups | map(attribute='columns') | sum(start=[]) | map(attribute='page_headers') | sum(start=[]) | map(attribute='compressed_page_size') | list"
      • size of each data/dict/index pages in the file
    • --template "metadata.row_groups | map(attribute='columns') | map('map', attribute='page_headers') | map('map', 'map', attribute='compressed_page_size') | map('map', 'list') | map('list') | list"
      • same as last but without flattening hierarchy of row-groups, columns

To read in a script:

from parquet_pages import read_parquet_metadata

metadata = read_parquet_metadata("example.parquet")

with open("example2.parquet", "rb") as file:
    file_contents = file.read()

metadata2 = read_parquet_metadata(file_contents)
  • This eagerly-loads PageHeaders by default, for simplicity.
  • To load them lazily like what happens in the TUI, we can pass the argument lazy_load_pg_hdrs=True
    • the argument is ignored when reading from a bytes object, as it only would have made a difference when reading from a file on disk.
    • it replaces PageHeader objects with parquet_bytes.LazyLoaded objects, calling whose .load() method will actually read and return the struct.

Requirements

Runtime

  • Requires thrift
  • Only optionally requires, but recommended: textual
    • not optional during install, so would be installed automatically, but someone might uninstall it and core functionality will still work
      • parquet_pages.read_parquet_metadata does not require it
      • python -m parquet_pages --raw ... does not require it
    • only to manage TUI display after metadata is read

Build-time

  • Requires thrift-compiler
    • but does NOT require this if installing from pypi
    • see Dockerfile, Makefile (make publish)

License

This project is licensed under the MIT License. See the LICENSE file for details.

Third-Party Code

This project includes the file parquet.thrift from Apache Parquet Format, developed by the Apache Software Foundation.

That file is licensed under the Apache License, Version 2.0. See LICENSE-APACHE and NOTICE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

parquet_pages-0.6.0.tar.gz (53.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

parquet_pages-0.6.0-py3-none-any.whl (53.3 kB view details)

Uploaded Python 3

File details

Details for the file parquet_pages-0.6.0.tar.gz.

File metadata

  • Download URL: parquet_pages-0.6.0.tar.gz
  • Upload date:
  • Size: 53.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for parquet_pages-0.6.0.tar.gz
Algorithm Hash digest
SHA256 db5881e2cecae3e7d87986d97b307ed89356be8ff90167f3081ae3e9a899bcc2
MD5 e99f77f3515e9e19f2efdc78e4eeb1ee
BLAKE2b-256 bdd6601814a40f84afa5254ec79aeb6ad472567873ff773625b1b47aca2ad399

See more details on using hashes here.

File details

Details for the file parquet_pages-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: parquet_pages-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 53.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for parquet_pages-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06d9091a584ddef0d5091f39fa0a8637bdfd68692a0cba4179802841a7ebc110
MD5 9f2bb6c6e0eb3ce7d3e3eb3002972375
BLAKE2b-256 78126b384dc4cc8fdf607c07edb6a385bf9f776c06b9d506085f189193670074

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page