Skip to content

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.

Nobody has passed this one yet.

What you will learn

  • What the three parts of catalog.schema.table actually are, and which one you usually create.
  • current_catalog() and current_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.

a bare name orders ? one query, two different tables catalog schema table volume workspace.brickster_namespace.orders

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

  1. Find out where you are. current_catalog() and current_schema(), then list the catalogs you can see.
  2. Read a volume somebody else owns. The sample datasets are a volume in the samples catalog, reachable at /Volumes/samples/databricks/datasets. List it.
  3. Make a schema and two tables. The starter does this. Count what the schema holds afterwards.
  4. Ask the table its own name. describe detail reports it with all three levels on it. Print the middle level.
  5. Make a volume and put two files in it. Then count what is in it.
  6. 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.

We measure how the site is used. PostHog and Google Analytics, set to measurement only with advertising features off. We do not sell your data or share it for advertising, and you can turn this off. What this stores.