liveBook · Manning

Logical type

As explained in DuckDB in Action

A logical type is semantic type information attached to a physical storage representation to specify how readers should interpret values.

A logical type adds semantic meaning to a physical storage type, telling readers how to interpret the stored value. Parquet stores dates physically as numeric values while metadata identifies them as dates. This preserves compact storage while enabling date-aware operations. section 5.4 section 5.5

Use logical types when converting loosely typed source data into a self-describing Parquet schema:

  • Inspect CSV values before export because CSV columns are typically strings or require sampling to infer types. section 5.4
  • Convert encoded values such as 20000110 into a proper DATE rather than leaving them as sortable but awkward integers. section 5.4
  • Inspect Parquet metadata to distinguish the physical type on disk from its logical interpretation. section 5.5

Converting an encoded ranking date

SELECT * REPLACE (cast(strptime(ranking_date::VARCHAR, '%Y%m%d') AS DATE) AS ranking_date) FROM 'atp/atp_rankings_*.csv' LIMIT 5; The resulting column is typed as DATE and displays values such as 2000-01-10, allowing SQL date manipulation functions to use it.

How DuckDB in Action covers it

How deep it goes
Explains annotations, demonstrates date conversion, and inspects Parquet metadata without developing logical-type internals beyond schemas.
Examples
Demonstrates encoded ranking dates, DuckDB strptime conversion, DATE output, and parquet_schema inspection.
What it assumes
Assumes basic CSV and SQL querying, while demonstrating type conversion and schema interpretation explicitly.
What you can do after
Apply logical types with DuckDB by parsing encoded dates and verifying their Parquet schema metadata.
How it connects
Connects logical types to Parquet, physical data types, schemas, CSV inference, metadata, and date parsing.

Also explained in

Compare how 2 books explain logical type →

Related concepts

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