Sub topic 3
Unity Catalog: Catalogs, Schemas, and Tables
Assume you know basic SQL, Python, cloud storage, and the difference between a data lake and a data warehouse. This chapter connects Unity Catalog to querying, jobs, governance, collaboration, cost, and machine learning.
Unity Catalog and the three-level name
Unity Catalog is Databricks’ governance layer. It organizes data with a three-level namespace:
catalog.schema.table
A catalog is a top-level container. A schema groups related tables and views. A table contains structured data, often stored as a Delta Lake table on cloud object storage.
CREATE SCHEMA IF NOT EXISTS main.tutorial;
CREATE TABLE IF NOT EXISTS main.tutorial.orders (
order_id BIGINT,
customer_id BIGINT,
amount DECIMAL(10, 2)
);
INSERT INTO main.tutorial.orders VALUES
(1, 101, 25.00),
(2, 102, 40.50);Querying and scheduling
Databricks SQL runs SQL statements through a SQL warehouse. A notebook can query the same table through Spark:
from pyspark.sql import functions as F
df = spark.table("main.tutorial.orders")
totals = df.groupBy("customer_id").agg(
F.sum("amount").alias("total_amount")
)
display(totals)A notebook becomes a scheduled job when you add it as a task in a Databricks job. The job starts compute, runs the notebook, records results and logs, and can retry or alert on failure.
Data organization and access
Teams often use the medallion pattern:
- Bronze stores raw ingested data.
- Silver stores cleaned and validated data.
- Gold stores business-ready aggregates.
Unity Catalog permissions apply at each level. A user needs USE CATALOG, USE SCHEMA, and SELECT to read a table.
GRANT USE CATALOG ON CATALOG main TO `data-analysts`;
GRANT USE SCHEMA ON SCHEMA main.tutorial TO `data-analysts`;
GRANT SELECT ON TABLE main.tutorial.orders TO `data-analysts`;
DESCRIBE HISTORY main.tutorial.orders;Audit logs and table history help show who accessed data and how a table changed.
> callout note > Grant access to groups rather than individual users. This makes reviews and removals easier.
Collaboration, cost, and AI
Git folders let teams synchronize notebooks and source files with a Git repository. Use branches and pull requests for review.
Usage is billed through compute consumption, commonly measured in DBUs, plus cloud infrastructure charges. Job compute usually stops after a run; all-purpose compute can cost more when left running.
Databricks also supports machine-learning training, feature engineering, model tracking, and model serving. These workloads use the same governed data and compute resources.
Exercise
Which name identifies the orders table in the example?
Show answer
main.tutorial.orders. It names the catalog, schema, and table.