Sub topic 2
Pointing COPY INTO at your data: volumes, external locations and permissions
This chapter assumes you know basic SQL, have worked with Delta tables, and can open a Databricks workspace with a SQL warehouse or cluster. It covers where COPY INTO can read files from and which permissions it needs. The statement itself is covered in the next chapter.
The source is a path
COPY INTO reads from a path in the FROM clause. In Unity Catalog, that path usually points to one of two things:
- A volume. A volume is a Unity Catalog object that holds files in cloud storage. Its path looks like
/Volumes/<catalog>/<schema>/<volume>/<folder>/. - A cloud storage URI, such as
s3://bucket/path/,abfss://[email protected]/path/orgs://bucket/path/. Unity Catalog governs access to these paths through an external location.
An external location is a Unity Catalog object. It pairs a cloud storage path with a storage credential, which is the identity Databricks uses to reach that storage.
How access flows
Unity Catalog checks your permissions before COPY INTO reads a single file. You need rights on the source and on the target table.
The privileges involved:
| Privilege | Granted on | Needed for |
|---|---|---|
| `READ VOLUME` | The volume | Reading files from a `/Volumes/...` path |
| `READ FILES` | An external location | Reading files from a cloud URI |
| `MODIFY` | The target table | Inserting rows with COPY INTO |
| `USE CATALOG`, `USE SCHEMA` | The catalog and schema | Reaching the objects inside them |
Granting access
A metastore admin or the object owner grants these privileges. The example below lets a group named data_engineers load from a volume into a table.
GRANT USE CATALOG ON CATALOG main TO `data_engineers`;
GRANT USE SCHEMA ON SCHEMA main.sales TO `data_engineers`;
GRANT READ VOLUME ON VOLUME main.sales.landing TO `data_engineers`;
GRANT MODIFY ON TABLE main.sales.orders TO `data_engineers`;For a cloud URI, grant READ FILES on the external location instead:
GRANT READ FILES ON EXTERNAL LOCATION landing_zone TO `data_engineers`;Here landing_zone is the name of an external location that an admin has already created.
Checking what you can see
Before you write a load, confirm that the path resolves and that you can list it. In a notebook, this statement lists the files in a volume folder:
LIST '/Volumes/main/sales/landing/orders/';If the folder shows the files you expect, the path and your READ VOLUME privilege are working. You can also run SHOW GRANTS ON VOLUME main.sales.landing to see who holds which privileges.
Common access errors
- A permission error that names the volume or external location means you lack
READ VOLUMEorREAD FILES. Ask the owner for the grant. - A "path does not exist" error usually means a typo in the catalog, schema, volume or folder name. Volume paths are case-sensitive in the folder part.
- A URI that matches no external location fails with an error about the path not being covered. An admin has to create an external location that contains that path.
- Writing works but reading fails when you have
MODIFYon the table but not read rights on the source. The two checks are independent.
Exercise
A user has MODIFY on main.sales.orders and runs COPY INTO from 's3://acme-landing/orders/'. The statement fails with a permission error on the path. Which privilege is probably missing, and on which object?
Show answer
READ FILES on the external location that covers s3://acme-landing/orders/. MODIFY only controls writing to the target table. Reading the source files is checked separately against the external location.
Exercise
Write the statement that lists the files in the volume folder /Volumes/main/sales/landing/returns/ so you can confirm access before loading.
Show answer
LIST '/Volumes/main/sales/landing/returns/';