Sub topic 15
Designing a catalog and schema layout
This chapter assumes you can write basic SQL, know what a metastore, catalog, schema, and table are, and have seen GRANT and REVOKE. It shows how to turn those pieces into a layout that fits your organization.
Start from the boundaries you need
A layout is a set of decisions about where to draw boundaries. Each level of the hierarchy gives you a different kind of boundary.
| Level | Typical boundary | Why it works |
|---|---|---|
| Metastore | One per cloud region | Fixed by region. Workspaces in that region share it. |
| Catalog | Environment, business unit, or domain | Privileges and default managed storage can be set once for the whole catalog. |
| Schema | Team, project, or data layer | Groups tables that share an owner and an audience. |
| Table | One dataset | The unit people query. |
Pick the catalog boundary first. It is the most expensive one to change later, because every query uses the catalog name and grants are usually made at this level.
Common patterns
Two patterns cover most organizations.
- Catalog per environment. Examples are
dev,test, andprod. Schemas inside hold the same subject areas in each environment, such assalesandmarketing. Promoting code means changing the catalog name, not the schema or table names. - Catalog per domain. Examples are
sales,finance, andhr. Each domain team owns its catalog and manages its own grants. Environments are then separated by schema naming or by a second set of catalogs.
You can combine them, for example prod_sales and dev_sales. This gives you both separation, at the cost of more catalogs to manage.
Use inheritance to keep grants small
Privileges granted on a catalog or schema apply to the objects below it, including objects created later. Grant at the highest level that matches the audience, and use groups instead of individual users.
-- Analysts can read everything in the prod sales schema, now and in the future.
GRANT USE CATALOG ON CATALOG prod TO `data-analysts`;
GRANT USE SCHEMA ON SCHEMA prod.sales TO `data-analysts`;
GRANT SELECT ON SCHEMA prod.sales TO `data-analysts`;Three grants cover every current and future table in prod.sales. Granting on each table would need a new statement for every table you create.
Choose storage per catalog
Managed tables are stored in managed storage. You can assign a storage location to a catalog or a schema, so one team's data lands in its own cloud path. Do this when teams need separate storage accounts, retention rules, or cost tracking. Keep external tables for data that must stay at a path you control, and make sure an external location covers that path.
Common mistakes
- Too many catalogs. Each one needs grants and ownership. Start with the fewest that give you the isolation you need.
- Granting to individuals. Grants tied to people break when they change roles. Grant to groups.
- Mixing audiences in one schema. If a schema holds both public and restricted tables, schema-level grants cannot separate them. Split the schema instead.
- Putting the environment in table names. Names like
orders_devdefeat the namespace. Let the catalog carry that information.
Exercise
A company has two teams, sales and finance, and wants separate dev and prod environments. Finance data must be readable only by finance staff. Propose a catalog layout and say where you would grant SELECT to the finance group.
Show answer
Use a catalog per environment and domain, such as dev_sales, prod_sales, dev_finance, and prod_finance, or use dev and prod catalogs with sales and finance schemas. In the second option, grant USE CATALOG on prod, USE SCHEMA on prod.finance, and SELECT on the schema prod.finance to the finance group. Because the schema holds only finance data, a single schema-level grant covers current and future tables. Do not grant on prod.sales to the finance group.