> For the complete documentation index, see [llms.txt](https://docs.e6data.com/query-engine/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.e6data.com/query-engine/developers/pyspark-compatibility.md).

# PySpark compatibility

Run existing PySpark and Apache Sedona code on e6data with a drop-in compatibility library - install, configure the connection, and run.

`e6-spark-compat` is a drop-in compatibility library that lets you run existing PySpark and Apache Sedona code on e6data. Update your import statements, configure the e6data connection, and your Spark code works as-is - no rewrites needed.

DataFrame operations are lazily evaluated: transformations build a query-plan tree, and when an action (`collect`, `show`, `count`) is called, the plan is translated into optimized SQL and executed on e6data.

## Key capabilities

* Full PySpark DataFrame API - `select`, `filter`, `join`, `groupBy`, `orderBy`, `union`, `pivot`, and more.
* 130+ SQL functions - string, math, aggregate, date/time, window, conditional.
* Window functions with the complete `Window` specification API.
* 70+ Apache Sedona-compatible spatial functions (`ST_*`).
* File format support - Parquet, ORC, CSV, JSON, GeoParquet, Delta.
* Read and write operations.

See [Supported APIs and compatibility notes](/query-engine/developers/pyspark-compatibility/supported-apis-and-compatibility.md) for the full list, and [Limitations](/query-engine/developers/pyspark-compatibility/limitations.md) for what isn't supported.

## Prerequisites

* An active e6data workspace and cluster.
* A [personal access token](/query-engine/guides/security/access-tokens/pat-and-service-account-keys.md) from the e6data Console (**User settings → Access tokens**).
* Python 3.8+.

## Installation

```bash
# Install from PyPI
pip install e6data-spark-compatibility

# With spatial support
pip install e6data-spark-compatibility[spatial]
```

## Getting started

Migrate a PySpark application to e6data in three steps: update imports, configure the connection, and run.

### Step 1: Update imports

Replace your PySpark imports with `e6-spark-compat` equivalents. The API is identical.

{% tabs %}
{% tab title="Before (PySpark)" %}

```python
from pyspark.sql import SparkSession
from pyspark.sql.functions import col, upper, count, sum, row_number
from pyspark.sql.window import Window
```

{% endtab %}

{% tab title="After (e6data)" %}

```python
from e6_spark_compat import SparkSession
from e6_spark_compat.sql.functions import col, upper, count, sum, row_number
from e6_spark_compat.sql.window import Window
```

{% endtab %}
{% endtabs %}

For spatial (Sedona) operations, replace `from sedona.register import SedonaRegistrator` with `from e6_spark_compat.sedona import SedonaRegistrator`.

### Step 2: Configure the connection

Create a `SparkSession` pointing to your e6data cluster.

```python
spark = (SparkSession.builder
    .appName("MyApp")
    .config("spark.e6data.host", "<cluster-host>")
    .config("spark.e6data.username", "<username>")
    .config("spark.e6data.password", "<access-token>")
    .config("spark.e6data.database", "<database>")
    .config("spark.e6data.catalog", "<catalog>")
    .config("spark.e6data.cluster", "<cluster-name>")
    .config("spark.e6data.secure", True)
    .getOrCreate())
```

| Parameter               | Description                                   | Required |
| ----------------------- | --------------------------------------------- | -------- |
| `spark.e6data.host`     | Cluster hostname or IP address                | Yes      |
| `spark.e6data.username` | e6data account email                          | Yes      |
| `spark.e6data.password` | Personal access token from the e6data Console | Yes      |
| `spark.e6data.database` | Target database name                          | Yes      |
| `spark.e6data.catalog`  | Catalog name                                  | Yes      |
| `spark.e6data.cluster`  | Cluster name                                  | Yes      |
| `spark.e6data.secure`   | Use TLS (`True` or `False`). Default `True`   | No       |

{% hint style="info" %}
Find your cluster hostname and connection details in the e6data Console under **Clusters → Connection Info**.
{% endhint %}

{% hint style="warning" %}
Don't hardcode your access token in source code. Use environment variables or a secrets manager - for example, `os.getenv("E6DATA_TOKEN")`.
{% endhint %}

### Step 3: Run your code

Your existing PySpark logic works without modification:

```python
df = spark.read.parquet("s3://bucket/path/to/data.parquet")

result = (df.filter(col("age") > 21)
    .select("name", "city", "salary")
    .groupBy("city")
    .agg(count("*").alias("total"), sum("salary").alias("total_salary"))
    .orderBy(col("total").desc()))

result.show()   # action triggers execution on e6data
```

## Catalog operations

Discover databases, tables, and columns programmatically:

```python
spark.catalog.listDatabases()
spark.catalog.listTables()
spark.catalog.listColumns("my_table")
spark.catalog.tableExists("my_table")
```

Close the session with `spark.stop()`.

## See also

* [Supported APIs and compatibility notes](/query-engine/developers/pyspark-compatibility/supported-apis-and-compatibility.md)
* [Limitations](/query-engine/developers/pyspark-compatibility/limitations.md)
* [Access tokens](/query-engine/guides/security/access-tokens.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.e6data.com/query-engine/developers/pyspark-compatibility.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
