> For the complete documentation index, see [llms.txt](https://docs.streambased.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.streambased.io/deploy-and-operate/integrate-with-iceberg-engines/integrate-with-spark.md).

# Integrate with Spark

## Connect Apache Spark to Streambased ISK

This guide walks you through connecting a self-managed **Apache Spark cluster** to your **Streambased ISK (Iceberg REST Catalog)** using Apache Iceberg's native Spark catalog integration.

Once configured, Spark can discover and query Iceberg tables exposed by your Streambased deployment, allowing you to work with your data using Spark SQL, PySpark, or other Spark applications.

The integration uses the Apache Iceberg REST Catalog API for metadata operations and Streambased's S3-compatible storage endpoint for accessing the underlying table data.

### Prerequisites

Before you begin, make sure you have:

* A running Apache Spark cluster that you can configure.
* An active Streambased deployment with ISK enabled.
* The Iceberg REST Catalog endpoint for your Streambased deployment.
* The S3-compatible storage endpoint for your Streambased deployment.
* A Streambased API key and secret key.
* Permission to install dependencies and modify Spark configuration.
* Network connectivity from your Spark driver and executors to the Streambased endpoints.

This guide assumes you are using **Apache Spark 3.x** with a compatible version of Apache Iceberg.

> **Important:** Your Spark and Iceberg library versions must be compatible. The exact dependencies will depend on your Spark and Scala versions.

### Step 1: Install Apache Iceberg dependencies

Apache Spark requires the Apache Iceberg runtime and AWS integration libraries to communicate with Streambased ISK.

The required libraries provide the following functionality:

| Library                      | Purpose                                                    |
| ---------------------------- | ---------------------------------------------------------- |
| Apache Iceberg Spark Runtime | Registers and interacts with Iceberg catalogs and tables   |
| Apache Iceberg AWS Bundle    | Provides S3FileIO and AWS-compatible storage functionality |

#### Example Maven dependencies

For a Spark 3.5 cluster using Scala 2.12 and Apache Iceberg 1.9.2, use:

```
org.apache.iceberg:iceberg-spark-runtime-3.5_2.12:1.9.2
org.apache.iceberg:iceberg-aws-bundle:1.9.2
```

These versions are illustrative. Use versions compatible with your Spark installation.

#### Option A: Install dependencies using spark-submit

If you are submitting Spark applications directly, use the `--packages` argument:

```
spark-submit \
  --packages \
  org.apache.iceberg:iceberg-spark-runtime-3.5_2.12:1.9.2,org.apache.iceberg:iceberg-aws-bundle:1.9.2 \
  your_application.py
```

Spark will resolve the dependencies from your configured Maven repositories.

#### Option B: Install dependencies using spark-shell

For an interactive Spark session:

```
spark-shell \
  --packages \
  org.apache.iceberg:iceberg-spark-runtime-3.5_2.12:1.9.2,org.apache.iceberg:iceberg-aws-bundle:1.9.2
```

#### Option C: Install dependencies at the cluster level

If you manage your own Spark installation, you can also make the required JAR files available to the Spark driver and executors.

For example, you can place the compatible JAR files in your Spark installation's `jars/` directory or configure your cluster's dependency management system to distribute them.

> **Note:** Ensure that all nodes use compatible Iceberg dependencies. Avoid installing multiple conflicting versions of Iceberg or its AWS libraries.

### Step 2: Configure the Streambased Iceberg catalog

Next, register Streambased ISK as an Apache Iceberg REST Catalog.

Spark supports configuring catalogs through properties in `spark-defaults.conf`, through `spark-submit` arguments, or programmatically when creating a Spark session.

For a self-managed cluster, configuring the catalog in `spark-defaults.conf` is a convenient way to make it available across Spark applications.

#### Locate spark-defaults.conf

The configuration file is typically located at:

```
$SPARK_HOME/conf/spark-defaults.conf
```

If the file does not exist, create it using the provided Spark configuration template.

#### Add the Streambased catalog configuration

Add the following properties to your Spark configuration:

```
# Register the Streambased Iceberg catalog
spark.sql.catalog.isk org.apache.iceberg.spark.SparkCatalog
spark.sql.catalog.isk.type rest
spark.sql.catalog.isk.uri <STREAMBASED_CATALOG_URI e.g. https://catalog.dev-us-west-2.streambased.cloud>

# Catalog warehouse
spark.sql.catalog.isk.warehouse s3://

# REST catalog authentication
spark.sql.catalog.isk.rest.sigv4-enabled true
spark.sql.catalog.isk.rest.signing-region us-west-2
spark.sql.catalog.isk.rest.access-key-id <STREAMBASED_API_KEY>
spark.sql.catalog.isk.rest.secret-access-key <STREAMBASED_SECRET_KEY>

# S3-compatible storage configuration
spark.sql.catalog.isk.io-impl org.apache.iceberg.aws.s3.S3FileIO
spark.sql.catalog.isk.s3.endpoint <STREAMBASED_STORAGE_URI e.g. https://isk.dev-us-west-2.streambased.cloud>
spark.sql.catalog.isk.s3.path-style-access true
spark.sql.catalog.isk.s3.access-key-id <STREAMBASED_API_KEY>
spark.sql.catalog.isk.s3.secret-access-key <STREAMBASED_SECRET_KEY>

# Metadata caching
spark.sql.catalog.isk.cache.expiration-interval-ms 10000

# Enable Iceberg Spark SQL extensions
spark.sql.extensions org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions

# Set ISK as the default catalog
spark.sql.defaultCatalog isk
```

> **Important:** Replace the example endpoint URLs and credential placeholders with the values provided for your Streambased deployment. The `s3://` warehouse value is retained from the Streambased reference configuration; confirm the appropriate warehouse value for your deployment.

#### Configuration reference

| Property                                             | Description                                              |
| ---------------------------------------------------- | -------------------------------------------------------- |
| `spark.sql.catalog.isk`                              | Registers a Spark catalog named `isk`                    |
| `spark.sql.catalog.isk.type`                         | Specifies the Iceberg REST Catalog implementation        |
| `spark.sql.catalog.isk.uri`                          | Streambased Iceberg REST Catalog endpoint                |
| `spark.sql.catalog.isk.warehouse`                    | Warehouse identifier or location used by the catalog     |
| `spark.sql.catalog.isk.rest.sigv4-enabled`           | Enables SigV4 signing for REST catalog requests          |
| `spark.sql.catalog.isk.rest.signing-region`          | Region used when signing REST requests                   |
| `spark.sql.catalog.isk.rest.access-key-id`           | Streambased API key for catalog authentication           |
| `spark.sql.catalog.isk.rest.secret-access-key`       | Streambased secret key for catalog authentication        |
| `spark.sql.catalog.isk.io-impl`                      | Configures Iceberg to use S3FileIO                       |
| `spark.sql.catalog.isk.s3.endpoint`                  | Streambased S3-compatible storage endpoint               |
| `spark.sql.catalog.isk.s3.path-style-access`         | Enables path-style S3 access                             |
| `spark.sql.catalog.isk.s3.access-key-id`             | Streambased API key for storage access                   |
| `spark.sql.catalog.isk.s3.secret-access-key`         | Streambased secret key for storage access                |
| `spark.sql.catalog.isk.cache.expiration-interval-ms` | Sets the catalog cache expiration interval to 10 seconds |
| `spark.sql.extensions`                               | Enables Iceberg-specific Spark SQL extensions            |
| `spark.sql.defaultCatalog`                           | Sets `isk` as the default catalog                        |

### Step 3: Configure authentication and endpoints

Streambased ISK uses your Streambased API key and secret key to authenticate catalog and storage requests.

Unlike the Snowflake integration, which uses a concatenated bearer token, Spark uses the credentials separately in its SigV4 configuration.

#### REST Catalog endpoint

The REST Catalog endpoint handles metadata operations, such as discovering namespaces and tables.

For example:

```
spark.sql.catalog.isk.uri https://catalog.dev-us-west-2.streambased.cloud
```

Replace this value with the Iceberg REST Catalog endpoint for your Streambased deployment.

#### REST Catalog authentication

Configure SigV4 signing using your Streambased API credentials:

```
spark.sql.catalog.isk.rest.sigv4-enabled true
spark.sql.catalog.isk.rest.signing-region us-west-2
spark.sql.catalog.isk.rest.access-key-id sbpk_12345678
spark.sql.catalog.isk.rest.secret-access-key sbsk_12345678
```

The signing region must match the region configured for your Streambased deployment.

#### S3-compatible storage endpoint

Iceberg tables reference data files stored in object storage.

Configure Iceberg's S3FileIO implementation to access these files through Streambased's S3-compatible storage endpoint:

```
spark.sql.catalog.isk.io-impl org.apache.iceberg.aws.s3.S3FileIO
spark.sql.catalog.isk.s3.endpoint https://isk.dev-us-west-2.streambased.cloud
spark.sql.catalog.isk.s3.path-style-access true
```

Configure the corresponding storage credentials:

```
spark.sql.catalog.isk.s3.access-key-id sbpk_12345678
spark.sql.catalog.isk.s3.secret-access-key sbsk_12345678
```

The credentials above are examples only.

> **Security:** Do not commit API credentials to source control or expose them in application logs. For production deployments, use an appropriate secrets-management solution and restrict access to configuration files containing credentials.

### Step 4: Start Spark with the catalog configuration

Once the dependencies and configuration are in place, start a new Spark session.

If you configured the catalog through `spark-defaults.conf`, Spark will load the settings when a new application starts.

#### Using Spark SQL

Start an interactive SQL session:

```
spark-sql \
  --packages \
  org.apache.iceberg:iceberg-spark-runtime-3.5_2.12:1.9.2,org.apache.iceberg:iceberg-aws-bundle:1.9.2
```

If the dependencies are already installed at the cluster level, the `--packages` argument can be omitted.

#### Using PySpark

Alternatively, start an interactive PySpark session:

```
pyspark \
  --packages \
  org.apache.iceberg:iceberg-spark-runtime-3.5_2.12:1.9.2,org.apache.iceberg:iceberg-aws-bundle:1.9.2
```

You can also supply the configuration directly to individual applications using `--conf` arguments rather than modifying the cluster's default configuration.

> **Note:** Spark SQL extensions and catalog configuration should be applied when the Spark session is initialized. Restart your Spark application after making changes to these settings.

### Step 5: Verify the connection

Once Spark is running, verify that it can communicate with Streambased ISK.

#### List available namespaces

Run:

```
SHOW NAMESPACES IN isk;
```

This queries the Streambased Iceberg REST Catalog and returns the namespaces available to your credentials.

If the command succeeds, Spark can communicate with the catalog and retrieve metadata.

#### List tables in a namespace

Once you have identified a namespace, list its tables:

```
SHOW TABLES IN isk.hotset;
```

#### Query an Iceberg table

Finally, run a query against an available Iceberg table:

```
SELECT *
FROM isk.hotset.my_table
LIMIT 10;
```

Replace  `my_table` with the appropriate names.

If this query succeeds, Spark can access both the Iceberg catalog metadata and the underlying table data through Streambased's S3-compatible storage endpoint.

**\[Screenshot: Spark SQL session successfully listing namespaces and querying an Iceberg table]**

> **Tip:** Successfully listing namespaces confirms catalog connectivity, but does not necessarily confirm access to the underlying storage. Run a `SELECT` query to verify that your S3FileIO configuration is working.

### Step 6: Query Streambased tables

Your Spark cluster is now configured to use Streambased ISK as an Iceberg REST Catalog.

You can use Spark SQL to discover, explore, and query Iceberg tables.

#### Discover namespaces

```
SHOW NAMESPACES IN isk;
```

#### Discover tables

```
SHOW TABLES IN isk.hotset;
```

#### Query table data

```
SELECT *
FROM isk.hotset.my_table
WHERE event_date >= '2026-01-01'
LIMIT 100;
```

#### Query using PySpark

You can also access the same tables programmatically using the Spark DataFrame API:

```
from pyspark.sql import SparkSession

spark = SparkSession.builder.getOrCreate()

df = spark.table("isk.hotset.my_table")

df.show(10)
```

#### Use ISK as the default catalog

If you included the following configuration:

```
spark.sql.defaultCatalog isk
```

You can reference tables without specifying the catalog name:

```
SELECT *
FROM hotset.my_table
LIMIT 10;
```

The available operations depend on the permissions associated with your Streambased credentials and the capabilities exposed by your deployment.

### Troubleshooting

If you experience issues connecting Spark to Streambased ISK, check the following common problems.

| Issue                                        | Possible cause                                             | Resolution                                                                 |
| -------------------------------------------- | ---------------------------------------------------------- | -------------------------------------------------------------------------- |
| `ClassNotFoundException` for Iceberg classes | Missing or incompatible Iceberg libraries                  | Verify that the correct Iceberg Spark runtime and AWS bundle are installed |
| Spark session fails to initialize            | Invalid Spark configuration or incompatible extensions     | Check the Spark configuration and library versions                         |
| Authentication failure                       | Invalid API key or secret key                              | Verify that your Streambased credentials are correct                       |
| Catalog connection timeout                   | Incorrect REST Catalog endpoint or network restrictions    | Confirm that the endpoint is reachable from your Spark cluster             |
| Unable to list namespaces                    | Catalog authentication or SigV4 configuration issue        | Check the REST Catalog URI, credentials, and signing region                |
| Tables are visible but queries fail          | S3-compatible storage connectivity or authentication issue | Check the S3FileIO configuration, endpoint, and credentials                |
| S3 access errors                             | Incorrect storage endpoint or path-style configuration     | Verify the S3 endpoint and ensure path-style access is enabled             |
| Tables appear out of date                    | Cached catalog metadata                                    | Review the catalog cache expiration interval                               |

### Configuration summary

| Setting                   | Value                                          |
| ------------------------- | ---------------------------------------------- |
| Integration Type          | Apache Iceberg REST Catalog                    |
| Spark Catalog Name        | `isk`                                          |
| Catalog Implementation    | `org.apache.iceberg.spark.SparkCatalog`        |
| Catalog Type              | `rest`                                         |
| Catalog URI               | Your Streambased Iceberg REST Catalog endpoint |
| Authentication            | SigV4 using Streambased API key and secret key |
| Storage Implementation    | `org.apache.iceberg.aws.s3.S3FileIO`           |
| Storage Endpoint          | Your Streambased S3-compatible endpoint        |
| S3 Path-Style Access      | `true`                                         |
| Metadata Cache Expiration | `10000` milliseconds                           |
| Default Catalog           | `isk`                                          |
| Compute Environment       | Self-managed Apache Spark cluster              |

### Need help?

If you experience issues connecting Apache Spark to Streambased ISK, contact **Streambased Support**.

When raising a support request, include:

* Your Spark and Scala versions.
* Your Apache Iceberg version.
* Your Streambased deployment environment.
* The Iceberg REST Catalog endpoint.
* The S3-compatible storage endpoint.
* Any relevant Spark error messages or stack traces.

Do not include API keys, secret keys, or other sensitive credentials in support requests.
