Sub topic 13
Views, Volumes, and Functions
This chapter assumes you have read the earlier chapters on the three-level namespace, managed and external tables, and GRANT/REVOKE with inheritance. You should be comfortable with dev.sales.orders and with the idea that a privilege on a parent object can flow down to its children.
Tables are only one kind of object that lives in a schema. Three others share the same namespace and the same privilege model: views, volumes, and functions. Each one needs its own privilege, and each has behaviors that surprise people the first time.
Where these objects live
A schema can hold several kinds of securable objects. All of them are addressed as catalog.schema.object, and all of them have an owner and can be the target of a GRANT.
| Object | Holds | Read or use it with | Create it with (on the schema) |
|---|---|---|---|
| Table | Rows | `SELECT` | `CREATE TABLE` |
| View | A saved query | `SELECT` | `CREATE TABLE` |
| Volume | Files of any format | `READ VOLUME`, `WRITE VOLUME` | `CREATE VOLUME` |
| Function | Reusable logic | `EXECUTE` | `CREATE FUNCTION` |
Creating a view uses the CREATE TABLE privilege because Unity Catalog treats a view as a kind of table. In information_schema, a view appears with table_type set to VIEW.
Views
A view is a named query. It stores no data. Each time someone queries the view, the query runs against the underlying tables.
CREATE VIEW dev.sales.big_orders AS
SELECT order_id, customer_id, order_ts, amount
FROM dev.sales.orders
WHERE amount >= 50;
SELECT * FROM dev.sales.big_orders;How access works through a view
A view runs with the permissions of its owner when it reads the underlying tables. The person querying the view does not need access to those tables. This gives you a simple way to expose a subset of a table.
To query dev.sales.big_orders, a user needs:
USE CATALOGondev.USE SCHEMAondev.sales.SELECTon the view.
They do not need SELECT on dev.sales.orders.
GRANT USE CATALOG ON CATALOG dev TO `data-analysts`;
GRANT USE SCHEMA ON SCHEMA dev.sales TO `data-analysts`;
GRANT SELECT ON VIEW dev.sales.big_orders TO `data-analysts`;With this grant the group can read the large orders and nothing else in the schema. The grant on the view does not expose the base table.
The owner must keep their own access to the underlying tables. If the owner loses SELECT on dev.sales.orders, or the table's catalog or schema becomes inaccessible to them, the view fails for every user, including users who hold SELECT on the view.
Dynamic views
A dynamic view changes its result depending on who runs it. It uses identity functions such as is_account_group_member() or current_user().
CREATE VIEW dev.sales.orders_masked AS
SELECT
order_id,
customer_id,
order_ts,
CASE
WHEN is_account_group_member('finance') THEN amount
ELSE NULL
END AS amount
FROM dev.sales.orders;Members of finance see the real amount. Everyone else sees NULL. You give analysts access to orders_masked and withhold access to orders itself. If you skip the second step, the masking can be bypassed by querying the table.
Unity Catalog also supports row filters and column masks attached directly to a table. These are often easier to maintain than dynamic views because the rule follows the table and users cannot query around it. Use a dynamic view when you need a quick, readable rule on a single derived dataset.
Other kinds of views
- Temporary views exist only for the current session. They are not stored in a schema and are not securable objects.
- Materialized views store their results and refresh them on a schedule or on demand. They are governed through Unity Catalog like other schema objects, but they depend on specific compute, so check the Databricks documentation for current requirements.
Volumes
Tables govern tabular data. A volume governs files: CSV drops from a vendor, images, PDFs, model artifacts, or ZIP archives. Before volumes, teams often mounted cloud storage paths and managed access outside Unity Catalog. A volume brings those files under the same grants and audit trail as your tables.
You reach a volume's files through a path with a fixed shape:
/Volumes/<catalog>/<schema>/<volume>/<path-to-file>Managed and external volumes
Volumes follow the same managed versus external split as tables.
| Row | Managed volume | External volume |
|---|---|---|
| Storage location | Managed storage of the schema, catalog, or metastore | A path you name, covered by an external location |
| `DROP VOLUME` | Deletes the files | Removes the volume. The files stay in storage. |
| Typical use | New file areas you own | Existing files that other systems also use |
-- Managed volume
CREATE VOLUME IF NOT EXISTS dev.sales.landing
COMMENT 'Incoming CSV files from the order system';
-- External volume (the bucket name is a placeholder)
CREATE EXTERNAL VOLUME IF NOT EXISTS dev.sales.partner_files
LOCATION 's3://example-bucket/partners/files';The external volume only works if the path falls inside an external location that you have permission to use. This is the same rule that applies to external tables.
Using a volume
Once files are in a volume, you can read them with SQL.
SELECT *
FROM read_files(
'/Volumes/dev/sales/landing/',
format => 'csv',
header => true
);Unity Catalog checks privileges when you access the path, the same way it checks them for a table.
GRANT USE CATALOG ON CATALOG dev TO `data-engineers`;
GRANT USE SCHEMA ON SCHEMA dev.sales TO `data-engineers`;
GRANT READ VOLUME, WRITE VOLUME ON VOLUME dev.sales.landing TO `data-engineers`;READ VOLUME lets a principal read and list files. WRITE VOLUME lets them add, change, and delete files. Neither is covered by SELECT, so a schema-level GRANT SELECT does not give anyone access to the files in a volume.
Functions
A user-defined function (UDF) in Unity Catalog is a function stored as a schema object. You write it once, grant EXECUTE, and anyone with access can call it by name. This is useful for business rules that must be the same everywhere, such as currency conversion or an ID format check.
CREATE OR REPLACE FUNCTION dev.sales.to_usd(
amount DECIMAL(10,2),
rate DECIMAL(10,4)
)
RETURNS DECIMAL(12,2)
RETURN ROUND(amount * rate, 2);
SELECT order_id, dev.sales.to_usd(amount, 1.0850) AS amount_usd
FROM dev.sales.orders;Grant access with EXECUTE:
GRANT EXECUTE ON FUNCTION dev.sales.to_usd TO `data-analysts`;The caller also needs USE CATALOG and USE SCHEMA on the parents. Without them the function name will not resolve, even if EXECUTE is granted.
Unity Catalog also supports Python UDFs, which let you use more complex logic than SQL allows. The governance model is the same: a schema object, an owner, and an EXECUTE grant.
Inheritance applies to all of them
Privileges granted on a schema flow down to its objects, including ones created later. The same four lines cover each type:
GRANT SELECT ON SCHEMA dev.sales TO `data-analysts`; -- tables and views
GRANT READ VOLUME ON SCHEMA dev.sales TO `data-analysts`; -- volumes
GRANT EXECUTE ON SCHEMA dev.sales TO `data-analysts`; -- functionsBe careful with a schema-level SELECT when the schema contains a dynamic view and the base table it protects. The grant reaches both, and the masking is bypassed. Keep sensitive base tables in a separate schema from the views that expose them, and grant on the views' schema only.
Inspecting these objects
Each object type has its own listing command and its own information_schema view.
SHOW VIEWS IN dev.sales;
SHOW VOLUMES IN dev.sales;
SHOW USER FUNCTIONS IN dev.sales;
SELECT volume_name, volume_type
FROM dev.information_schema.volumes
WHERE volume_schema = 'sales';
SELECT routine_name
FROM dev.information_schema.routines
WHERE routine_schema = 'sales';SHOW GRANTS ON VOLUME dev.sales.landing and SHOW GRANTS ON FUNCTION dev.sales.to_usd list the grants on a single object.
Common errors
- "Permission denied" on a view that the user has
SELECTon. CheckUSE SCHEMAandUSE CATALOGfirst. Then check that the view's owner can still read the base tables. - A group can read tables but not files.
SELECTdoes not cover volumes. GrantREAD VOLUME. - A function call fails with "cannot be found." The caller probably lacks
USE SCHEMA, or the name is not fully qualified and the current schema is different. - Files vanished after a
DROP VOLUME. The volume was managed. Checkvolume_typebefore dropping.
Exercise
The schema dev.hr holds a table employees and a view employee_directory that selects only the name and department columns from employees. A group staff needs to look up the directory but must not see salaries. Which privileges does staff need, and which does it not need?
Show answer
staff needs USE CATALOG on dev, USE SCHEMA on dev.hr, and SELECT on the view dev.hr.employee_directory. It does not need SELECT on dev.hr.employees, because the view reads the table with its owner's permissions. Do not grant SELECT on the whole schema, because that would also cover the employees table and expose the salaries. The view's owner must keep SELECT on employees, or the view will fail for everyone.
Exercise
A team drops a volume and finds that the files in cloud storage are still there. What kind of volume was it, and what would have happened with the other kind?
Show answer
It was an external volume. Dropping an external volume removes only the Unity Catalog object and leaves the files at the storage path. Dropping a managed volume deletes the files too.