Sub topic 5
Unity Catalog essentials for feature storage
This chapter assumes you know basic PySpark, Delta tables, and Databricks notebooks. It also assumes you have seen the catalog.schema.table naming style. Here you will see how Unity Catalog stores and governs feature tables, so that the next chapters can create them.
The three-level namespace
Unity Catalog (UC) is the governance layer for data and AI assets in Databricks. It organizes objects in three levels:
- Catalog: the top-level container, often one per environment or business unit.
- Schema: a group of related objects inside a catalog.
- Table: the object that holds data, such as a feature table.
A feature table is addressed by its full name, for example main.ml.user_features. Here main is the catalog, ml is the schema, and user_features is the table. The same pattern covers models, so the model main.ml.churn_model lives beside the features it uses.
A feature table is a Delta table
In Unity Catalog, a feature table is a Delta table with a primary key constraint on non-null key columns. No special storage format exists. You can create one with plain SQL:
CREATE TABLE main.ml.product_features (
product_id BIGINT NOT NULL,
category STRING,
avg_rating DOUBLE,
CONSTRAINT product_features_pk PRIMARY KEY (product_id)
);The NOT NULL on the key column is required. Unity Catalog primary keys are informational, which means the constraint identifies the key but does not reject duplicate rows. Keeping keys unique is your pipeline's job.
Because the table is a normal UC table, you can query it with SQL, read it with spark.table, and apply the same governance as for any other table.
Permissions you need
Access follows the usual UC privilege model. These are the privileges that matter for feature work:
| Privilege | Where it applies | Why you need it |
|---|---|---|
| `USE CATALOG` | Catalog | Lets you see into the catalog |
| `USE SCHEMA` | Schema | Lets you see into the schema |
| `CREATE TABLE` | Schema | Lets you create feature tables |
| `SELECT` | Table | Lets you read features for training and scoring |
| `MODIFY` | Table | Lets you write or merge feature data |
A common split gives a feature pipeline MODIFY on the table, while data scientists get only SELECT. Grant privileges with SQL:
GRANT USE CATALOG ON CATALOG main TO `data-scientists`;
GRANT USE SCHEMA ON SCHEMA main.ml TO `data-scientists`;
GRANT SELECT ON TABLE main.ml.product_features TO `data-scientists`;Common errors
- Missing
USE CATALOGorUSE SCHEMA. A user withSELECTon the table still cannot read it without access to the parent levels. - A nullable key column. Creating the primary key fails if the column is not declared
NOT NULL. - Wrong namespace. A table name with only one or two parts resolves against the current catalog and schema, which may not be
main.ml. Use the full three-part name in shared code. - Assuming key uniqueness is enforced. Duplicate keys can silently produce ambiguous lookups later, so check uniqueness before you write.
Exercise
A data scientist has SELECT on main.ml.user_features but gets a permission error when reading it. Which two other privileges should you check, and why?
Show answer
Check USE CATALOG on main and USE SCHEMA on main.ml. Table-level SELECT is not enough without access to the parent catalog and schema.