Sub topic 2
Compute, Spark, Notebooks, and Delta Lake
Assume you know basic SQL and Python, understand cloud storage, and know the difference between a data lake and a data warehouse. This chapter connects those ideas to Databricks compute and table processing.
Choosing compute
Compute is the CPU, memory, and software that runs your code. Databricks offers several choices:
- An all-purpose cluster is interactive compute for notebooks and exploration. It stays available while you work.
- Job compute is temporary compute created for a scheduled workflow. It ends after the job finishes, which usually reduces idle cost.
- A SQL warehouse is compute optimized for SQL queries, dashboards, and analysts. It can serve many SQL users concurrently.
- Serverless compute is managed by Databricks. You choose fewer infrastructure settings, while Databricks starts and scales resources for you.
Use an all-purpose cluster for development, job compute for production pipelines, and a SQL warehouse for SQL-first workloads.
Spark as the engine underneath
Apache Spark is a distributed processing engine. It divides a large operation into tasks and runs those tasks across multiple machines. Databricks adds managed compute, notebooks, governance, and platform tools around Spark.
Spark is usually lazy: transformations such as filter and groupBy describe a plan, while an action such as display or write starts execution.
Working in notebooks
A notebook combines executable cells, text, and results. Attach it to a cluster or serverless compute, then use Python, SQL, or another supported language. The predefined spark session lets PySpark code access tables.
from pyspark.sql import functions as F
orders = spark.table("main.tutorial.orders")
totals = (
orders.groupBy("customer_id")
.agg(F.sum("amount").alias("total_amount"))
)
display(totals)Delta Lake: reliable tables on open storage
Delta Lake stores table data in open cloud files and records changes in a transaction log. The log supports ACID transactions, schema enforcement, and table history. This makes concurrent writes and reproducible reads safer than treating raw files as tables.
Exercise
Which compute option is usually the best fit for a scheduled production notebook?
Show answer
Job compute, because it can start for the run and terminate afterward.