TECHNOLOGIESTieInn Technologies

File formats: Parquet and Delta

Spark / PySpark · 12 questions

Short notes

Key idea

The file format decides how fast Spark can read. Parquet is columnar, compressed and typed, so Spark reads only the needed columns and skips row groups. Delta Lake adds a transaction log on top of Parquet: ACID writes, updates, merges and time travel.

Syntax

df.write.mode("overwrite").partitionBy("order_date").parquet("gs://lake/orders")
spark.read.parquet("gs://lake/orders").filter("order_date = '2024-03-05'")

df.write.format("delta").mode("append").save("/lake/orders_delta")
spark.read.format("delta").option("versionAsOf", 3).load("/lake/orders_delta")
# MERGE INTO orders_delta t USING updates s ON t.id = s.id
# WHEN MATCHED THEN UPDATE SET * WHEN NOT MATCHED THEN INSERT *

Example

The same 50 GB as CSV vs Parquet: a query on two columns reads 50 GB of CSV but about 4 GB of Parquet, and Parquet keeps the types, so there's no schema guessing.

Traps

  • CSV and JSON have no real types and can't skip columns; convert early.
  • Partitioning by a high-cardinality column (customer_id) creates millions of tiny folders.
  • Plain Parquet folders can't be updated safely; two writers can corrupt them. Use Delta or Iceberg.
  • Run OPTIMIZE/VACUUM on Delta tables to compact files and clean old versions.

Want the full lesson with step-by-step examples, a project and a certificate? Spark / PySpark course, ₹120 →

Questions

Open in Code Lab5 free questions
5 questions

    File formats: Parquet and Delta

  1. Question 1easy

    Why is Parquet faster than CSV for analytical queries?

  2. File formats: Parquet and Delta

  3. Question 2medium

    What does Delta Lake add on top of Parquet files?

  4. File formats: Parquet and Delta

  5. Question 3medium

    Data is written with partitionBy("order_date"). A query filters order_date = '2024-02-29'. What does Spark read?

  6. File formats: Parquet and Delta

  7. Question 4medium

    Which format is most common for individual messages in a Kafka-style stream?

  8. File formats: Parquet and Delta

  9. Question 5hard

    A table at gs://lake/orders/ is partitioned by order_date with 3 years of data. A job runs today.write.mode("overwrite").partitionBy("order_date").parquet("gs://lake/orders/") with default settings. What happens?

7 more questions on this topic, with hints, and tests

Sign up free for 21 days of every question and test.