Create the Table

A namespace, then a table

run(ctx, spark, "CREATE NAMESPACE IF NOT EXISTS hms.db")

run(ctx, spark, `
CREATE TABLE hms.db.orders (
    order_id    BIGINT,
    customer_id BIGINT,
    order_ts    TIMESTAMP,
    amount      DECIMAL(10,2),
    status      STRING,
    country     STRING
)
USING iceberg
PARTITIONED BY (days(order_ts))
`)

That first statement is the one piece of setup a metastore-backed catalog needs and a filesystem-backed one does not. A namespace in HMS is a row in the DBS table, and a row has to exist before a table can reference it — CREATE TABLE hms.db.orders against a missing db fails with NoSuchNamespaceException. (the Lab: the filesystem catalog part's filesystem catalog invents the namespace the moment you name one, because there a namespace is just a subdirectory.) It is also the statement that makes HMS mkdir the database directory — if it fails with a MetaException naming your warehouse path, that's the permission case the Bring up Postgres and the Hive Metastore section warned about.

What those two statements actually do, move by move. The Where each process runs, and one INSERT end to end trace followed an INSERT; this is the same machinery on an empty table, and it is worth walking once because CREATE TABLE is the only commit in the lab with no previous pointer to compare against. Nothing below is inferred — every step lands in a place you can look at with find or psql.

  1. CREATE NAMESPACE → one thrift call, and Iceberg is not involved at all. Spark routes it to HiveCatalog.createNamespace, which sends create_database("db") with no location set, leaving HMS to pick its default: the warehouse root plus the database name plus .db. No metadata.json is written, because a namespace has no Iceberg-format representation — it exists only in the catalog.
  2. HMS does its one and only filesystem write.mkdir warehouse/db.db/, as the hive user, through the bind mount — the mkdir the Bring up Postgres and the Hive Metastore box exists for. Then INSERT INTO "DBS": name, DB_LOCATION_URI, owner. Postgres commits, and the namespace exists. From here to the end of the lab HMS never touches a file again.
  3. CREATE TABLE → Spark builds the Iceberg objects in memory first. A Schema of six fields carrying field IDs 1–6, and a PartitionSpec holding one field — a day transform over source ID 3, named order_ts_day, given partition-field ID 1000. Those IDs, not the column names, are what every later file references, which is the whole basis of schema evolution. This is also where TIMESTAMP becomes timestamptz — the Read metadata.json straight, in Go section unpacks why.
  4. Resolve the location, then write the file — before telling anyone. The table location is DBS.DB_LOCATION_URI + /orders (unless you passed LOCATION). Spark writes metadata/00000-<uuid>.metadata.json straight to the host filesystem: format version, table UUID, location, the schema, the partition spec, the sort order, "current-snapshot-id": -1 and an empty "snapshots": []. At this instant the file exists and nothing knows about it — if the next step failed, this would be an orphan, which is exactly the failure mode see Lab: two writers, one table and Lab: compaction and cleanup's orphan-file cleanup are about.
  5. One create_table thrift call registers it, and Postgres writes four kinds of row in one transaction. A TBLS row (the table's identity and owner), an SDS row (its location and Hive's storage-descriptor boilerplate), a set of COLUMNS_V2 rows (the six columns again, translated into Hive's type system), and a set of TABLE_PARAMS rows — among them the one that matters. That commit is the table's creation instant; before it there was a file, after it there is a table.

The last of those rows is the interesting one, because Iceberg writes considerably more into TABLE_PARAMS than the pointer alone:

PARAM_KEYValue after CREATE TABLEWhat it is for
metadata_location…/00000-<uuid>.metadata.jsonThe pointer. The one authoritative fact in this table
previous_metadata_locationabsentAppears from the first commit onward; the CAS "expected" value
table_typeICEBERGTells any Hive-aware engine to ignore the rest of this row and go read the file
current-schemathe same six columns, as Iceberg JSONConvenience copy
default-partition-specthe same days(order_ts) rule, as JSONConvenience copy
snapshot-count0Convenience copy — no snapshot exists yet
uuidthe table UUIDConvenience copy

What landed on disk

Run it (go run main.go — same command for the rest of this lab, only main.go changes), then look at what showed up before a single row of data exists:

bash

$ find warehouse/db.db/orders -type f -not -name '.*'
warehouse/db.db/orders/metadata/00000-2f8a1c6d-....metadata.json

One file. No data/ directory, because no snapshot has ever been committed — CREATE TABLE is pure metadata, the same fact the main guide's Iceberg's metadata tree makes about DDL: schema and partition-spec changes bump metadata.json without touching snapshots at all.

And no pointer file either. Nothing in this directory says which metadata.json is current, and the name is not v1 — BaseMetastoreTableOperations writes <seq>-<uuid>.metadata.json, a name deliberately unguessable. That matters more than it looks: two writers racing to commit each write a private file and can never collide on a filename, which is the precondition for the compare-and-swap in the Lab: two writers, one table part.

The pointer, as a database row

So where is the pointer? In Postgres, one psql away:

bash — the pointer, in the metastore's own database

$ docker compose exec -T postgres psql -U hive -d metastore_db <<'SQL'
SELECT p."PARAM_KEY", right(p."PARAM_VALUE", 46) AS tail
FROM "TBLS" t
JOIN "TABLE_PARAMS" p ON p."TBL_ID" = t."TBL_ID"
WHERE t."TBL_NAME" = 'orders'
  AND p."PARAM_KEY" IN ('table_type','metadata_location','previous_metadata_location');
SQL

You get table_type = ICEBERG — how any Hive-aware engine knows not to read this as a Hive table — and metadata_location, holding the exact path find just printed. There is no previous_metadata_location yet; nothing has superseded anything.

Keep that query handy. Run it again after each of the Lab: write data part's three inserts and metadata_location will have advanced while the old value slides into previous_metadata_location. That single UPDATE is the commit. Every snapshot, manifest list, and Parquet file is already durably on disk before this row changes; flipping this one string is the instant the new data becomes visible to every reader, and it is the only step in the whole commit that has to be atomic. That is the entire job of a catalog, and watching it is normally impossible — here it's a SELECT.