≈ The Lake

Part 7 · Catalogs and governance · Chapter 23

Unity Catalog: object model and architecture

Metastores, catalogs, schemas, tables, volumes, functions and models; managed vs external tables; storage credentials and external locations; and Unity Catalog as the commit authority for managed Delta tables, from the open-source server's code.

complete ~25 min

After this chapter you should be able to:
  • Navigate the three-level namespace and the securable hierarchy.
  • Predict the storage path of a managed table, and which external location owns an external table's path.
  • Describe how Unity Catalog acts as the commit authority for managed Delta tables, and how its Iceberg REST endpoint fits.

Chapters 14 and 21 treated the catalog as a protocol participant: the thing that ratifies Delta commits for a catalog-managed table, or swaps an Iceberg table’s metadata pointer. This chapter looks at one catalog from the inside. Unity Catalog is two things with one name: a service inside Databricks, and an open-source server under the LF AI and Data Foundation. Their documented models match, so the chapter follows the open-source server’s code at v0.7.0 for the algorithms and marks the Databricks-only behavior.

The simulator in src/sim/uc/uc.ts ports the managed-location resolution, the external-location rules and the path-ownership lookup from the server; its tests pin the paths and errors.

History

Databricks announced Unity Catalog at its Data + AI Summit on May 26, 2021, alongside Delta Live Tables.[Databricks press release, 2021-05-26] A gated public preview on AWS and Azure followed on April 20, 2022.[Databricks blog, 2022-04-20]

On June 12, 2024 Databricks announced it was open-sourcing Unity Catalog as an Apache 2.0 licensed server that also speaks the Iceberg REST catalog and Hive Metastore interfaces.[Databricks press release, 2024-06-12] The next day’s engineering post by Matei Zaharia, Ali Ghodsi, Reynold Xin and others described version 0.1, hosted at the LF AI and Data Foundation, with credential vending already in it.[Databricks blog: Open Sourcing Unity Catalog]

Object model

Every object is a securable, something that can be granted on. Tables are named catalog.schema.table; the metastore is the container above the catalogs. The server’s API enumerates the securable types: metastore, catalog, schema, table, function, volume, registered model, storage credential, external location and a few others.[api/all.yaml: SecurableType]

Where Unity Catalog places its objects
  1. Metastore Container for catalogs and storage securables.
Data namespace
  1. Catalog → schema Scopes a three-part name.
  2. Schema → data objects Tables, views, volumes, functions and models.
Storage access
  1. Storage credential Represents a cloud identity.
  2. External location Binds a storage URL to a credential.
A table name walks the namespace branch. An external location defines access to storage independently of the namespace.[Unity Catalog API]

Two properties of this tree matter for everything later. First, objects are identified by UUID, and names exist only in the catalog’s database. Second, the tree is also the authorization hierarchy: in the server, each create call grants OWNER to the creator and adds a parent-to-child edge, which is what lets a grant on a catalog reach the tables inside it.[AuthorizedService.initializeHierarchicalAuthorization] Chapter 24 is about that edge.

Quiz Check: the object modelAnswers are scheduled for spaced review on the Review page.

Q1. What are the three levels of a Unity Catalog table name, and what sits above them?

How sure are you?

Q2. Which securables hang directly off the metastore rather than off a schema? (select all that apply)

How sure are you?

Storage

A table is managed when the catalog owns its storage path, and external when the user names the path and the catalog only records it. The two kinds take different code paths.

Managed locations. CREATE CATALOG ... MANAGED LOCATION 's3://lake/sales' does not store the URL as given. The server turns a storage root into <root>/__unitystorage/catalogs/<catalog uuid> (or .../schemas/<schema uuid> for a schema).[Constants: MANAGED_STORAGE_PREFIX] When a managed table or volume is created, getManagedStorageLocation resolves its parent location in a fixed order:[ExternalLocationUtils.getManagedStorageLocation]

if (schemaInfoDAO.getStorageLocation() != null) {
  return NormalizedURL.from(schemaInfoDAO.getStorageLocation());
} else if (catalogInfoDAO.getStorageLocation() != null) {
  return NormalizedURL.from(catalogInfoDAO.getStorageLocation());
} else {
  return fallbackStorageRoot.get()
      .map(fallback -> NormalizedURL.from(fallback + "/" + Constants.MANAGED_STORAGE_PREFIX))
      .orElseThrow(() -> new BaseException(ErrorCode.FAILED_PRECONDITION,
          "None of catalog, schema or storage-root.tables server property has managed location configured."));
}

The table’s directory is then <parent>/tables/<table uuid> (volumes use volumes/, models models/).[ManagedResourceType] So a table in a schema without a location, in the catalog above, lands at

s3://lake/sales/__unitystorage/catalogs/<catalog uuid>/tables/<table uuid>

Because the path contains only UUIDs, a rename is a catalog update, and a table dropped and recreated under the same name gets a new directory. The __unitystorage segment is reserved: validateNotSameOrUnderManagedStoragePrefix rejects an external location or storage root whose URL contains it, so no user-named path can reach into managed storage.[validateNotSameOrUnderManagedStoragePrefix]

Storage credentials and external locations. An external location pairs a URL prefix with a storage credential. The server refuses to create one whose URL equals, contains or sits inside another location’s URL, so locations never nest and every path is inside at most one of them.[validateUrlNotUsedByAnyExternalLocation]

Who owns a path. When a request names a storage path, for example CREATE TABLE ... LOCATION, the authorization layer maps the path to the securable that owns it with getMapResourceIdsForPath:[ExternalLocationUtils.getMapResourceIdsForPath]

  1. If any external location or data securable (table, volume, registered model) lies strictly below the path, fail with PERMISSION_DENIED: a new table may not swallow existing ones.
  2. If the path is at or below exactly one data securable, that securable owns it.
  3. Else, if it is at or below exactly one external location, that location owns it.
  4. Else nothing owns it.

The decorator then sets no_overlap_with_data_securable to whether step 2 found nothing, and chapter 24’s CREATE_TABLE expression requires it for an external table, along with CREATE EXTERNAL TABLE on the owning location if there is one.[UnityAccessDecorator] Two tables therefore never share files, and access to a path is governed by exactly one object.

Quiz Check: storageAnswers are scheduled for spaced review on the Review page.

Q1. A catalog was created with a managed location and its schema without one. Where does the OSS server put a new managed table?

How sure are you?

Q2. Why do managed table paths use the table id rather than its name?

How sure are you?

Q3. What does the server do with an external location URL that contains __unitystorage?

How sure are you?

Q4. External location raw covers s3://lake/raw. Can you create raw_eu at s3://lake/raw/eu?

How sure are you?

Q5. You CREATE TABLE ... LOCATION 's3://lake/raw', and an existing table lives at s3://lake/raw/clicks. What happens?

How sure are you?

Unity Catalog as catalog of record

For a managed Delta table, Unity Catalog is more than a name registry. It implements Delta’s catalog-managed tables (chapter 14): the catalog ratifies each commit, and a version exists only once the catalog has accepted it.[PROTOCOL.md: Catalog-managed tables] The server’s managed Delta tables spec defines the API under /api/2.1/unity-catalog/delta/v1. The flow, in order:[ManagedDeltaTablesSpec: APIs]

  1. createStagingTable. The server allocates a table UUID and a location by the rule above, and returns the required and suggested protocol and properties plus short-lived credentials for the location.[StagingTableRepository.createStagingTable]
  2. Write 0.json. The client writes the first commit into _delta_log at that location, with every required feature and property.
  3. createTable. The server checks that the caller created the staging table and that the declared protocol and properties match the contract, including io.unitycatalog.tableId, then registers the table at version 0. A staging table can be finalized once.
  4. loadTable. Returns the metadata, an etag, latest-table-version, and every ratified commit not yet published. A reader unions those with the published _delta_log files; if a version appears in both, the catalog’s entry wins, and anything past latest-table-version is ignored.
  5. updateTable with add-commit. A writer writes a staged commit file, then proposes it. The server accepts only version = last ratified + 1, which is the mutual exclusion that chapter 10’s put-if-absent provides for path-based tables. The request carries assert-table-uuid and may carry assert-etag.
  6. Publish, then set-latest-backfilled-version. The writer copies ratified commits into _delta_log in order and tells the server, which may then drop its copies.

The spec’s reference list of required features is catalogManaged, inCommitTimestamp, vacuumProtocolCheck, v2Checkpoint and deletionVectors, with column mapping, domain metadata and row tracking recommended; the authoritative set is whatever createStagingTable returns.[ManagedDeltaTablesSpec: table features] Maintenance is also the catalog’s to allow: loadTable lists the permitted operations, and the server permits data reorganization, data cleanup and metadata cleanup for managed tables.

Iceberg REST. The same server mounts the Iceberg REST catalog API (chapter 21) at /api/2.1/unity-catalog/iceberg.[ArmeriaServerBuilder.ICEBERG_RELATIVE_PATH] An Iceberg namespace is a UC schema, and loadTable is guarded by the same GET_TABLE expression as the UC REST and Delta APIs, then returns the table metadata and a config that tells the client where to get credentials.[IcebergRestCatalogService.loadTable] One set of grants governs a table whichever protocol a client speaks, which is the point of the next chapter.

Quiz Check: catalog of recordAnswers are scheduled for spaced review on the Review page.

Q1. In the managed Delta tables protocol, who chooses the location of a new managed table, and when?

How sure are you?

Q2. A reader lists _delta_log and also gets commits from loadTable. A version appears in both. Which wins?

How sure are you?

Q3. Which table features does the managed-table spec list as required? (select all that apply)

How sure are you?

Q4. An Iceberg client calls loadTable against the OSS server's Iceberg REST endpoint. Which authorization expression guards it?

How sure are you?

Try it

  • Managed location: set only the catalog root and read the table path. Then set a schema root and watch the schema win; clear both and set the server root to see the fallback; clear everything for FAILED_PRECONDITION.
  • External table path: pick s3://lake/raw/clicks/2024 (inside an existing table, so the overlap flag fails), s3://lake/raw (the parent of a table, refused outright) and s3://other/t (owned by nothing). Then try to create raw_eu inside raw.
  • Securables: click through the tree.

The catalog has id 3f1c, the schema 9ab2. A storage root becomes <root>/__unitystorage/catalogs/<id> or .../schemas/<id> when the object is created.

getManagedStorageLocation triesvalue
1. schema storage locationnot setskip
2. catalog storage locations3://lake/sales/__unitystorage/catalogs/3f1cused
3. server storage-root.tables + /__unitystoragenot setnot reached

A new managed table with id 7d40 goes to s3://lake/sales/__unitystorage/catalogs/3f1c/tables/7d40, and a managed volume to s3://lake/sales/__unitystorage/catalogs/3f1c/volumes/v1.

Summary

  • Names are catalog.schema.object under a metastore; every object is a securable, identified by UUID, and the create call adds it to the ownership and inheritance tree.
  • A managed table’s path is <schema or catalog or server location>/tables/<uuid>, under a reserved __unitystorage prefix that user paths cannot enter.
  • External locations never nest. A storage path is owned by the one table, volume or model containing it, else by the one external location containing it; a path above an existing entity is refused.
  • For managed Delta tables, the server allocates the location in createStagingTable, ratifies commits in updateTable at exactly last + 1, and is authoritative over _delta_log until commits are backfilled. The Iceberg REST endpoint shares the same authorization.

Concepts in this chapter

Explained here

See how the book's concepts connect →

Primary sources

Review this chapter

This chapter has 11 quiz questions.

Review this chapter's cards → Review all due cards