ADR-003 placed the three zones of DataCorp's platform on object storage. That has a consequence that is easy to overlook: there are no tables there, only files. What the model calls fact_sales or "clickstream events" is, physically, a set of objects with an internal format and a name. On those two decisions, which format the data is written in and how the files are distributed across paths, depends whether a query reads 2 GB or 20 MB.

This lesson closes the module by going down to that physical level. We will compare the usual file formats (CSV, JSON, Avro, Parquet and ORC), look at the role of compression, measure with Python the difference between a CSV and a Parquet file, and study partitioning: the technique of organizing files into folders so that the engine can discard, without opening them, the ones it does not need. We will finish with the path convention for DataCorp's three zones and with ADR-004, which puts the decisions in writing.

What we ask of a file format

A file format is the agreement on how data is laid out inside the file. Formats differ in six properties:

Property Question
Organization Does it store the data by rows or by columns? (lesson 02-01)
Schema Does the file include the names and types of the columns, or do you have to know them some other way?
Data types Does it tell a number from text, a date from a string?
Compression How much space does it take up and how much does it cost to compress and decompress?
Splittability Can several processes read different pieces of the same file at the same time?
Schema evolution What happens to the old files when a column is added?

To these we add a practical question: whether the file is human-readable and readable by any tool, or whether it requires a specific library.

Text formats: CSV and JSON

CSV

A CSV (comma-separated values) file is plain text with one row per line and the values separated by a delimiter:

order_id,customer_id,order_date,status,total_amount
8801,1042,2026-10-03 18:45:00,delivered,258.90
8802,2210,2026-10-05 10:02:00,delivered,59.00
  • Pros: it is universal. Any tool can open it, including a spreadsheet, and it can be understood at a glance.
  • Cons: it has no schema and no types (is 8801 a number or text? is 03/10/2026 March or October?), there is no strict standard (delimiter, quoting, character encoding and line breaks inside a field vary from one system to another), it is bulky and it is row-oriented: to read one column you have to go through the entire file.

It is the format in which the ERP inventory and part of the marketing data arrive. DataCorp does not choose it: it receives it.

JSON and JSON Lines

JSON represents nested data as text. For large volumes its JSON Lines variant is used (extension .jsonl): one complete JSON object per line, with no brackets wrapping the whole set.

{"event_id":"e-7f3a91","type":"add_to_cart","event_time":"2026-10-03T18:39:55Z","customer_id":10472,"device":{"type":"mobile","os":"Android"},"product":{"product_id":3301,"quantity":1}}
{"event_id":"e-7f3a92","type":"search","event_time":"2026-10-03T18:40:02Z","customer_id":10472,"device":{"type":"mobile","os":"Android"},"search_text":"vacuum cleaner bags"}

The difference matters: a regular JSON file, with a list of a million events, has to be read in full before it can be interpreted. A JSON Lines file is processed line by line, and events can be appended to the end of it.

  • Pros: it supports nested structures and variable fields; each record describes itself.
  • Cons: it repeats the name of every field in every record (it is the bulkiest of all), it has few types (it does not distinguish dates or exact decimals) and it is also row-oriented.

It is the natural format for clickstream and for the marketing API.

Binary formats: Avro, Parquet and ORC

Binary formats cannot be read at a glance, but they include the schema, have precise types and are compressed internally.

Avro: row-oriented binary

Avro stores records one after another, like a CSV, but in binary and with the schema included in the file header, expressed in JSON. Field names are not repeated in every record.

  • Strength: it writes very fast, record by record, and has the best schema evolution rules. That is why it is widely used for exchanging messages between systems and in streaming processing (Module 4).
  • Limitation: being row-oriented, it does not offer the analytical advantages of columnar formats.

Parquet: columnar binary

Parquet is the most widespread columnar format in analytical platforms. Its internal structure explains its performance:

Parquet file
├── Row group 1  (e.g. 1 million rows)
│   ├── column order_id      [compressed values]    min=1        max=1000000
│   ├── column order_date    [compressed values]    min=2025-11  max=2026-08
│   ├── column status        [dictionary + codes]
│   └── column total_amount  [compressed values]    min=5.12     max=912.40
├── Row group 2
│   └── ...
└── File footer: schema (names and types) + statistics for each group
  • The file is divided into row groups and, within each one, the data is stored column by column.
  • The footer contains the schema and, for each column of each group, statistics such as the minimum and the maximum.
  • An engine that reads Parquet starts with the footer. With it, the engine decides which columns it needs (column projection) and which row groups it can skip because their statistics prove they do not contain what is being looked for (statistics-based filtering).

These are exactly the three advantages of columnar storage described in lesson 02-01, made concrete in a file.

  • Limitation: a Parquet file is written in one go; rows cannot be appended to it, nor can a single row be modified. To change a piece of data the file is rewritten. And writing it takes more compute than writing a CSV.

ORC

ORC is another columnar format, with a structure and performance comparable to Parquet's. It was born in the Hive ecosystem and is still common there. Outside that environment, Parquet has broader support among tools and providers, which is why it is the default choice when there is no reason to prefer ORC.

Compression and splittability

Compressing reduces space and, above all, the amount of data that travels over the network from object storage. In exchange, it consumes processor time. The three algorithms (codecs) you will come across most often:

Codec Reduction Speed Typical use
gzip High Slow, especially when compressing Text files (CSV, JSON) that are stored and seldom read
snappy Moderate Very fast Parquet's traditional default; data that is read constantly
zstd High, similar to or better than gzip Fast A good all-round balance; increasingly the recommended option

Splittability indicates whether a large file can be divided among several processes that read it in parallel:

  • An uncompressed CSV or JSON Lines file is splittable: reading can start at any line break.
  • The same file compressed as a whole with gzip is not: it has to be decompressed from the beginning, by a single process. A 50 GB .csv.gz is a bottleneck.
  • Avro, Parquet and ORC compress by internal blocks, not the whole file. They remain splittable with any codec.

For compressed text files, the solution is simple: many moderately sized files instead of one enormous one.

Schema evolution

Sources change (lesson 02-04), and the files written yesterday must be readable alongside tomorrow's.

Format What happens when a column is added What happens on renaming or reordering
CSV It depends on the reader: if it identifies columns by position, it may read the wrong data without raising an error High risk of misassigned data
JSON Old records do not have the field; the reader must allow for its absence A renamed field is, to all intents and purposes, a new field
Avro Supported with explicit rules: the new field declares a default value for the old files It supports aliases for names
Parquet and ORC Supported: in the old files the column is read as null Problematic: columns are identified by name

Adding optional columns is safe in formats that carry a schema. Renaming or changing types is still an incompatible change, just as in a database, and is handled with the same caution.

Comparison and usage criteria

Characteristic CSV JSON Lines Avro Parquet ORC
Organization Rows Rows Rows Columns Columns
Human-readable Yes Yes No No No
Schema included No Field names only Yes Yes Yes
Data types No Few Rich Rich Rich
Nested data No Yes Yes Yes Yes
Size Large Very large Medium Small Small
Splittable when compressed No (with gzip) No (with gzip) Yes Yes Yes
Reading a few columns Slow Slow Slow Fast Fast
Record-by-record writing Yes Yes Yes No No
Schema evolution Fragile Flexible, uncontrolled Very good Good Good
Situation Recommended format
Exchanging a small file with a person or with a legacy system CSV
Receiving events or API responses with a variable structure JSON Lines
Sending messages between systems or writing in streaming, record by record Avro
Storing data for analysis Parquet (or ORC in a Hive environment)
Keeping the faithful copy of what a source sent The original format, unconverted

The last row is a direct consequence of ADR-002: the raw zone stores what arrived, as it arrived. Converting at ingestion would mean interpreting the data, and any interpretation error would be beyond recovery.

From CSV to Parquet with Python

Let's check the differences with data. The first script generates a synthetic CSV with one year of DataCorp's orders (1,500 a day); it needs the pandas and pyarrow libraries.

# generate_orders.py - synthetic CSV with one year of orders (fictitious data)
import numpy as np
import pandas as pd

rng = np.random.default_rng(42)          # fixed seed: the result is reproducible
N = 1_500 * 365                          # 547,500 orders

statuses = ["pending", "paid", "shipped", "delivered", "cancelled", "returned"]
weights  = [0.02, 0.05, 0.08, 0.77, 0.05, 0.03]

start = pd.Timestamp("2025-11-01")
seconds = np.sort(rng.integers(0, 365 * 24 * 3600, size=N))   # sorted instants

orders = pd.DataFrame({
    "order_id":     np.arange(1, N + 1),
    "customer_id":  rng.integers(1, 200_001, size=N),
    "order_date":   start + pd.to_timedelta(seconds, unit="s"),
    "status":       rng.choice(statuses, size=N, p=weights),
    "total_amount": np.round(rng.gamma(shape=2.0, scale=40.0, size=N) + 5, 2),
})
orders.to_csv("orders.csv", index=False)
print(f"{len(orders):,} rows written to orders.csv")

The second one converts the CSV to Parquet and compares:

# convert_to_parquet.py
import os
import time

import pandas as pd

# 1) Read the CSV specifying the types: the CSV does not store them
orders = pd.read_csv(
    "orders.csv",
    dtype={"order_id": "int32", "customer_id": "int32", "status": "category"},
    parse_dates=["order_date"],
)

# 2) Write the same content to Parquet with three different compressions
for compression in ["snappy", "gzip", "zstd"]:
    orders.to_parquet(f"orders_{compression}.parquet", engine="pyarrow",
                      compression=compression, index=False)

# 3) Compare sizes on disk
def mb(path):
    return os.path.getsize(path) / 1_000_000

base = mb("orders.csv")
print(f"{'File':<26}{'MB':>8}{'% of CSV':>12}")
for path in ["orders.csv", "orders_snappy.parquet",
             "orders_gzip.parquet", "orders_zstd.parquet"]:
    print(f"{path:<26}{mb(path):>8.2f}{100 * mb(path) / base:>11.1f}%")

# 4) Selective read: only the two columns the query needs
t0 = time.perf_counter()
df_csv = pd.read_csv("orders.csv", usecols=["status", "total_amount"])
t_csv = time.perf_counter() - t0

t0 = time.perf_counter()
df_parquet = pd.read_parquet("orders_zstd.parquet", columns=["status", "total_amount"])
t_parquet = time.perf_counter() - t0

print(f"Reading 2 columns from CSV:     {t_csv * 1000:7.1f} ms")
print(f"Reading 2 columns from Parquet: {t_parquet * 1000:7.1f} ms")

Output of one run (the timings vary from one machine to another):

File                            MB    % of CSV
orders.csv                   26.89      100.0%
orders_snappy.parquet         9.95       37.0%
orders_gzip.parquet           6.78       25.2%
orders_zstd.parquet           8.18       30.4%
Reading 2 columns from CSV:        57.7 ms
Reading 2 columns from Parquet:    13.3 ms

The script, step by step

  • dtype and parse_dates are needed because the CSV does not say what type each column is. Without them, the date would be read as text. It is the lack of a schema, turned into code.
  • "status": "category" indicates that the column has few distinct values; Parquet will store it with a dictionary.
  • to_parquet(..., compression=...) writes the file. index=False avoids storing pandas' internal index, which adds nothing here.
  • columns=[...] when reading the Parquet file is column projection: the other three are not read from disk. In the CSV, usecols only discards the columns after having gone through the whole file.

What the result tells us

  1. The Parquet file takes up between 25% and 37% of what the CSV does, without losing information and with the schema added.
  2. The codecs behave as the table announced: snappy compresses the least, gzip the most, and zstd lands close to gzip at a much lower processing cost.
  3. Reading two columns is about four times faster, and that is on local disk. On object storage, where every byte travels over the network, the difference grows.
  4. This data is an unfavorable case. The identifiers and the amounts were generated at random, and random data hardly compresses. Real data contains many more repetitions (categories, cities, event types, devices), and clickstream, which is JSON with the field names repeated on every line, shrinks considerably more. That is why the estimate in lesson 02-03 assumed one eighth of the original volume: it is an assumption that Íñigo will have to confirm with a real sample.

One caveat for production: pandas has stored total_amount as a floating-point number. In the platform, amounts will be declared with Parquet's decimal type, for the same reason NUMERIC is used in the database.

Partitioning and partition pruning

A columnar format reduces what is read inside each file. Partitioning reduces the number of files that have to be opened.

Partitioning means distributing the files of a dataset into folders according to the value of one or more columns. The most widespread convention, inherited from Hive, names each folder column=value:

datacorp-data-cleansed/clickstream/events/
├── date=2026-11-16/
│   └── part-00000.parquet
├── date=2026-11-17/
│   └── part-00000.parquet
└── date=2026-11-18/
    ├── part-00000.parquet
    └── part-00001.parquet

Query engines recognize this convention: they treat date as one more column of the table, even though its value is not inside the files, but in the path. When a query filters on that column, the engine reads only the folders that satisfy the condition. This is called partition pruning.

-- "Add to cart" events on November 18
SELECT COUNT(*)
FROM cleansed.events
WHERE "date" = DATE '2026-11-18'         -- filter on the partition column (quoted: DATE is a reserved word)
  AND event_type = 'add_to_cart';
Unpartitioned Partitioned by date
Folders examined The whole history: 395 days 1
Data that is a candidate for reading All 13 months One day's worth: 0.25%
Inside each file Only the event_type column Only the event_type column

The two techniques multiply each other: partitioning discards files, and the columnar format discards columns and row groups within the ones that remain.

With pandas, writing and reading a partitioned dataset takes a single parameter:

import pandas as pd

orders = pd.read_parquet("orders_zstd.parquet")

# Partition column: the month of the order, derived from the date
orders["month"] = orders["order_date"].dt.strftime("%Y-%m")

# Write a partitioned dataset: one folder for each value of "month"
orders.to_parquet("cleansed/orders", engine="pyarrow", compression="zstd",
                  index=False, partition_cols=["month"])

# Read a single partition: the filter on "month" avoids opening the other folders
october = pd.read_parquet("cleansed/orders", filters=[("month", "=", "2026-10")],
                          columns=["status", "total_amount"])
print(len(october), "orders read from October 2026")
46476 orders read from October 2026

partition_cols=["month"] creates the folders month=2025-11/, month=2025-12/... and filters applies the pruning: of the twelve folders, one is opened.

Partitioning also has an operational advantage: it lets you rewrite one piece without touching the rest. If a day's load fails or has to be corrected, that day's folder is replaced. And it fits in with the lifecycle policies of lesson 02-03, which act by prefix and age.

Choosing the partition key: small files and over-partitioning

A good partition key meets three conditions:

  1. It appears in the filters of most queries. A partition that nobody filters on prunes nothing. In analytics, it is almost always the date.
  2. It has few distinct values (low cardinality): hundreds or a few thousand, not millions. Partitioning by customer_id would create 200,000 folders.
  3. It distributes the data evenly. If one partition contains 90% of the data, it is not much use.

The most common mistake is overdoing it. Over-partitioning fragments the data into too many folders and leads to the small files problem:

  • Each file requires at least one request to storage, and requests are billed and take time (lesson 02-03). Opening 10,000 files of 30 KB is much slower than opening one of 300 MB.
  • Each Parquet file carries its own footer and its own dictionaries: many small files compress worse.
  • The engine spends more time listing folders and planning than reading data.

We can measure it with the orders from the previous example:

Partitioning of one year of orders Files Average size Total size
Unpartitioned 1 8.2 MB 8.2 MB
By month 12 0.9 MB 10.9 MB
By day 365 31 KB 11.5 MB

Daily partitioning multiplies the number of files by 365 and increases the total size by 40%, in exchange for nothing: a whole year of orders fits in 8 MB.

As a reference, analytical engines work best with files of between about 128 MB and 1 GB. A rule of thumb follows from that: choose the granularity of the partition so that each one contains at least one such file; if the volume does not stretch that far, use coarser partitions. Let's apply it to DataCorp:

Data Daily volume in Parquet (estimated) Partition chosen Reason
Clickstream About 250 MB By day: date=2026-11-18 One day fills one or two files of a good size; queries filter by day
Orders, order lines, inventory, marketing, tickets From a few KB to 1 MB By month: month=2026-11 By day they would be tiny files. The month makes it possible to rewrite only the affected period
Customers, products and dimensions Small tables Unpartitioned They are read in full

For the small tables, monthly partitioning is not justified by performance (they could go unpartitioned), but by operations: each load rewrites only the current month.

Three additional remedies against small files:

  • Compacting: a periodic process that merges the small files of a partition into a few large ones.
  • Not partitioning by two columns unless there is a proven need: the values multiply. date and event_type with ten event types means ten times as many folders.
  • Batching on write: accumulating events and writing them in bulk, not one file for every tiny batch.

DataCorp's path and naming convention

A fixed convention lets people find the data, lets processes build the paths without looking them up and lets lifecycle and permission rules be expressed by prefix. Marta and Íñigo agree on the following.

RAW ZONE: original format, immutable, partitioned by load date
datacorp-data-raw/<source>/<entity>/load_date=YYYY-MM-DD/<entity>_<YYYYMMDD>.<ext>

  postgres/orders/load_date=2026-11-18/orders_20261118.csv.gz
  postgres/order_lines/load_date=2026-11-18/order_lines_20261118.csv.gz
  postgres/customers/load_date=2026-11-18/customers_20261118.csv.gz
  postgres/products/load_date=2026-11-18/products_20261118.csv.gz
  erp/inventory/load_date=2026-11-18/inventory_20261118.csv
  marketing/campaigns/load_date=2026-11-18/campaigns_20261118.json
  support/tickets/load_date=2026-11-18/tickets_20261118.csv.gz
  clickstream/events/load_date=2026-11-18/hour=14/events_20261118T1400.jsonl.gz

CLEANSED ZONE: Parquet (zstd), partitioned by business date
datacorp-data-cleansed/<source>/<entity>/<partition>/part-NNNNN.parquet

  postgres/orders/month=2026-11/part-00000.parquet
  postgres/order_lines/month=2026-11/part-00000.parquet
  postgres/customers/part-00000.parquet
  erp/inventory/month=2026-11/part-00000.parquet
  clickstream/events/date=2026-11-18/part-00000.parquet

CONSUMPTION ZONE: Parquet (zstd), one folder per table of the model
datacorp-data-consumption/<table>/<partition>/part-NNNNN.parquet

  fact_sales/month=2026-11/part-00000.parquet
  dim_customer/part-00000.parquet
  dim_product/part-00000.parquet
  dim_date/part-00000.parquet
  daily_net_sales/part-00000.parquet

The rules behind it:

  • Lowercase, no spaces, no accented or other special characters, with underscores within a name: order_lines, campaigns. It avoids problems between tools.
  • Dates in ISO format (YYYY-MM-DD): they sort alphabetically the same way they sort chronologically.
  • The source prefixes match those of the lifecycle policy in lesson 02-03 (postgres/, erp/, support/, clickstream/), and they are kept in the cleansed zone so that each piece of data can be traced back to its origin.
  • The raw zone is partitioned by load date; the other two, by business date. In the raw zone what matters is knowing when each file arrived and being able to reprocess a specific load; a file loaded today may contain an order from yesterday that was modified. In the cleansed and consumption zones, the partition is the date of the order or of the event, because that is what queries filter on.
  • Raw clickstream adds hour= because it arrives continuously and must be available in under an hour (RQ-04): 24 files a day of about 80 MB before compression. When it is cleansed it is grouped by day.
  • Text files are compressed with gzip when they are written by the ingestion process. Those delivered directly by a source, such as the ERP's CSV, are stored as they arrive.
  • part-NNNNN.parquet is the name the processing tools generate; no meaning is attached to it.
  • The consumption zone mirrors the dimensional model of lesson 02-05: one folder per table of the consumption schema.

Whether the consumption data is queried directly on these files or is also loaded into an analytical store with its own storage depends on the engine that is chosen, and that decision belongs to Module 6.

Table formats: a preview

A set of Parquet files in folders has limitations when compared with a database table: there are no transactions (a reader can see a half-finished load), modifying or deleting a row means rewriting files by hand, and changing the partitioning means moving everything. Open table formats (Delta Lake, Apache Iceberg and Apache Hudi) add a metadata layer on top of the Parquet files that provides ACID transactions, updates and deletes, schema evolution and querying of earlier versions. They are the basis of the lakehouse architecture, which we will study in lesson 06-04. For now it is enough to know that they build on what you have learned here: underneath, they are still partitioned Parquet files.

ADR-004: formats and partitioning

ADR-004: File formats and partitioning of the storage zones

Status: Accepted
Date: 2026-11-27
Author: Marta (data architect)
Reviewed by: Íñigo (data engineer)

CONTEXT
ADR-003 places the three zones of the platform on object storage and
requires open formats. The sources deliver CSV, JSON and JSON events
(RQ-03). Clickstream is 99.6% of the volume (RQ-01) and queries must respond
in under 5 seconds (RQ-05). The cost estimate shows that the relevant
expense is compute, not storage. ADR-002 requires the raw data to be kept
unmodified.

DECISION
1. Raw zone: the data is stored in the source's original format (CSV, JSON
   or JSON Lines), compressed with gzip when it is written by the ingestion
   process, with no conversion at all. It is partitioned by load date
   (load_date=YYYY-MM-DD) and, for clickstream, by hour as well.
2. Cleansed and consumption zones: the data is stored in Parquet with zstd
   compression.
3. The cleansed and consumption zones are partitioned by business date:
   by day (date=YYYY-MM-DD) for clickstream and by month (month=YYYY-MM) for
   the other tables with history. Dimension and reference tables are not
   partitioned.
4. Target file size of 128 MB to 1 GB when the volume allows it. No
   partitioning by more than one column without a measurement to justify it.
5. Paths follow the convention <source>/<entity>/<partition>/ in the raw and
   cleansed zones, and <table>/<partition>/ in the consumption zone.

ALTERNATIVES CONSIDERED
A. Converting to Parquet at ingestion and not keeping the original. Rejected:
   it violates ADR-002 and would make a conversion error unrecoverable.
B. CSV in every zone. Rejected: no types or schema, and every query would
   read the complete files.
C. Avro in the cleansed zone. Rejected: row-oriented; its advantage lies in
   streaming writes, not in querying.
D. ORC. Rejected: similar capabilities, with less support outside Hive.
E. Partitioning every table by day. Rejected: it would generate thousands of
   files of a few kilobytes in the small tables.
F. Adopting a table format now (Delta Lake, Iceberg or Hudi). Deferred: to be
   decided with the analytical engine. It is compatible with this decision.

CONSEQUENCES
Positive:
- Queries read only the partitions and columns they need, which reduces
  compute, the dominant cost.
- Open formats, readable by any engine: less lock-in.
- The raw zone makes it possible to reprocess any load.
Negative:
- The data exists twice (original and Parquet), at an acceptable cost.
- Parquet does not support modifications: correcting a piece of data means
  rewriting the entire partition.
- File sizes have to be monitored, and files compacted if they proliferate.
- Two partition granularities (day and month) that the processes must know.
Follow-up work:
- Measure the actual compression with a clickstream sample.
- Define the compaction process.

Common Mistakes and Tips

  • Converting the data at ingestion and throwing away the original. If the conversion misinterpreted a date or truncated a field, there is no longer any way to know or to repair it.
  • Using CSV or JSON for the analysis zones. It is convenient at first and condemns every query to reading everything.
  • Compressing a single gigantic text file with gzip. It is not splittable: it will be processed with a single thread. Split it into moderately sized files.
  • Partitioning by a high-cardinality column. Customer identifiers, order identifiers or full timestamps produce millions of folders.
  • Partitioning by several columns "just in case". Each level multiplies the files. Start with the date and add only what a measurement justifies.
  • Filtering without using the partition column. WHERE CAST(event_time AS DATE) = ... on an internal column prunes nothing; you have to filter on the partition column (date).
  • Changing the path convention on the fly. Processes, permissions and lifecycle rules depend on it. Decide it early and document it.
  • Tip: before settling on a partitioning scheme, calculate the resulting file size: daily volume divided by the number of partitions created each day.
  • Tip: measure with your own data. Compression ratios and timings depend on the content; ten minutes with a real sample are worth more than any comparison table.

Exercises

Exercise 1: Choosing the format

State which format you would use in each case and why:

  1. Finance asks for an extract with the month's 200 returned orders to review it in a spreadsheet.
  2. The clickstream events as sent by the mobile app, in the raw zone.
  3. The fact_sales table in the consumption zone.
  4. A system that publishes each order as a message for other systems to consume in streaming.

Exercise 2: Evaluating a partitioning scheme

Íñigo proposes storing the cleansed tickets (400 a day, about 2 KB each before compression, 3 years of retention) partitioned by date and by status (5 possible statuses).

  1. How many folders would there be after 3 years, at most?
  2. Roughly how much space would each file take up? Assume Parquet reduces the size to one fifth.
  3. What problem do you see and what partitioning do you propose? What other drawback does partitioning by status have?

Exercise 3: What gets read?

The cleansed events table is partitioned by date, in Parquet, with 395 days of history. For each query, state how many partitions are read and which columns:

-- A
SELECT COUNT(*) FROM cleansed.events
WHERE "date" BETWEEN DATE '2026-11-01' AND DATE '2026-11-07';

-- B
SELECT event_type, COUNT(*) FROM cleansed.events
WHERE customer_id = 10472
GROUP BY event_type;

-- C
SELECT * FROM cleansed.events
WHERE "date" = DATE '2026-11-18' AND event_type = 'search';

Which one is the most expensive? How would you improve query C?

Solutions

Exercise 1

  1. CSV. It is small, a person is going to open it and the spreadsheet reads it directly. Efficiency is irrelevant with 200 rows.
  2. JSON Lines, the original format, compressed with gzip. The raw zone does not convert (ADR-002 and ADR-004).
  3. Parquet with zstd compression, partitioned by month. It is an analysis table that is queried by columns.
  4. Avro. It is written record by record, includes the schema and handles its evolution well between the system that emits and those that consume. (JSON is a common and simpler alternative, without those guarantees.)

Exercise 2

  1. 3 years × 365 days × 5 statuses = 5,475 folders, each with at least one file.
  2. 400 tickets × 2 KB = 800 KB a day; in Parquet, about 160 KB a day, spread across 5 statuses: about 32 KB per file on average.
  3. It is a clear case of over-partitioning: thousands of tiny files for a total of about 175 MB in three years. Proposal: partition by month (36 folders, with files of about 5 MB) or even not partition at all. The second drawback is that a ticket's status changes: when it goes from "open" to "closed", the row would have to move to another folder, which means rewriting two partitions. You never partition by a mutable attribute.

Tip: the open date is a good key precisely because it never changes.

Exercise 3

  • A: 7 partitions. No columns: COUNT(*) can be answered with the row count stored in the footer of each Parquet file.
  • B: all 395 partitions, because it does not filter on date. It reads only the customer_id and event_type columns, and the statistics may help skip some row groups, but every file has to be opened.
  • C: 1 partition, but all the columns, because of the SELECT *.

The most expensive is B: partitioning does not help queries that do not filter on the partition key. If that query were frequent, it would have to be bounded with a date range, or a specific table would have to be prepared in the consumption zone. Query C is improved by replacing SELECT * with the columns that are really needed, to take advantage of the columnar format.

Conclusion

On object storage, data is files, and their format and organization determine how much has to be read to answer a question. We have compared the text formats (CSV and JSON Lines), universal but schemaless and bulky, with the binary ones: Avro, row-oriented and excellent for streaming writes, and Parquet and ORC, columnar and designed for analysis. We have seen the role of compression, splittability and schema evolution, and we have measured that a Parquet file takes up about a third of its CSV and serves two columns four times faster. Partitioning completes the picture: organizing files into column=value folders lets the engine prune the ones it does not need, provided the key is chosen judiciously and you do not fall into over-partitioning. ADR-004 sets it down for DataCorp: raw zone in the original format and partitioned by load date; cleansed and consumption zones in Parquet with zstd, partitioned by business date, with a common path convention.

This lesson brings Module 2 to an end. DataCorp now knows where and how its data will be stored: which types of storage it needs, which database models (and which not), in which cloud and at what cost, with which operational and dimensional schemas, and in which files and paths. But a well-designed infrastructure does not guarantee reliable data: nobody is yet accountable for each dataset, nobody has defined who can see what or how a figure is checked to be correct. That is what Module 3 is about, devoted to data management, which begins with the piece that gives meaning to all the others: data governance.

© Copyright 2026. All rights reserved