Sub topic 1
What a SQL warehouse is and when to use one
Prerequisites
This chapter assumes you can write basic SQL (SELECT, WHERE, JOIN, GROUP BY). It also assumes you have opened a Databricks workspace and know roughly what tables, schemas, and catalogs are. A general sense of how cloud compute is billed helps with the cost points near the end.
The working model
A SQL warehouse is a compute resource that runs SQL statements against data in Databricks. It is not a database and it does not store data. Your tables live in cloud storage and are governed by Unity Catalog. The warehouse supplies the CPUs and memory that read, filter, join, and aggregate that data.
Inside a warehouse sits one or more clusters, which are groups of machines that do the work. You never log in to these machines. You pick settings such as type, size, and auto stop, and Databricks manages the rest. Later chapters cover each setting.
Any client that sends SQL to the warehouse uses this same compute:
- The SQL editor in the workspace.
- Dashboards and alerts built from saved queries.
- BI tools that connect over JDBC or ODBC.
- Code that calls the Statement Execution API.
How it differs from other compute
Databricks has other compute, mainly all-purpose clusters and jobs compute. They run notebooks and code in Python, Scala, or R as well as SQL. A SQL warehouse accepts only SQL. In return it is tuned for SQL: it starts quickly, handles many concurrent queries, and can add clusters when load rises.
| Compute | Best for | Languages |
|---|---|---|
| SQL warehouse | Ad hoc queries, dashboards, BI tools | SQL |
| All-purpose cluster | Interactive notebooks, data science | SQL, Python, Scala, R |
| Jobs compute | Scheduled pipelines | SQL, Python, Scala, R |
When to use one
Use a SQL warehouse when the work is SQL and people or tools wait for the answer. Typical cases are analysts exploring tables, dashboards that refresh on a schedule, and BI tools such as Tableau or Power BI that need a SQL endpoint.
Use other compute when you need Python or Scala logic, machine learning libraries, or custom libraries on the cluster.
Common errors
- Querying with no running warehouse. A stopped warehouse starts when a query arrives, so the first query waits for startup. Startup time depends on the warehouse type.
- Choosing the wrong warehouse in the editor. The editor sends your query to whichever warehouse is selected. Check the selector before you run.
- Missing permissions. You need permission to use the warehouse and access to the data in Unity Catalog. Either one can fail on its own.
- Leaving a warehouse running. A running warehouse bills while it is up, even when idle. Auto stop limits this.
Try it
Open the SQL editor, choose a warehouse, and run this query. It lists the catalogs you can see and reads a sample table by its full name.
SHOW CATALOGS;
SELECT * FROM samples.nyctaxi.trips LIMIT 10;If the second statement fails with a permission error, the warehouse is working and the problem is data access.
Exercise
A teammate says a query failed with "permission denied" on a table, even though they can start and use the warehouse. Which of the two access layers is the likely problem, and why?
Show answer
Data access in Unity Catalog. Permission to use a warehouse is separate from permission to read a table. The warehouse ran the statement, but the user lacks a privilege such as SELECT on the table or USE on its catalog or schema.