Sub topic 2
The object hierarchy and securable objects
This chapter assumes you know basic SQL and can run statements in a Databricks notebook or the SQL editor. It also assumes you understand users, groups and role-based access control in general.
Unity Catalog organizes everything it governs into a tree. Permissions attach to nodes of that tree, so you need to know the tree before you can reason about who can see what.
The three-level namespace
A securable object is any object in Unity Catalog on which you can grant a privilege. Most data objects are named with three parts: catalog, schema, and object.
SELECT * FROM main.sales.orders;Here main is the catalog, sales is the schema, and orders is the table. Writing the full name avoids ambiguity when you work in several catalogs.
The levels of the hierarchy
- Metastore: the top-level container for metadata and permissions. One metastore is attached to each region's workspaces, and it can be shared by many workspaces.
- Catalog: the first level of the namespace. Teams often use catalogs to separate environments or business domains.
- Schema: also called a database. It groups related objects inside a catalog.
- Objects inside a schema: tables, views, volumes, functions, and registered models.
What each object holds
| Object | What it is |
|---|---|
| Table | Structured rows and columns, either managed by Unity Catalog or external. |
| View | A saved query that behaves like a read-only table. |
| Volume | A governed location for files such as CSVs, images or libraries. |
| Function | A reusable SQL or Python routine, including row filter and mask functions. |
| Registered model | A versioned machine learning model. |
Tables hold data in rows and columns. Volumes hold files that do not fit a table. Giving files their own securable type lets you control file access with the same GRANT statements you use for tables.
Securables outside the namespace
Some securables sit directly under the metastore and are not part of the catalog.schema.object path. These include storage credentials, external locations, connections, shares, and recipients. A later chapter covers storage credentials and external locations in detail. For now, remember that they are separate objects with their own privileges.
Why the hierarchy matters for permissions
Permissions follow the tree. To query a table, a principal needs access to each level above it as well as to the table. The privilege to use a catalog and a schema is separate from the privilege to read a table:
GRANT USE CATALOG ON CATALOG main TO `data-analysts`;
GRANT USE SCHEMA ON SCHEMA main.sales TO `data-analysts`;
GRANT SELECT ON TABLE main.sales.orders TO `data-analysts`;A principal that holds only SELECT on the table cannot read it, because it cannot traverse the catalog and schema. This is the most common cause of "table not found" or permission errors for people who appear to have the right grant.
Common errors
- Using a two-part name by mistake. If you write
sales.orders, Unity Catalog resolvessalesas a schema in your current catalog. Set the catalog withUSE CATALOGor write the full three-part name. - Granting at the wrong level. A grant on a table affects only that table. A grant on a schema applies to the objects in it, as the inheritance chapter explains.
- Forgetting that views are objects too. A view needs its own grants, and it is a separate securable from the tables it reads.
Exercise
A user has SELECT on main.sales.orders but gets a permission error when querying it. Which two privileges are most likely missing, and on which objects?
Show answer
USE CATALOG on the catalog main, and USE SCHEMA on the schema main.sales. SELECT on the table is useless without the ability to traverse its parent objects.