Querying shared data from Snowflake

Snowflake is one of the external engines that can read data shared through the Cloudera Iceberg REST Catalog. Configure a Snowflake catalog integration that points to the Cloudera data sharing endpoint, and follow the Snowflake documentation to run queries.

Any engine that supports the Apache Iceberg REST catalog specification can read the Iceberg tables that you share through the Cloudera Iceberg REST Catalog. Snowflake is one such engine. Cloudera provides and supports the data sharing endpoint; the configuration and operation of Snowflake is described in the Snowflake documentation.

What you configure in Cloudera

Before an external engine can query shared data, complete the data sharing setup on the Cloudera side:

  • Register the external client and create a Data Share, then provision the CLIENT_ID and CLIENT_SECRET that the engine uses to authenticate. For more information, see Setting up Cloudera Iceberg REST Catalog for data sharing.
  • Allow the addresses that Snowflake uses to reach the Knox gateway. Snowflake validates the catalog integration when you create it and polls the endpoint for automatic refresh, so the security group must persistently allow this access. Snowflake egresses from non-fixed addresses, so allow its published egress ranges or use private connectivity.
  • Use the data sharing token and REST catalog endpoints when you configure the engine. For the endpoint paths and the authentication flow, see Supported REST Catalog APIs for accessing the data.

What you configure in Snowflake

In Snowflake, create an Iceberg REST catalog integration that points to the Cloudera data sharing endpoint using the credentials and endpoint values from the previous steps, and then create a catalog-linked database to query the tables. For instructions, see the Snowflake documentation:

Cloudera values for the catalog integration

Set the following Snowflake catalog integration parameters to point Snowflake at the Cloudera data sharing endpoint. Replace the placeholders with the values for your environment.

Table 1. Snowflake catalog integration parameters for the Cloudera data sharing endpoint
Parameter Value to set
CATALOG_SOURCE ICEBERG_REST
TABLE_FORMAT ICEBERG
CATALOG_NAMESPACE

[***DB***]

The database (namespace) that contains the shared tables, for example the database you shared in the Data Share.

CATALOG_URI

https://[***DL-GATEWAY-FQDN***]/[***DL-NAME***]/cdp-datashare-access/iceberg-rest

Use the base REST catalog URI without a trailing /v1/, and use the Data Lake gateway host, not an individual master0 host, so that requests route correctly on High Availability Data Lakes.

CATALOG_API_TYPE PUBLIC
ACCESS_DELEGATION_MODE VENDED_CREDENTIALS
REST_AUTHENTICATION TYPE

BEARER

Use BEARER with a pre-fetched JWT, not OAUTH. The Cloudera token endpoint returns the token expiry as an absolute timestamp in milliseconds, which the native OAUTH option in Snowflake cannot parse correctly.

REST_AUTHENTICATION BEARER_TOKEN

[***JWT***]

A JWT access token that you obtain from the Cloudera token endpoint. For the two-step authentication flow that exchanges the CLIENT_ID and CLIENT_SECRET for this token, see https://docs.cloudera.com/runtime/7.3.3/using-cloudera-data-sharing/topics/cr-ds-access-data-using-rest-catalog-apis.html. The token expires, so you must refresh it.

Example: Snowflake catalog integration

First, obtain a JWT from the Cloudera token endpoint, from a host whose address the Knox security group allows:

JWT=$(curl -sk -X POST -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=client_credentials&client_id=[***CLIENT-ID***]&client_secret=[***CLIENT-SECRET***]" \
  "https://[***DL-GATEWAY-FQDN***]/[***DL-NAME***]/cdp-datashare-access/knoxtoken/api/v2/token" | jq -r .access_token)

Then, create the catalog integration in Snowflake, using the JWT as the bearer token:

CREATE OR REPLACE CATALOG INTEGRATION cdp_iceberg
  CATALOG_SOURCE     = ICEBERG_REST
  TABLE_FORMAT       = ICEBERG
  CATALOG_NAMESPACE  = '[***DB***]'
  REST_CONFIG = (
    CATALOG_URI            = 'https://[***DL-GATEWAY-FQDN***]/[***DL-NAME***]/cdp-datashare-access/iceberg-rest'
    CATALOG_NAME           = '[***DL-NAME***]'
    CATALOG_API_TYPE       = PUBLIC
    ACCESS_DELEGATION_MODE = VENDED_CREDENTIALS
  )
  REST_AUTHENTICATION = (
    TYPE         = BEARER
    BEARER_TOKEN = '[***JWT***]'
  )
  ENABLED = TRUE;

The bearer token expires. To refresh it in place without recreating the integration, use ALTER CATALOG INTEGRATION with a fresh JWT:

ALTER CATALOG INTEGRATION cdp_iceberg
  SET REST_AUTHENTICATION = ( BEARER_TOKEN = '[***FRESH-JWT***]' );

After you create the catalog integration, create a catalog-linked database to sync the tables, and then you can query them:

CREATE DATABASE cdp_linked_db
  LINKED_CATALOG = ( CATALOG = 'cdp_iceberg' );

USE DATABASE cdp_linked_db;

SELECT * FROM [***DB***].[***TABLE***] LIMIT 10;