如何在 GCP 上读取 Unity Catalog Iceberg 表

读写操作用 REST API。只读可移植性用 Hive 注册,并在每次 Databricks 加载后刷新。
Unity Catalog 托管的 Iceberg 表就是标准的 Apache Iceberg 元数据和 Parquet 文件,存放在你自己在 Google Cloud Platform(GCP)上的 Google Cloud Storage(GCS)存储桶中。GCP Dataproc 上的开源 Apache Spark 无需任何 Databricks 库,即可通过 Iceberg REST API 读写这些表;同样的文件也可以注册到任何其他 Iceberg 目录(例如 Hive metastore),以实现可移植的只读访问。本演练在一个普通 Dataproc 集群上,借助可直接运行的脚本,端到端演示这两条路径。
本演练拿一张现有的、由 Unity Catalog 托管的 Iceberg 表,在 Dataproc 上用纯开源的 Apache Spark™ 操作它,集群上不安装任何 Databricks 专有组件,具体有两种方式:
通过 Iceberg REST API。Unity Catalog 实现了开放的 Apache Iceberg™ REST Catalog 规范。Dataproc 上的 Spark 连接它,就像连接任何其他 Iceberg REST 目录一样,读取该表、新建一张表并写入数据行,Databricks 会立即看到这些数据。
把同一张表注册到 Hive 目录。该表的 metadata.json 就在你自己的 GCS 存储桶中。使用 Iceberg 标准的 register_table 过程,把该文件注册到 Dataproc Hive metastore,并通过 Spark 的 Hive 目录进行查询,从而证明数据可以迁移到任何支持 Iceberg 的目录。展示这第二条路径只是为了证明可移植性;在生产环境中,每张表应只归属于一个目录。
文中还逐一说明了每条路径各自的适用场景,以及 Hive 路径的一种行为——在你依赖它之前,这一点值得先弄清楚。每一步的完整可运行脚本都在这个 GitHub 仓库中。
是什么让 Unity Catalog 的 Iceberg 表既开放又可移植?
有三层机制共同实现了这一点,而且没有一层是专有的。
开放格式。在 Unity Catalog 中,托管 Iceberg 表通过 USING ICEBERG 创建,并以 Apache Iceberg 元数据(metadata.json、manifest 列表、manifest)加上 Parquet 数据文件的形式存储。这些文件存放在你自己 Google Cloud 项目中的 GCS 存储桶里,位于目录或 schema 的托管存储位置之下。这些文件中没有任何内容需要依赖 Databricks 才能读取。
开放目录 API。Unity Catalog 通过其在 /api/2.1/unity-catalog/iceberg-rest 上对 Iceberg REST Catalog 规范的实现来对外提供这些表。任何基于该规范构建的客户端,包括 Spark、Trino、Flink、PyIceberg、Snowflake 和 Dremio,都使用相同的 type=rest、uri、warehouse 和 token 配置。本文后面的 Spark 配置不含任何 Databricks jar,也没有任何 Databricks 专有属性。只要更改 uri 和 warehouse,同一个 Dataproc 作业就能指向另一个 Iceberg REST 目录。
开放凭证分发。当 Spark 加载表时,Unity Catalog 会检查调用者的权限,并遵循标准的 Iceberg REST 访问委派流程,返回一个限定到该表位置的短期 GCS 凭证。Dataproc 集群无需持有 Unity Catalog 存储桶的密钥,Dataproc 服务账号也无需访问该存储桶。治理始终集中在一处。
如何为外部 Iceberg 访问设置 Unity Catalog?
本演练假设你已有一张由 Unity Catalog 管理的 Iceberg 表,即 uc_iceberg_demo.sales.orders。如果你还没有,请先在 Databricks 中创建它(用 SQL 编辑器或 notebook 均可):
然后完成三项一次性的前置准备,由 metastore 管理员或表的所有者执行。
首先,在 metastore 上启用外部数据访问。在工作区中,该设置位于 Catalog、Metastore details、External data access 之下。
其次,选定 Dataproc 将要使用的身份,并为其创建凭证。本演练使用个人访问令牌(PAT),因为这是最快跑通会话的方式。生产环境中应使用配合 OAuth 的服务主体(service principal)。关于这一点,“经验教训”部分另有说明。
第三,授予相应权限。EXTERNAL USE SCHEMA 这一权限允许 Unity Catalog 向外部引擎下发存储凭证。
如果 Dataproc 要写入或创建表,还需在 schema 上加上 MODIFY 和 CREATE TABLE 权限。
如何为 Iceberg 创建 Dataproc 集群?
使用 Dataproc 镜像 2.3 的单节点集群就足够了。截至 2026 年 11 月,镜像 2.3 搭载的是运行在 Scala 2.12 上的 Spark 3.5,而这两个版本决定了你需要哪个 Iceberg 运行时构件。
该集群没有外部 IP,因此需要一条出网路径(例如 Cloud NAT),才能访问 Maven Central 获取 Iceberg jar 包,以及访问你的 Databricks 工作区 URL。一小时的空闲超时会自动将其销毁。
只需导出一次工作区 URL 和 Token,后续命令即可复用它们。
开源 Spark 如何连接到 Iceberg REST API?
这就是全部配置。每个属性都是标准的 Apache Iceberg REST 目录属性。
iceberg-spark-runtime-3.5_2.12 和 iceberg-gcp-bundle 是来自 Maven Central 的 Apache Iceberg 官方构件。在撰写本文时(2026 年 11 月),1.10.0 是最新的稳定版本。runtime 必须与镜像上的 Spark 和 Scala 版本匹配,且两个构件必须是同一个 Iceberg 版本。GCP bundle 提供 GCSFileIO;缺少它时,Spark 能连上目录但无法打开 GCS 中的文件,报出的错误是类未找到(class-not-found),而不是权限错误。
type=rest 和 uri 将标准 Iceberg REST 客户端指向 Unity Catalog。要把它指向任何其他 Iceberg REST 目录,只需改动一行。
warehouse 是 Unity Catalog 的目录名称。Spark 中的别名 uc 可以任意命名,因此 Spark 里的 uc.sales.orders 对应 Databricks 中的 uc_iceberg_demo.sales.orders。
这里没有任何 GCS 凭据。Unity Catalog 会按表发放凭据。
Dataproc 能否读写 Unity Catalog 的 Iceberg 表?
读取一张已有的表只需提交一个作业。
从 Dataproc 创建并写入一张新表也是同样的方式。
最终出现在 Databricks 中的,是一张普通的 Unity Catalog 托管 Iceberg 表。它会显示在 Catalog Explorer 中,可以立即在 SQL 仓库中以 uc_iceberg_demo.sales.my_orders 进行查询,Unity Catalog 的权限、血缘和审计也都对它生效。没有任何标记表明它是“从外部创建的”。提交是通过 REST API 完成的,因此 Unity Catalog 指向当前 metadata.json 的指针发生了移动,两个引擎对表状态的认识保持一致。
如何在 Hive 中注册一张 Unity Catalog 的 Iceberg 表?
接下来是可移植性演示。REST API 并不是访问这些文件的唯一途径。由于这张表就是你自己的存储桶中的标准 Iceberg 表,任何 Iceberg 目录都可以取其当前的 metadata.json 并完成注册。本示例使用的是 Dataproc 自带的 Hive metastore,许多已有基于 Hive 的 Spark 工具链的团队本来就在用它。
注意:仅用于演示。这一步把一张仍由 Unity Catalog 管理的表注册到第二个目录中,纯粹是为了说明这些文件是可移植的。在生产环境中,一张表应当只属于一个目录:Apache Iceberg 的 register_table 文档警告说,把同一个 metadata.json 注册到多个目录中可能导致更新丢失、数据丢失以及表损坏。请把下面的注册视为临时的只读视图,不要通过它写入。若确实要把一张表迁移到另一个目录,应先从 Unity Catalog 中注销它,再在目标目录中注册(UNREGISTER → REGISTER),从而确保始终只有一个目录拥有它。截至 2026 年 11 月,UNREGISTER 处于 Private Preview 阶段。
为基于 Hive 的 Iceberg catalog 设置第二个 properties 文件。只需要 Iceberg runtime jar。在这条路径上没有凭证分发,因此 Dataproc 服务账号需要自己对存放该表的 bucket 具有读取权限。
找到表的当前元数据文件。标准的 Iceberg REST loadTable 响应会在 metadata-location 中携带该位置,因此一次 curl 调用就足够了。你也可以在 GCS 中列出该表的元数据文件夹。
创建一个 Hive 命名空间,注册该文件,并通过 Hive catalog 查询该表。
计数与 Databricks 一致。GCS 中的相同字节现在对两个独立的 catalog 可见,其中一个从未听说过 Databricks。
为什么通过 Hive 注册的 Iceberg 表会变得陈旧?
一次注册会指向一个特定的 metadata.json。每次 Databricks 写入(INSERT、MERGE、UPDATE、DELETE 以及诸如 OPTIMIZE 之类的维护操作)都会在 Unity Catalog 中提交一个新的元数据文件,但 Hive 条目仍指向旧文件。从那一刻起,两个 catalog 对该表的认知就不一致了,而且没有任何机制会自动让它们重新同步。要获取新数据,需要获取新位置并重新注册。
在 Databricks 中插入,例如从 SQL 编辑器执行。
确认 Hive 侧仍显示旧计数,然后获取新的元数据位置。文件名现在以更高的序列号结尾。
在不执行 PURGE 的情况下删除该注册,然后注册新文件。随后验证计数包含新增行,并且快照历史显示 Databricks 提交。
原文较长,译文为节选;译文由英文原文机器翻译,术语按行业惯例统一,可在文末展开原文核对。
查看英文原文(How to read Unity Catalog Iceberg tables on GCP)
Use the REST API for reads and writes. Use Hive registration for read-only portability and refresh it after each Databricks load.
Unity Catalog managed Iceberg tables are standard Apache Iceberg metadata and Parquet files stored in your own Google Cloud Storage (GCS) bucket on Google Cloud Platform (GCP). Open source Apache Spark on GCP Dataproc can read and write them through the Iceberg REST API with no Databricks libraries, and the same files can be registered into any other Iceberg catalog, such as a Hive metastore, for portable read-only access. This walkthrough demonstrates both paths end to end, with runnable scripts, on a plain Dataproc cluster.
This walkthrough takes an existing Unity Catalog-managed Iceberg table and works with it from plain open source Apache Spark™ on Dataproc, with nothing Databricks-specific installed on the cluster, in two ways:
Through the Iceberg REST API. Unity Catalog implements the open Apache Iceberg™ REST Catalog specification. Spark on Dataproc connects to it exactly as it would to any other Iceberg REST catalog, reads the table, creates a new one and writes rows that Databricks sees immediately.
By registering the same table in a Hive catalog. The table's metadata.json lives in your own GCS bucket. The file is registered in the Dataproc Hive metastore with Iceberg's standard register_table procedure and queried through Spark's Hive catalog, demonstrating that the data is portable to any Iceberg-capable catalog. This second path is shown only to demonstrate portability; in production, keep each table owned by a single catalog.
Along the way, the blog notes where each path fits, and one behaviour of the Hive path that is worth understanding before you rely on it. The complete, runnable scripts for every step are in this GitHub repository.
What makes Unity Catalog Iceberg tables open and portable?
Three layers make this work, and none of them is proprietary.
Open format. A managed Iceberg table in Unity Catalog is created with USING ICEBERG and stored as Apache Iceberg metadata (metadata.json, manifest lists, manifests) plus Parquet data files. They sit in a GCS bucket in your own Google Cloud project, under the catalog or schema's managed storage location. Nothing in those files requires Databricks to read them.
Open catalog API. Unity Catalog exposes the tables through its implementation of the Iceberg REST Catalog spec at /api/2.1/unity-catalog/iceberg-rest. Any client built against that spec, including Spark, Trino, Flink, PyIceberg, Snowflake and Dremio, uses the same type=rest, uri, warehouse and token settings. The Spark configuration later in this blog contains no Databricks jar and no Databricks-specific property. Change the uri and warehouse and the same Dataproc job targets a different Iceberg REST catalog.
Open credential vending. When Spark loads a table, Unity Catalog checks the caller's privileges and returns a short-lived GCS credential scoped to that table's location, following the standard Iceberg REST access-delegation flow. The Dataproc cluster needs no keys for the Unity Catalog bucket, and the Dataproc service account needs no access to it. Governance stays in one place.

How do you set up Unity Catalog for external Iceberg access?
This walkthrough assumes a Unity Catalog managed Iceberg table, uc_iceberg_demo.sales.orders. If you don't have one, create it in Databricks (SQL editor or notebook) first:
Then complete three one-time prerequisites, performed by a metastore admin or the table owner.
First, enable external data access on the metastore. In the workspace this is under Catalog, Metastore details, External data access.
Second, pick the identity Dataproc will use and create a credential for it. This walkthrough uses a personal access token (PAT) because it is the fastest route to a working session. For production, use a service principal with OAuth. There is a note on that under lessons learned.
Third, grant the privileges. EXTERNAL USE SCHEMA is the one that permits Unity Catalog to vend storage credentials to an external engine.
Add MODIFY and CREATE TABLE on the schema if Dataproc will write or create tables.
How do you create a Dataproc cluster for Iceberg?
A single-node cluster on Dataproc image 2.3 is enough. Image 2.3 ships Spark 3.5 on Scala 2.12 as of November 2026, and those two versions decide which Iceberg runtime artifact you need.
The cluster has no external IP, so it needs an egress path such as Cloud NAT to reach Maven Central for the Iceberg jars and your Databricks workspace URL. The one-hour idle timeout tears it down automatically.
Export the workspace URL and token once so the later commands can reuse them.
How does open source Spark connect to the Iceberg REST API?
This is the entire configuration. Every property is a standard Apache Iceberg REST catalog property.
iceberg-spark-runtime-3.5_2.12 and iceberg-gcp-bundle are the stock Apache Iceberg artifacts from Maven Central. Version 1.10.0 was the latest stable release at the time of writing (November 2026). The runtime must match the Spark and Scala versions on the image, and both artifacts must be the same Iceberg version. The GCP bundle provides GCSFileIO; without it Spark reaches the catalog but cannot open files in GCS, and the error is a class-not-found rather than a permission error.
type=rest and uri point the standard Iceberg REST client at Unity Catalog. Pointing it at any other Iceberg REST catalog is a one-line change.
warehouse is the Unity Catalog catalog name. The Spark alias uc is arbitrary, so uc.sales.orders in Spark is uc_iceberg_demo.sales.orders in Databricks.
There are no GCS credentials. Unity Catalog vends them per table.
Can Dataproc read and write Unity Catalog Iceberg tables?
Reading an existing table is one job submission.
Creating and populating a new table from Dataproc works the same way.
The table that appears in Databricks is an ordinary Unity Catalog managed Iceberg table. It shows up in Catalog Explorer, it is queryable as uc_iceberg_demo.sales.my_orders from a SQL warehouse straight away, and Unity Catalog privileges, lineage and audit apply to it. Nothing marks it as "created externally". The commit went through the REST API, so Unity Catalog's pointer to the current metadata.json moved, and both engines agree on the table state.
How do you register a Unity Catalog Iceberg table in Hive?
Now the portability demonstration. The REST API is not the only way to reach these files. Because the table is standard Iceberg in your own bucket, any Iceberg catalog can take its current metadata.json and register it. This example uses the Hive metastore that ships with Dataproc, which is what many teams with existing Hive-based Spark tooling already run.
Note: for demonstration only. This step registers a table that Unity Catalog still manages in a second catalog, purely to show that the files are portable. In production, a table should have exactly one owning catalog: Apache Iceberg's register_table documentation warns that registering the same metadata.json in more than one catalog can lead to missing updates, data loss and table corruption. Treat the registration below as a temporary, read-only view, and don't write through it. To actually move a table to another catalog, unregister it from Unity Catalog first and then register it in the destination (UNREGISTER → REGISTER), so only one catalog ever owns it. UNREGISTER is in Private Preview as of November 2026.
Set up a second properties file for a Hive-backed Iceberg catalog. Only the Iceberg runtime jar is needed. On this path there is no credential vending, so the Dataproc service account needs its own read access to the bucket that holds the table.
Find the table's current metadata file. The standard Iceberg REST loadTable response carries it in metadata-location, so one curl call is enough. You could equally list the table's metadata folder in GCS.
Create a Hive namespace, register the file, and query the table through the Hive catalog.
The count matches Databricks. The same bytes in GCS are now visible to two independent catalogs, one of which has never heard of Databricks.
Why does a Hive-registered Iceberg table go stale?
A registration points at one specific metadata.json. Every Databricks write (INSERT, MERGE, UPDATE, DELETE and maintenance such as OPTIMIZE) commits a new metadata file in Unity Catalog, but the Hive entry keeps pointing at the old one. From that moment the two catalogs disagree about the table, and nothing brings them back in step automatically. To pick up new data, fetch the new location and re-register.
Insert in Databricks, for example from the SQL editor.
Confirm the Hive side still shows the old count, then fetch the new metadata location. The file name now ends in a higher sequence number.
Drop the registration without PURGE and register the new file. Then verify that the count includes the new rows and the snapshot history shows the Databricks commit.
In production, make the fetch and re-register the last task of the Databricks job that loads the table, or run it on a schedule. Between refreshes, Dataproc reads the last registered version.
DROP TABLE without PURGE removes only the Hive metastore entry; the files in GCS are untouched and the table can be registered again at any time. DROP TABLE ... PURGE would delete the data files, and those belong to the Databricks table. Never use PURGE on a registered Unity Catalog table.
Run this on Dataproc against the Hive catalog. In Databricks, DROP TABLE on a Unity Catalog managed table drops the table itself, which would remove the source table this registration points to.
What this costs in practice: stale reads between refreshes, with no warning to Dataproc users; a refresh job that must run after every load and fails silently if skipped; and fragility, since a write through the registration diverges from Databricks. The REST API path removes the problem, because Spark asks Unity Catalog for the current metadata on every query.
What happens if you write through a Hive-registered table?
A common question is whether you can write through the registered table. An INSERT through the Hive-registered table succeeds and the Hive catalog returns the new row. Databricks does not. This is standard Iceberg behaviour, not a Unity Catalog quirk: the Hive commit writes a new metadata.json and moves the Hive metastore pointer, and Unity Catalog's pointer, which is the only one Databricks consults, is unaware of it. The two catalogs now hold diverging histories of the same table, the split-brain scenario described in “Unlocking Data Portability: Preventing Catalog Lock-in with REGISTER and UNREGISTER APIs”. The Apache Iceberg documentation for register_table warns about exactly this, which is why Step 5 treats the registration as a read-only demo.
So the two paths have different jobs. The REST API path is a shared catalog: every commit, from Databricks or from Dataproc, moves the same pointer, and that is why writes through it are safe. The Hive registration is a portable read-only view of a point in time. Use it for reads from Hive-based tooling, refresh it as shown above, and send writes through the REST API or Databricks.
When should you use the REST API vs. Hive registration?
Iceberg REST API (Unity Catalog)
Hive catalog registration
Open catalog API: standard REST client, no Databricks libraries
Open format: standard Iceberg files usable by any catalog
Yes, as of the registered metadata.json
Yes, visible in Databricks immediately
Not recommended; forks the table history
Storage credentials on Dataproc
None, vended per table by Unity Catalog
Service account needs read access to the bucket
Unity Catalog governance
Only at registration time
Refresh after Databricks writes
Fetch new metadata.json and re-register
Any read or write workload
Short-lived, read-only demos of portability; for a real move, use UNREGISTER → REGISTER
What are the common pitfalls with Iceberg on GCP Dataproc?
The configuration is standard Apache Iceberg. The Dataproc side needs no Databricks-specific libraries or settings. The REST catalog properties are documented by Apache Iceberg, and the Hive registration uses Iceberg's standard register_table procedure.
Match jar versions to the Dataproc image. Classpath mismatches often look like connectivity or permission errors. Check the Spark and Scala versions on the image and use the matching iceberg-spark-runtime artifact.
Use a service principal for anything scheduled. PATs are convenient for a walkthrough but are legacy for production. The Iceberg REST client supports OAuth client credentials directly: replace token with rest.auth.type=oauth2, oauth2-server-uri, credential and scope=all-apis.
Know the external-write limitations on the REST path. As of this writing, external clients cannot run table maintenance such as snapshot expiry or orphan file removal. On Iceberg v3 tables, row-level changes from external engines must use copy-on-write or deletion vectors.
Unity Catalog managed Iceberg tables are open at every layer that matters: open files in your own bucket, an open catalog API, and standard credential vending. Plain open source Spark on Google Cloud Dataproc read and wrote them through the Iceberg REST API with a generic configuration, and the same files were registered into a Hive catalog with no Databricks involvement. The practical rule that falls out is simple: use the shared REST API for anything that writes, and treat a registration in another catalog as a portable read-only view you refresh on your own schedule.
Ready to try it on your own tables?
Start with the Databricks documentation on accessing tables from Apache Iceberg clients and the overview of Apache Iceberg in Databricks. If you are evaluating Iceberg v3 features such as deletion vectors and row lineage, see Iceberg v3 on Databricks. For the same openness story from other engines, see the Community blogs on Apache Spark via Open APIs and Trino via Open APIs. The complete code for this walkthrough is in the companion GitHub repository.
Are Unity Catalog managed Iceberg tables locked to Databricks?
No, Unity Catalog managed Iceberg tables are not locked to Databricks. They are standard Apache Iceberg metadata and Parquet files stored in a GCS bucket in your own Google Cloud project. Any client that implements the open Iceberg REST Catalog spec can read and write them, and the same files can be registered into another Iceberg catalog, such as a Hive metastore, with Iceberg's standard register_table procedure.
Does open source Spark on Dataproc need any Databricks libraries to use Unity Catalog?
No, open source Spark on Dataproc does not need any Databricks libraries to query Unity Catalog Iceberg tables. The configuration uses only the Apache Iceberg Spark runtime and the Iceberg GCP bundle from Maven Central, with the standard type=rest, uri, warehouse and token properties. Changing the uri and warehouse points the same job at a different Iceberg REST catalog.
Does Dataproc need credentials for the Google Cloud Storage bucket behind the table?
On the REST API path, Dataproc does not need any GCS credentials for the table's bucket. Unity Catalog vends short-lived, table-scoped GCS credentials to the Iceberg client on each table load, provided the identity has EXTERNAL USE SCHEMA on the schema. The Hive registration path has no credential vending, so there the Dataproc service account needs its own read access to the bucket.
Why does Databricks not see rows written through a Hive metastore registered table?
Because the Hive commit moves only the Hive metastore's pointer to a new metadata.json. Unity Catalog keeps its own pointer and was never told about the commit, so Databricks continues reading the previous version. Send writes through the REST API, where every commit moves the shared Unity Catalog pointer, and treat the Hive registration as read-only.
How do I see new Databricks data in a Hive metastore registered table?
Fetch the latest metadata-location from the REST loadTable endpoint, drop the registered table without PURGE, and call register_table again with the new file. Automate this as the final step of the Databricks job that loads the table.
Related Databricks Blogs
Related Community Technical Blogs (same series of external-engine walkthroughs):
Get the latest posts in your inbox
原文为英文,正文由自动抓取并保留原文。
原文发布于 Databricks Blog(How to read Unity Catalog Iceberg tables on GCP),标题、摘要与正文由机器翻译,术语按行业惯例统一,未经人工逐句校订。