Catalog, schema, table, volume
Unity Catalog's three-level namespace hands-on: current_catalog and current_schema, creating a schema, tables and a volume inside it, and reading a table's own fully qualified name out of describe detail.
What you will learn
- What the three parts of
catalog.schema.tableactually are, and which one you usually create. current_catalog()andcurrent_schema(), which is what an unqualified name gets resolved against.- How to create a schema, tables in it, and a volume beside them.
- What a volume is for, and how the same three-level name reaches files as well as rows.
The problem
A query that says select * from orders does not name a table. It names a table relative to
wherever the notebook happens to be standing, and two notebooks standing in different places read
two different tables from the same line of SQL. Nothing errors. The numbers are just wrong in one of
them.
Set up
Nothing to download. The starter finds out which catalog you are standing in, creates a schema
called brickster_namespace inside it, and builds two tables from spark.range: 4,096 orders over
64 regions, and a summary derived from them.
Creating a catalog usually needs an account admin, so the lab stays inside the catalog you already
have. If workspace is not the one you can create a schema in, change CATALOG in the setup cell.
Leave SCHEMA as it is, since one of the answers is that name.
Paste your salt into the first cell. One of the four answers is yours alone, so a notebook borrowed from somebody else fails that check and passes the rest.
The work
- Find out where you are.
current_catalog()andcurrent_schema(), then list the catalogs you can see. - Read a volume somebody else owns. The sample datasets are a volume in the
samplescatalog, reachable at/Volumes/samples/databricks/datasets. List it. - Make a schema and two tables. The starter does this. Count what the schema holds afterwards.
- Ask the table its own name.
describe detailreports it with all three levels on it. Print the middle level. - Make a volume and put two files in it. Then count what is in it.
- Answer for your own region. Your salt picks one of the 64.
Steps 3 to 6 are yours to write.
The questions
| key | what to print |
|---|---|
schema_tables |
tables in the schema you created |
table_schema |
the middle level of the name describe detail reports |
volume_files |
files in the volume you created |
bucket_total |
the total for the region your salt picks |
Notes
A volume path is a real path. /Volumes/<catalog>/<schema>/<name> works with dbutils.fs.ls,
dbutils.fs.put, and with ordinary Python file reads, which is what makes it the place to put a
file that is not a table.
show tables in <catalog>.<schema> gives back a DataFrame, so .count() on it counts the tables
rather than any rows inside them.
describe detail is Delta metadata, not table contents. Its name column is the fully qualified
name, and .split(".") gets you the level you want.
Documentation Databricks' own pages for what this lab uses. They are reference, not the answer.
- What are Unity Catalog volumes
What a volume is for and how its path is shaped.
- CREATE SCHEMA
The statement the starter runs, and what you need to be allowed to run it.
- CREATE VOLUME
Making the volume, including the managed and external forms.
- current_catalog function
What an unqualified table name is resolved against.
- DESCRIBE DETAIL
The metadata view the table's own name is read out of.
-
v12026-09-21 First release.
Re-run needed means an answer changed, so passes from before it have to be earned again. Every other release leaves them alone.