liveBook · Manning

Parquet

As explained in Digital Twins in Action

Parquet is a column-oriented, open-source file format for efficient storage and retrieval of structured data.

Parquet is an open-source, column-oriented file format for structured data. It suits analytical work that filters, aggregates, or reads selected fields across many records. Unlike a database, a Parquet file can sit in a filesystem or object store and be queried directly by a compatible engine. section 4.3.2

Consider sensor readings with timestamps, temperature, humidity, and pressure. A column-oriented layout groups values by field rather than keeping every reading together. A query that needs only temperature can avoid reading the other columns. Compression reduces file size, while schema and metadata in the file footer preserve data types. section 4.3.2 section 8.1.4

Query a file without loading it into a database

DuckDB can run SQL against a local Parquet file: SELECT COUNT(*) AS trips, ROUND(AVG(fare_amount), 2) AS avg_fare FROM 'taxi.parquet'. The query counts taxi trips and calculates their average fare directly from the file. section 4.3.2

Listing 4.4 Using DuckDB and SQL to query data directly from a Parquet file
import duckdb, requests, time

url = "https://d37ci6vzurychx.cloudfront.net/trip-data/yellow_tripdata_
2024-01.parquet"
with open('taxi.parquet', 'wb') as f:  #1
  f.write(requests.get(url).content)

start_time = time.time()
result = duckdb.query("""  #2
  SELECT
      COUNT(*) as trips,
      ROUND(AVG(fare_amount), 2) as avg_fare,
      ROUND(MIN(fare_amount), 2) as min_fare,
      ROUND(MAX(fare_amount), 2) as max_fare
  FROM 'taxi.parquet'
""").fetchone()
query_time = time.time() - start_time

print(f"\nResults: {result[0]:,} trips, avg ${result[1]},
range ${result[2]}-${result[3]}")

The full listing downloads the taxi file, queries its trip count and fare statistics with DuckDB, and times the query. section 4.3.2

Parquet also serves as an output for analytical pipelines: data from multiple sources can be aligned, resampled, cleaned, and stored as features for machine learning. It is not, by itself, a transactional table format. Individual files are immutable; changing a record or adding a column requires writing a new file. Delta Lake adds a transaction log and metadata layer over Parquet for record-level changes. section 8.1 section 4.3.5

How Digital Twins in Action covers it

How deep it goes
Explains selective column reads, compression, schema metadata, and immutable-file limits without detailing encoding internals.
Examples
Uses a DuckDB query over taxi trips and a sensor-data pipeline that produces resampled Parquet features.
What it assumes
Assumes Python and SQL familiarity for the runnable query while illustrating columnar organization with sensor readings.
What you can do after
Apply it via DuckDB to query a Parquet file directly and use Parquet to store prepared machine-learning features.
How it connects
Connects columnar storage and data lakes to Delta Lake transactions and machine-learning feature stores.

Also explained in

Compare how 9 books explain Parquet →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Digital Twins in Action. The section links point to the parts of the book it draws on.