Apache Iceberg REST catalog API

Updated at:

The MaxCompute Iceberg REST Catalog provides a query interface compatible with the Apache Iceberg REST Catalog. This interface lets you discover service capabilities, query MaxCompute schema, read metadata for Iceberg tables (beta), and retrieve storage credentials. The current interface version is v1alpha and includes eight API operations: configuration discovery, namespace query, table query, and storage credential retrieval.
For the complete API documentation and spec, see the Apache Iceberg REST Catalog Spec.

API

  • The service endpoint is available only in the China (Shanghai) region. All projects, regardless of their region, must use this endpoint.

  • Request URIs are relative to this service endpoint.

    • project_id is the MaxCompute project name.

    • namespace is the MaxCompute schema name. Only single-level namespaces are supported.

The service endpoint for the China (Shanghai) region is as follows:

https://catalogapi.cn-shanghai.maxcompute.aliyun-inc.com/api/iceberg/v1alpha/restcatalog

API overview

API

HTTP method

URI

Permissions

GetConfig

GET

/v1/config

No MaxCompute resource permission required.

ListNamespaces

GET

/v1/projects/{project_id}/namespaces

project-level List permission.

GetNamespace

GET

/v1/projects/{project_id}/namespaces/{namespace}

schema-level Describe permission.

NamespaceExists

HEAD

/v1/projects/{project_id}/namespaces/{namespace}

project-level List permission.

ListTables

GET

/v1/projects/{project_id}/namespaces/{namespace}/tables

schema-level or project-level List permission.

LoadTable

GET

/v1/projects/{project_id}/namespaces/{namespace}/tables/{table}

table-level Describe and Select permissions. The UseConnection permission may also be required.

TableExists

HEAD

/v1/projects/{project_id}/namespaces/{namespace}/tables/{table}

schema-level or project-level List permission.

GetTableCredentials

GET

/v1/projects/{project_id}/namespaces/{namespace}/tables/{table}/credentials

table-level Describe and Select permissions. The UseConnection permission may also be required.

Note

The endpoints field in the GetConfig response specifies the supported data operations.

API list

GetConfig - Get catalog configuration

Retrieves the catalog configuration specified by the server. The Iceberg REST client should call this API first to obtain defaults, overrides, and the endpoints supported by the server.

Authorization

No MaxCompute resource permission is required.

Request syntax

GET /v1/config?warehouse=projects/my_project HTTP/1.1

Request parameters

Parameter

Location

Type

Required

Description

Example value

warehouse

Query

string

Yes

The warehouse identifier must be projects/{project_id}.

projects/my_project

Response parameters

Parameter

Type

Description

Example value

defaults

object

Default properties that apply if the client does not explicitly configure them.

{"format-version":"2"}

overrides

object

The server properties that override the client configuration, including prefix and warehouse.

{"prefix":"projects/my_project"}

endpoints

array[string]

A data operation supported by the server is in the format <HTTP method> <resource path>.

["GET /v1/{prefix}/namespaces"]

Success response example

{
  "defaults": {
    "format-version": "2"
  },
  "overrides": {
    "prefix": "projects/my_project",
    "warehouse": "projects/my_project"
  },
  "endpoints": [
    "GET /v1/{prefix}/namespaces",
    "GET /v1/{prefix}/namespaces/{namespace}",
    "HEAD /v1/{prefix}/namespaces/{namespace}",
    "GET /v1/{prefix}/namespaces/{namespace}/tables",
    "GET /v1/{prefix}/namespaces/{namespace}/tables/{table}",
    "HEAD /v1/{prefix}/namespaces/{namespace}/tables/{table}",
    "GET /v1/{prefix}/namespaces/{namespace}/tables/{table}/credentials"
  ]
}

ListNamespaces

Lists the single-level namespaces (which are MaxCompute schemas) in a project.

Authorization

You must have the project-level List permission. For details on granting permissions, see Manage user permissions by using commands or Manage user permissions by using the console.

Request syntax

GET /v1/projects/{project_id}/namespaces?pageToken={pageToken}&pageSize={pageSize} HTTP/1.1

Request parameters

Parameter

Location

Type

Required

Description

Example value

project_id

Path

string

Yes

The name of the MaxCompute project.

my_project

pageToken

Query

string

No

An opaque pagination token. Leave this parameter empty for the first request. For subsequent requests, use the next-page-token value from the previous response.

schema_b!

pageSize

Query

integer

No

The maximum number of results to return per page. This value must be greater than 0.

100

Response parameters

Parameter

Type

Description

Example value

namespaces

array[array[string]]

A list of namespaces. Each namespace is an array that contains a single schema name.

[["schema_a"],["schema_b"]]

next-page-token

string

A token for retrieving the next page of results. If this parameter is absent from the response, all results have been returned.

schema_b!

Successful response

{
  "namespaces": [
    ["schema_a"],
    ["schema_b"]
  ],
  "next-page-token": "schema_b!"
}

GetNamespace - Get namespace metadata

Retrieves the identifier and properties of a specified namespace.

Permissions

To grant permissions, see Manage user permissions by using commands or Manage user permissions by using the console.

Request syntax

GET /v1/projects/{project_id}/namespaces/{namespace} HTTP/1.1

Request parameters

Parameter

In

Type

Required

Description

Example value

project_id

Path

string

Yes

The name of the MaxCompute project.

my_project

namespace

Path

string

Yes

The name of the schema, which functions as a single-level namespace.

schema_a

Response parameters

Parameter

Type

Description

Example value

namespace

array[string]

The namespace identifier, an array that contains a single schema name.

["schema_a"]

properties

object

The properties of the namespace. This object may be empty.

{}

Success response

{
  "namespace": ["schema_a"],
  "properties": {}
}

NamespaceExists

Checks if the specified namespace exists. The response body is empty.

Permissions

This operation requires the project-level List permission. For more information, see Manage user permissions by using commands or Manage user permissions by using the console.

Request syntax

HEAD /v1/projects/{project_id}/namespaces/{namespace} HTTP/1.1

Request parameters

Parameter

Position

Type

Required

Description

Example

project_id

Path

string

Yes

The name of the MaxCompute project.

my_project

namespace

Path

string

Yes

The name of the schema, which is a single-level namespace.

schema_a

Response parameters

The response body is empty.

Success response example

HTTP/1.1 204 No Content

ListTables

Lists managed Iceberg tables in a specified namespace.

Permissions

This operation requires the List permission. If your project supports a schema layer, this permission is required at the schema level. Otherwise, it is required at the project level. To learn how to grant permissions, see Manage user permissions by using commands or Manage user permissions by using the console.

Request syntax

GET /v1/projects/{project_id}/namespaces/{namespace}/tables?pageToken={pageToken}&pageSize={pageSize} HTTP/1.1

Request parameters

Parameter

Location

Type

Required

Description

Sample value

project_id

Path

string

Yes

The name of the MaxCompute project.

my_project

namespace

Path

string

Yes

The name of the schema. For projects without a schema layer, you must use the default schema.

schema_a

pageToken

Query

string

No

An opaque pagination token.

table_2!

pageSize

Query

integer

No

The maximum number of results to return per page. The value must be greater than 0.

100

Response parameters

Parameter

Parent

Type

Description

Sample value

identifiers

Top level

array<object>

A list of table identifiers. Each element represents a table.

See the example below.

namespace

identifiers element

array<string>

The schema (namespace) to which the table belongs. MaxCompute supports only single-level namespaces, so this array contains only one value.

["schema_a"]

name

identifiers element

string

The table name.

table_1

next-page-token

Top level

string

The token for the next page of results. If this field is not returned, you have reached the last page.

table_2!

Example response

{
  "identifiers": [
    {"namespace": ["schema_a"], "name": "table_1"},
    {"namespace": ["schema_a"], "name": "table_2"}
  ],
  "next-page-token": "table_2!"
}

LoadTable

Retrieves the complete metadata for an Iceberg table, including the metadata file location, table-level configuration, and available storage access credentials.

Permissions

This operation requires table-level Describe and Select permissions. For details on granting permissions, see Manage User Permissions by Using Commands or Manage User Permissions by Using the Console.

This operation also requires the Use permission for the connection. For more information, see Grant Permissions on a Connection.

Request syntax

GET /v1/projects/{project_id}/namespaces/{namespace}/tables/{table} HTTP/1.1

Request parameters

Parameter

Location

Type

Required

Description

Example

project_id

Path

string

Yes

The name of the MaxCompute project.

my_project

namespace

Path

string

Yes

The name of the schema. For projects that do not have a schema layer, you must use the default schema.

schema_a

table

Path

string

Yes

The name of the table.

sales

Response parameters

Parameter

Level

Type

Description

Example

metadata-location

Top-level

string

The location of the Iceberg table metadata JSON file. This value can be null.

oss://bucket/path/metadata/00001.metadata.json

metadata

Top-level

object

This object follows the Iceberg metadata JSON format.

See the example below.

config

Top-level

object

Table-level client configuration. This can include S3-compatible settings.

{"s3.access-key-id":"AKIDEXAMPLE"}

storage-credentials

Top-level

array<object>

A list of storage access credentials.

See the example below.

prefix

storage-credentials element

string

The storage path prefix to which the credential applies. If multiple credentials match a path, the system selects the one with the longest prefix.

oss://bucket/path

config

storage-credentials element

object

Configuration for the credential, including details such as the access key, secret, session token, and expiration time.

See the example below.

Click to view key fields for metadata

Parameter

Type

Description

format-version

integer

The Iceberg format version. Valid values: 1 to 3.

table-uuid

string

The UUID of the table.

location

string

The root storage location of the table.

last-updated-ms

integer(int64)

The time the metadata was last updated, as a Unix timestamp in milliseconds.

properties

object

Table properties. This does not include server-side-only properties.

schemas

array[object]

The history of schemas for the table.

current-schema-id

integer

The ID of the current schema.

last-column-id

integer

The highest assigned column ID.

partition-specs

array[object]

The history of partition specifications.

default-spec-id

integer

The ID of the default partition specification.

last-partition-id

integer

The highest assigned partition field ID.

sort-orders

array[object]

The history of sort orders.

default-sort-order-id

integer

The ID of the default sort order.

snapshots

array[object]

A list of snapshots.

refs

object

Snapshot references.

current-snapshot-id

integer(int64)

The ID of the current snapshot.

last-sequence-number

integer(int64)

The last sequence number.

snapshot-log

array[object]

The snapshot log.

metadata-log

array[object]

The metadata log.

statistics

array[object]

Statistics files.

partition-statistics

array[object]

Partition statistics files.

Success response example

The credentials in the following example are placeholders.

{
  "metadata-location": "oss://bucket/path/metadata/00001.metadata.json",
  "metadata": {
    "format-version": 2,
    "table-uuid": "2f1d1d1e-1111-4444-8888-123456789abc",
    "location": "oss://bucket/path",
    "last-updated-ms": 1784275200000,
    "current-schema-id": 0,

    "schemas": [{"type": "struct", "schema-id": 0, "fields": [ ]}],

    "properties": {}
  },
  "config": {
    "s3.access-key-id": "AKIDEXAMPLE",
    "s3.secret-access-key": "SECRETEXAMPLE",
    "s3.session-token": "TOKENEXAMPLE",
    "s3.session-token-expires-at-ms": "1784318400000"
  },
  "storage-credentials": [{
    "prefix": "oss://bucket/path",
    "config": {
      "s3.access-key-id": "AKIDEXAMPLE",
      "s3.secret-access-key": "SECRETEXAMPLE",
      "s3.session-token": "TOKENEXAMPLE",
      "s3.session-token-expires-at-ms": "1784318400000"
    }
  }]
}

TableExists

Checks if a specified table exists and is visible to the REST Catalog. The response body is empty.

Permissions

For projects that support schemas, schema-level List permission is required. Otherwise, project-level List permission is required. To grant permissions, see Manage user permissions by using commands or Manage user permissions in the MaxCompute console.

Request syntax

HEAD /v1/projects/{project_id}/namespaces/{namespace}/tables/{table} HTTP/1.1

Request parameters

Parameter

Location

Type

Required

Description

Example

project_id

Path

string

Yes

The name of the MaxCompute project.

my_project

namespace

Path

string

Yes

The schema name. For projects that do not support schemas, you must use the default schema.

schema_a

table

Path

string

Yes

The table name.

sales

Response parameters

The response body is empty.

Success response example

HTTP/1.1 204 No Content

GetTableCredentials

Retrieves the credentials to access a specified table storage location.

Authorization

This operation requires the table-level Describe and Select permissions. To grant these permissions, see Manage User Permissions by Using Commands or Manage User Permissions by Using the console.

This operation also requires the Use permission on the connection. For more information, see Grant Permissions on a Connection.

Request syntax

GET /v1/projects/{project_id}/namespaces/{namespace}/tables/{table}/credentials HTTP/1.1

Request parameters

Parameter

Location

Type

Required

Description

Example

project_id

Path

string

Yes

The name of the MaxCompute project.

my_project

namespace

Path

string

Yes

The schema name. For projects with a two-level model, you must use the default schema.

schema_a

table

Path

string

Yes

The table name.

sales

Response parameters

Parameter

Parent

Type

Description

Example

storage-credentials

Top level

array<object>

A list of storage credentials. Returns an empty array if no credentials are available.

See the example below.

prefix

storage-credentials element

string

The storage path prefix that the credential applies to.

oss://bucket/path

config

storage-credentials element

object

S3-compatible credential configuration.

See the example below.

s3.access-key-id

config field

string

The AccessKey ID.

AKIDEXAMPLE

s3.secret-access-key

config field

string

The AccessKey Secret.

SECRETEXAMPLE

s3.session-token

config field

string

The STS session token. This parameter is omitted when using static Access Keys.

TOKENEXAMPLE

s3.session-token-expires-at-ms

config field

string

The expiration time of the STS credential, as a Unix timestamp in milliseconds. This parameter is omitted when using static Access Keys.

1784318400000

Successful response example

The credentials in the following example are placeholders.

{
  "storage-credentials": [{
    "prefix": "oss://bucket/path",
    "config": {
      "s3.access-key-id": "AKIDEXAMPLE",
      "s3.secret-access-key": "SECRETEXAMPLE",
      "s3.session-token": "TOKENEXAMPLE",
      "s3.session-token-expires-at-ms": "1784318400000"
    }
  }]
}

Usage examples

Postman example

  1. Enter the request URL. This example uses the China (Shanghai) region.

    https://catalogapi.cn-shanghai.maxcompute.aliyun-inc.com/api/iceberg/v1alpha/restcatalog
  2. Configure the pre-request script.

    We recommend that you use STS temporary credentials to avoid leaking your AccessKey pair.

    // ODPS standard signature Pre-request Script (supports STS temporary credentials)
    // Long-term AK: ODPS_AK_ID, ODPS_AK_SECRET
    // STS temporary credentials: ODPS_AK_ID, ODPS_AK_SECRET (temporary), ODPS_STS_TOKEN
    const accessKeyId = pm.environment.get("ODPS_AK_ID");
    const accessKeySecret = pm.environment.get("ODPS_AK_SECRET");
    const stsToken = pm.environment.get("ODPS_STS_TOKEN"); // leave empty / unset if not used
    
    const method = pm.request.method;          // GET / HEAD
    const contentType = "";                     // empty when there is no body
    const contentMD5 = "";                      // empty when there is no body
    const date = new Date().toUTCString();      // GMT, e.g. "Wed, 15 Jul 2026 06:00:00 GMT"
    
    // CanonicalizedResource: path + query sorted by parameter name
    const url = pm.request.url;
    let resource = "/" + url.getPath().replace(/^\/+/, "");
    const params = (url.query && url.query.all() ? url.query.all() : [])
      .filter(p => p && p.key && !p.disabled)
      .map(p => [p.key, p.value == null ? "" : p.value])
      .sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0);
    if (params.length) {
      resource += "?" + params.map(([k, v]) => v === "" ? k : `${k}=${v}`).join("&");
    }
    
    // StringToSign (CanonicalizedHeaders is empty when there are no x-odps- headers)
    const stringToSign =
      method + "\n" +
      contentMD5 + "\n" +
      contentType + "\n" +
      date + "\n" +
      resource;
    
    const signature = CryptoJS.HmacSHA1(stringToSign, accessKeySecret)
                              .toString(CryptoJS.enc.Base64);
    
    pm.request.headers.upsert({ key: "Date", value: date });
    pm.request.headers.upsert({
      key: "Authorization",
      value: "ODPS " + accessKeyId + ":" + signature
    });
    
    // STS temporary credentials: attach the SecurityToken header; skipped automatically
    // when the variable is empty (long-term AK mode)
    if (stsToken) {
      pm.request.headers.upsert({ key: "authorization-sts-token", value: stsToken });
    } else {
      pm.request.headers.remove("authorization-sts-token");
    }
  3. Confirm your current environment settings.

Spark example

This section shows how to use the REST Catalog API to access data and metadata from MaxCompute-managed Iceberg tables in a Spark environment. The process is fully compatible with open-source standards.

Prerequisites

  • Ensure that your project has been approved for the beta trial and you can use Iceberg tables managed by MaxCompute (beta).

  • Upload the following JAR files to your Spark environment:

    • iceberg-odps-1.12.0-SNAPSHOT.jar

      This file contains the OdpsAuthManager implementation and must be uploaded.

    • iceberg-spark-runtime-3.5_2.12-1.10.1.jar

      This file contains all dependencies required for Iceberg to run on Spark. If your environment already includes this JAR file, you can skip this upload.

    • iceberg-aws-bundle-1.10.1.jar

      This file contains the dependencies required for Iceberg to interact with S3- and OSS-compatible services. If your environment already includes this JAR file, you can skip this upload.

  • Upgrade your Spark 3 service to JDK 17. If you use an E-MapReduce (EMR) instance, follow the instructions in Use JDK 11 with Spark 3, but replace java-11 with java-17 in the commands.

Configure and start spark-sql

The following command starts spark-sql. Run it on your Spark client node, such as the master node of an EMR cluster or a local environment with Spark configured.

Start spark-sql
export AWS_REGION=cn-shanghai
spark-sql \
  --jars /root/iceberg/iceberg-spark-runtime-3.5_2.12-1.10.1.jar,/root/iceberg/iceberg-aws-bundle-1.10.1.jar,/root/iceberg/iceberg-odps-1.12.0-SNAPSHOT.jar \
  --conf spark.driver.extraClassPath=/root/iceberg/* \
  --conf spark.executor.extraClassPath=/root/iceberg/* \
  --conf spark.sql.extensions=org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions \
  --conf spark.sql.catalog.odps=org.apache.iceberg.spark.SparkCatalog \
  --conf spark.sql.catalog.odps.catalog-impl=org.apache.iceberg.rest.RESTCatalog \
  --conf spark.sql.catalog.odps.uri=https://catalogapi.cn-shanghai.maxcompute.aliyun-inc.com/api/iceberg/v1alpha/restcatalog/ \
  --conf spark.sql.catalog.odps.warehouse=projects/project_name \
  --conf spark.sql.catalog.odps.io-impl=org.apache.iceberg.aws.s3.S3FileIO \
  --conf spark.sql.catalog.odps.rest.auth.type=org.apache.iceberg.odps.auth.OdpsAuthManager \
  --conf spark.sql.catalog.odps.odps.auth.access-key-id=<your_access_key_id> \
  --conf spark.sql.catalog.odps.odps.auth.access-key-secret=<your_access_key_secret> \
  --conf spark.sql.catalog.odps.s3.endpoint=https://oss-cn-shanghai.aliyuncs.com \
  --conf spark.sql.catalog.odps.client.region=cn-shanghai \
  --conf spark.sql.catalogImplementation=in-memory \
  --conf spark.hadoop.javax.jdo.option.ConnectionURL="jdbc:derby:/tmp/metastore_db;create=true"

Parameters

Parameter

Note

Example

Environment variable

export AWS_REGION

Specifies the deployment environment:

  • Required for local Spark environments.

  • Optional for EMR clusters.

Fixed value: cn-shanghai.

JAR file parameter

--jars

The JAR files on which spark-sql depends.

You must upload these files to the Spark cluster in advance. Separate multiple JAR file paths with a comma (,).

/root/iceberg/iceberg-spark-runtime-3.5_2.12-1.10.1.jar,/root/iceberg/iceberg-aws-bundle-1.10.1.jar,/root/iceberg/iceberg-odps-1.12.0-SNAPSHOT.jar

Configuration parameters

spark.driver.extraClassPath

This configuration is required for EMR instances to avoid conflicts with Iceberg JAR files. Set the value to the path of the Iceberg JAR files.

If the Iceberg JAR files are in the /root/iceberg/ directory, set this to /root/iceberg/*.

spark.executor.extraClassPath

This configuration is required for EMR instances to avoid conflicts with Iceberg JAR files. Set the value to the path of the Iceberg JAR files.

If the Iceberg JAR files are in the /root/iceberg/ directory, set this to /root/iceberg/*.

spark.sql.extensions

Specifies the extensions to register with the SparkSession.

Fixed value: org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions.

spark.sql.catalog.odps

Registers a custom catalog named odps. You can then use this name to access tables in Spark SQL. If you customize the name, you must update it in all related parameters.

Fixed value: org.apache.iceberg.spark.SparkCatalog.

spark.sql.catalog.odps.catalog-impl

Specifies the catalog implementation class.

Fixed value: org.apache.iceberg.rest.RESTCatalog.

spark.sql.catalog.odps.uri

The MaxCompute REST Catalog endpoint.

  • If your Spark cluster is local or an EMR cluster with public network access, use the public endpoint: https://catalogapi.cn-shanghai.maxcompute.aliyun-inc.com/api/iceberg/v1alpha/restcatalog/

  • If your Spark cluster is an EMR cluster without public network access, use the VPC endpoint: https://catalogapi.cn-shanghai-vpc.maxcompute.aliyun-inc.com/api/iceberg/v1alpha/restcatalog/

spark.sql.catalog.odps.warehouse

The name of the MaxCompute project where the Iceberg tables are located.

spark.sql.catalog.odps.io-impl

Specifies the data I/O implementation class.

Fixed value: org.apache.iceberg.aws.s3.S3FileIO.

spark.sql.catalog.odps.rest.auth.type

Specifies the authentication implementation class.

Fixed value: org.apache.iceberg.odps.auth.OdpsAuthManager. This is the MaxCompute authentication implementation.

spark.sql.catalog.odps.odps.auth.access-key-id

Your AccessKey ID.

spark.sql.catalog.odps.odps.auth.access-key-secret

Your AccessKey secret.

spark.sql.catalog.odps.odps.auth.sts-token

The STS token for your account. This parameter is required only for authentication using a RAM role. Omit this parameter if you are using an Alibaba Cloud account or a RAM user.

spark.sql.catalog.odps.s3.endpoint

The OSS endpoint for data I/O.

  • If your Spark cluster is local or an EMR cluster with public network access, use the public endpoint: https://oss-cn-shanghai.aliyuncs.com

  • If your Spark cluster is an EMR cluster without public network access, use the VPC endpoint: https://oss-cn-shanghai-internal.aliyuncs.com

  • To avoid potential data transfer charges, we recommend using the internal endpoint in environments with internal network access.

spark.sql.catalog.odps.client.region

This configuration is required for EMR instances.

Fixed value: cn-shanghai.

spark.sql.catalogImplementation

This configuration is required for EMR instances.

Fixed value: in-memory.

spark.hadoop.javax.jdo.option.ConnectionURL

This configuration is required for EMR instances.

Fixed value: jdbc:derby:/tmp/metastore_db;create=true.

Run spark-sql

After you start spark-sql, use the appropriate syntax to access MaxCompute Iceberg tables based on whether your project has schema-level hierarchy enabled.

Projects with schema-level hierarchy

When schema-level hierarchy is enabled, a project supports a table-schema-project hierarchy and schema-related operations. The schema level maps to the namespace level of the Iceberg catalog. The REST Catalog API uses the catalog.namespace.table syntax. For more information, see Schema operations.

  1. List the namespaces in the project. This syntax is supported only for projects with schema-level hierarchy enabled.

    show namespaces in odps;
  2. List the tables in a namespace.

    -- List tables in the 'default' namespace.
    show tables in odps.default;
    
    -- List tables in the 'test01' namespace. Replace 'test01' with another schema name.
    show tables in odps.test01;
  3. Query a table in a namespace.

    -- Query a table in the 'default' namespace.
    select * from odps.default.table_name;
    
    -- Query a table in the 'test01' namespace. Replace 'test01' with another schema name.
    select * from odps.test01.table_name;
  4. View table details.

    -- View details for a table in the 'default' namespace.
    desc odps.default.table_name;
    
    -- View details for a table in the 'test01' namespace. Replace 'test01' with another schema name.
    desc odps.test01.table_name;
Projects without schema-level hierarchy

If a project does not have schema-level hierarchy enabled, it supports a table-project hierarchy, and schema-related operations are not supported. The REST Catalog API uses the project.default.table syntax. For more information, see Schema operations.

  1. List the tables in a namespace.

    show tables in odps.default;
  2. Query a table in a namespace.

    select * from odps.default.table_name;
  3. View table details.

    desc odps.default.table_name;

Usage example

The following example demonstrates the complete process using an EMR cluster, a RAM role, and a project that supports schema-level hierarchy.

Prepare data
  1. Create a connection

    1. Log in to the MaxCompute console and select a region in the upper-left corner.

    2. In the left-side navigation pane, choose MaxLake > Data Lake Connection.

    3. On the Data Lake Connection (CONNECTION) page, click Create Data Lake Connection.

    4. In the Create Data Lake Connection dialog box, configure the parameters and click OK.

      Parameter

      Description

      Data lake connection parameter

      The name of the data lake connection. The name must be unique within the tenant.

      RAMRoleARN

      The ARN of a RAM role that has permissions to access OSS.

      You can also create a custom role and specify its RAM role ARN. For more information, see Authorization for accessing external data sources.

      Data lake connection description

      A description of the data lake connection.

    5. On the Data Lake Connection (CONNECTION) page, in the Operation column for the desired CONNECTION, click Add Authorization.

      In the Data Lake Connection Authorization dialog box, add the users you want to authorize and click OK.

  2. Create a managed Iceberg table and write test data

    Create a MaxCompute-managed Iceberg table and insert test data into it.

    SET odps.namespace.schema=true;
    CREATE ICEBERG TABLE default.mc_iceberg_table_rest_catalog (
        emp_id      BIGINT       COMMENT 'Employee ID',
        emp_name    STRING       COMMENT 'Employee Name',
        department  STRING       COMMENT 'Department',
        salary      DOUBLE       COMMENT 'Salary',
        hire_date   DATE         COMMENT 'Hire Date',
        ds          STRING       COMMENT 'Partition Date'
    )
    PARTITIONED BY (ds)
    WITH CONNECTION <YOUR CONNECTION>
    OPTIONS(
      location='oss://<oss bucket>/rest_catalog/'
    );
    
    -- Write data to the table.
    SET odps.namespace.schema=true;
    INSERT INTO TABLE default.mc_iceberg_table_rest_catalog 
        VALUES (1001, 'Alice',   'Tech', 15000.00, date '2020-03-15','2024-01-01');
    INSERT INTO TABLE default.mc_iceberg_table_rest_catalog 
        VALUES (1002, 'Bob',   'Tech', 18000.00, date '2019-07-22','2024-01-01');
    INSERT INTO TABLE default.mc_iceberg_table_rest_catalog  
        VALUES (1003, 'Charlie',   'Product', 16000.00, date '2021-01-10','2024-01-01');
    
    -- Confirm that you can read the table by using SQL.
    SET odps.namespace.schema=true;
    SELECT * FROM default.mc_iceberg_table_rest_catalog;
    
    +------------+------------+------------+------------+------------+------------+
    | emp_id     | emp_name   | department | salary     | hire_date  | ds         | 
    +------------+------------+------------+------------+------------+------------+
    | 1003       | Charlie    | Product    | 16000.0    | 2021-01-10 | 2024-01-01 | 
    | 1001       | Alice      | Tech       | 15000.0    | 2020-03-15 | 2024-01-01 | 
    | 1002       | Bob        | Tech       | 18000.0    | 2019-07-22 | 2024-01-01 | 
    +------------+------------+------------+------------+------------+------------+
Start spark-sql

The following command starts spark-sql on an EMR cluster with VPC internal network access. It is configured to use a RAM role to access a MaxCompute project where schema-level hierarchy is enabled. If you are using a RAM user, remove the spark.sql.catalog.odps.odps.auth.sts-token parameter.

export AWS_REGION=cn-shanghai

spark-sql \
--jars /root/iceberg/iceberg-spark-runtime-3.5_2.12-1.10.1.jar,/root/iceberg/iceberg-aws-bundle-1.10.1.jar,/root/iceberg/iceberg-odps-1.12.0-SNAPSHOT.jar \
--conf spark.driver.extraClassPath=/root/iceberg/* \
--conf spark.executor.extraClassPath=/root/iceberg/* \
--conf spark.sql.extensions=org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions \
--conf spark.sql.catalog.odps=org.apache.iceberg.spark.SparkCatalog \
--conf spark.sql.catalog.odps.catalog-impl=org.apache.iceberg.rest.RESTCatalog \
--conf spark.sql.catalog.odps.uri=https://catalogapi.cn-shanghai-vpc.maxcompute.aliyun-inc.com/api/iceberg/v1alpha/restcatalog/ \
--conf spark.sql.catalog.odps.warehouse=projects/<projectname> \
--conf spark.sql.catalog.odps.io-impl=org.apache.iceberg.aws.s3.S3FileIO \
--conf spark.sql.catalog.odps.rest.auth.type=org.apache.iceberg.odps.auth.OdpsAuthManager \
--conf spark.sql.catalog.odps.odps.auth.access-key-id=STS.*** \
--conf spark.sql.catalog.odps.odps.auth.access-key-secret=*** \
--conf spark.sql.catalog.odps.odps.auth.sts-token=*** \
--conf spark.sql.catalog.odps.s3.endpoint=https://oss-cn-shanghai-internal.aliyuncs.com \
--conf spark.sql.catalog.odps.client.region=cn-shanghai \
--conf spark.sql.catalogImplementation=in-memory \
--conf spark.hadoop.javax.jdo.option.ConnectionURL="jdbc:derby:/tmp/metastore_db;create=true"
Run spark-sql queries
  1. List the namespaces in the project.

    spark-sql (default)> show namespaces in odps;
    default
    test01
    Time taken: 1.676 seconds, Fetched 2 row(s)
  2. List the tables in a namespace.

    spark-sql (default)> show tables in odps.default;
    mc_iceberg_table_test1
    mc_iceberg_table_test2
    mc_iceberg_table_test3
    mc_iceberg_table_rest_catalog
    Time taken: 0.276 seconds, Fetched 4 row(s)
  3. Query a table in a namespace.

    spark-sql (default)> select * from odps.default.mc_iceberg_table_rest_catalog;
    1003    Charlie Product   16000.0 2021-01-10      2024-01-01
    1002    Bob     Tech      18000.0 2019-07-22      2024-01-01
    1001    Alice   Tech      15000.0 2020-03-15      2024-01-01
    Time taken: 5.403 seconds, Fetched 3 row(s)
  4. View table details.

    spark-sql (default)> desc odps.test01.mc_iceberg_table_rest_catalog;
    emp_id                  bigint                  Employee ID             
    emp_name                string                  Employee Name           
    department              string                  Department              
    salary                  double                  Salary                  
    hire_date               date                    Hire Date               
    ds                      string                  Partition Date          
    # Partition Information                                             
    # col_name              data_type               comment             
    ds                      string                  Partition Date          
    Time taken: 0.78 seconds, Fetched 9 row(s)