kevinjqliu commented on code in PR #17940: URL: https://github.com/apache/iceberg/pull/17940#discussion_r3961153312
########## docs/docs/rest-protocol.md: ########## @@ -0,0 +1,180 @@ +--- +title: "REST Catalog Protocol" +--- +<!-- + - Licensed to the Apache Software Foundation (ASF) under one or more + - contributor license agreements. See the NOTICE file distributed with + - this work for additional information regarding copyright ownership. + - The ASF licenses this file to You under the Apache License, Version 2.0 + - (the "License"); you may not use this file except in compliance with + - the License. You may obtain a copy of the License at + - + - http://www.apache.org/licenses/LICENSE-2.0 + - + - Unless required by applicable law or agreed to in writing, software + - distributed under the License is distributed on an "AS IS" BASIS, + - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + - See the License for the specific language governing permissions and + - limitations under the License. + --> + +# REST Catalog Protocol + +## Overview + +As the Iceberg ecosystem grew, every engine and language needed its own client +for every catalog implementation. The REST catalog protocol solves this by +putting the catalog logic behind a common HTTP API, defined by the +[Iceberg REST Catalog API specification](../../rest-catalog-spec.md): a single +client implementation works with any compliant server. Because the server owns +commit logic, the protocol also enables capabilities that client-side catalogs +cannot offer, such as server-side conflict resolution, multi-table commits, +and secure table sharing through credential vending or remote signing. + +This page explains the concepts behind the protocol features and how the Java +client uses them. For configuring a REST catalog connection and the full +client property reference, see the [REST catalog page](rest-catalog.md). + +## Endpoint discovery and server-provided configuration + +On initialization, the client calls the server's configuration route +(`GET /v1/config`, passing the configured `warehouse` as a query parameter if +one is set). The response can adjust the client's configuration in three ways: + +- **`defaults`**: properties the server suggests; the client's own + configuration takes precedence over them. +- **`overrides`**: properties the server requires; they take precedence over + the client's configuration. A common override is `prefix`, which the client + inserts into all subsequent request paths (`/v1/{prefix}/namespaces/...`) + so that one server can host multiple catalogs. +- **`endpoints`**: the list of API endpoints the server supports. The client + only uses features whose endpoints are advertised, so a server that does not + implement, for example, view or scan-planning endpoints simply causes those + features to be unavailable rather than producing failed requests. + +If the server omits the `endpoints` field entirely, the client assumes a +default set of namespace and table endpoints. For older servers that support +views but predate endpoint discovery, set `view-endpoints-supported=true` +(see [REST catalog properties](rest-catalog.md#configuration)). + +## Multi-table transactions Review Comment: im a bit torn about this paragraph, i feel like this is over selling the capability. Spark/Flink/Kafka Connect all use single-table transaction. We technically can do this, but it requires both client implementation details and server implementation details. What do you think about dropping "Multi-table transactions" and instead describing the commit protocol, i.e. the client sends requirements and updates and the server validates and applies them? That's the part of the protocol every user actually relies on, and the page doesn't cover it yet. ########## docs/docs/rest-protocol.md: ########## @@ -0,0 +1,180 @@ +--- +title: "REST Catalog Protocol" +--- +<!-- + - Licensed to the Apache Software Foundation (ASF) under one or more + - contributor license agreements. See the NOTICE file distributed with + - this work for additional information regarding copyright ownership. + - The ASF licenses this file to You under the Apache License, Version 2.0 + - (the "License"); you may not use this file except in compliance with + - the License. You may obtain a copy of the License at + - + - http://www.apache.org/licenses/LICENSE-2.0 + - + - Unless required by applicable law or agreed to in writing, software + - distributed under the License is distributed on an "AS IS" BASIS, + - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + - See the License for the specific language governing permissions and + - limitations under the License. + --> + +# REST Catalog Protocol + +## Overview + +As the Iceberg ecosystem grew, every engine and language needed its own client +for every catalog implementation. The REST catalog protocol solves this by +putting the catalog logic behind a common HTTP API, defined by the +[Iceberg REST Catalog API specification](../../rest-catalog-spec.md): a single +client implementation works with any compliant server. Because the server owns +commit logic, the protocol also enables capabilities that client-side catalogs +cannot offer, such as server-side conflict resolution, multi-table commits, +and secure table sharing through credential vending or remote signing. + +This page explains the concepts behind the protocol features and how the Java +client uses them. For configuring a REST catalog connection and the full +client property reference, see the [REST catalog page](rest-catalog.md). + +## Endpoint discovery and server-provided configuration + +On initialization, the client calls the server's configuration route +(`GET /v1/config`, passing the configured `warehouse` as a query parameter if +one is set). The response can adjust the client's configuration in three ways: + +- **`defaults`**: properties the server suggests; the client's own + configuration takes precedence over them. +- **`overrides`**: properties the server requires; they take precedence over + the client's configuration. A common override is `prefix`, which the client + inserts into all subsequent request paths (`/v1/{prefix}/namespaces/...`) + so that one server can host multiple catalogs. +- **`endpoints`**: the list of API endpoints the server supports. The client + only uses features whose endpoints are advertised, so a server that does not + implement, for example, view or scan-planning endpoints simply causes those + features to be unavailable rather than producing failed requests. + +If the server omits the `endpoints` field entirely, the client assumes a +default set of namespace and table endpoints. For older servers that support +views but predate endpoint discovery, set `view-endpoints-supported=true` +(see [REST catalog properties](rest-catalog.md#configuration)). + +## Multi-table transactions + +The REST protocol can commit changes to multiple tables in one atomic +operation (`POST /v1/{prefix}/transactions/commit`). Each participating table +contributes its update requirements and metadata updates; the server validates +all requirements and applies all updates atomically, so either every table +commit succeeds or none does. + +In Java, this is exposed as `RESTCatalog.commitTransaction`: + +```java +import org.apache.iceberg.catalog.TableCommit; + +// derive requirements and updates from each table's base and updated metadata +TableCommit commit1 = TableCommit.create(identifier1, baseMetadata1, updatedMetadata1); +TableCommit commit2 = TableCommit.create(identifier2, baseMetadata2, updatedMetadata2); + +catalog.commitTransaction(commit1, commit2); +``` + +Multi-table commits are optional on both sides: the server must support the +transactions endpoint, and a server may restrict which operations can +participate in a transaction. Engines generally do not expose multi-table +commits through SQL today, so this is primarily a Java API feature. + +## Storage access delegation + +The REST protocol lets the catalog server control access to table data, so +that clients do not need long-lived storage credentials of their own. The spec +defines the `X-Iceberg-Access-Delegation` header with two mechanisms, and a +server may supply access through either or both: + +### Credential vending + +The server returns short-lived, table-scoped storage credentials +(`storage-credentials`) in the load-table response. The client applies them +automatically when it creates the table's `FileIO`, so reads and writes of +data and metadata files use the vended credentials without any client-side +configuration. Because each credential is scoped to a table's storage +prefixes, the catalog becomes the single point of access control. Review Comment: ```suggestion The server returns short-lived, table-scoped storage credentials (`storage-credentials`) in the load-table response. When they are present, the client applies them when it creates the table's `FileIO`, so reads and writes of data and metadata files use the vended credentials. Because each credential is scoped to a table's storage prefixes, the catalog becomes the single point of access control. Whether credentials are vended is up to the server. Some servers only vend credentials when the request carries the `X-Iceberg-Access-Delegation` header. ``` nit: adding some details about the header, and get rid of "without any client-side configuration" ########## docs/docs/rest-catalog.md: ########## @@ -0,0 +1,172 @@ +--- +title: "REST Catalog" +--- +<!-- + - Licensed to the Apache Software Foundation (ASF) under one or more + - contributor license agreements. See the NOTICE file distributed with + - this work for additional information regarding copyright ownership. + - The ASF licenses this file to You under the Apache License, Version 2.0 + - (the "License"); you may not use this file except in compliance with + - the License. You may obtain a copy of the License at + - + - http://www.apache.org/licenses/LICENSE-2.0 + - + - Unless required by applicable law or agreed to in writing, software + - distributed under the License is distributed on an "AS IS" BASIS, + - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + - See the License for the specific language governing permissions and + - limitations under the License. + --> + +# Iceberg REST Catalog + +An Iceberg REST catalog is any catalog service that implements the +[Iceberg REST Catalog API specification](../../rest-catalog-spec.md). Instead of +requiring a catalog-specific client in every engine and language, the catalog +logic lives behind an HTTP API, and a single client implementation works with +any compliant server. + +This page describes how to connect to a REST catalog from engines. For the protocol's features see the +[REST Catalog Protocol](rest-protocol.md) concept page; for the protocol +definition itself, see the [spec page](../../rest-catalog-spec.md). To try the +protocol locally, the community publishes the +[`apache/iceberg-rest-fixture`](https://hub.docker.com/r/apache/iceberg-rest-fixture) +Docker image, which serves the REST API backed by an in-memory catalog; see its +[README](https://github.com/apache/iceberg/blob/main/docker/iceberg-rest-fixture/README.md) +for how to run and configure it, or the +[Spark quickstart](../../spark-quickstart.md). + +## Examples + +### Spark + +```shell +spark-sql --packages org.apache.iceberg:iceberg-spark-runtime-{{ sparkVersionMajor }}:{{ icebergVersion }} \ + --conf spark.sql.catalog.my_catalog=org.apache.iceberg.spark.SparkCatalog \ + --conf spark.sql.catalog.my_catalog.type=rest \ + --conf spark.sql.catalog.my_catalog.uri=https://catalog-service/api/catalog \ + --conf spark.sql.catalog.my_catalog.warehouse=my_warehouse \ + --conf spark.sql.catalog.my_catalog.rest.auth.type=oauth2 \ + --conf spark.sql.catalog.my_catalog.credential=<client_id>:<client_secret> +``` + +See [Spark catalog configuration](spark-configuration.md#catalog-configuration) +for details. + +### Flink + +```sql +CREATE CATALOG prod WITH ( + 'type'='iceberg', + 'catalog-type'='rest', + 'uri'='https://catalog-service/api/catalog' +); +``` + +See the [Flink catalog documentation](flink.md#rest-catalog) for details. + +## Configuration + +Connecting to a REST catalog requires at minimum a `uri` pointing at the +service. The following properties configure the client side of the +connection; the +[common catalog properties](catalog-properties.md) (such as `warehouse` and +`io-impl`) apply as well. Note that the server can adjust this configuration +at connection time through +[endpoint discovery](rest-protocol.md#endpoint-discovery-and-server-provided-configuration). + +| Property | Default | Description | +|---------------------------------------|-------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `snapshot-loading-mode` | `ALL` | Controls how snapshots are loaded from the REST server. Supported values: `ALL` (load all snapshots), `REFS` (load only referenced snapshots). | +| `rest-metrics-reporting-enabled` | `true` | Whether to enable metrics reporting to the REST server. | +| `view-endpoints-supported` | `false` | For backwards compatibility with older REST servers. Set to `true` if the server supports view endpoints but doesn't send the `endpoints` field in the ConfigResponse. | +| `rest-page-size` | null | The page size to use when listing namespaces, tables, or other paginated resources. | +| `namespace-separator` | `%1F` | The separator character used for namespace levels when communicating with the REST server. | +| `scan-planning-mode` | `CLIENT` | Controls where scan planning is performed. Supported values: `CLIENT` (client-side planning), `SERVER` (server-side planning). Can be overridden per-table by the server in LoadTableResponse. | Review Comment: ```suggestion | `scan-planning-mode` | `client` | Controls where scan planning is performed. Supported values: `client` (client-side planning), `server` (server-side planning). Can be overridden per-table by the server in LoadTableResponse. | ``` nit these should be lower cased -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
