Title
Page icon
Create new category
Edit page index title
Edit category
Edit link
Spark 4 Connect
Spark 4.1 Connect is available with ODP 3.3.6.5. Spark 4 Connect differs from Spark 3.5.5 Connect in its default port, client installation, Scala version, configuration paths, and Ambari configuration.
For information about Spark 3.5.5 Connect, see Spark Connect.
Spark 4 Connect configuration
The following table compares the Spark 3.5.5 and Spark 4.1.1 Connect configurations.
Configuration | Spark 3.5.5 | Spark 4.1.1 |
|---|---|---|
Server component | Spark3 Connect |
|
Default gRPC port |
|
|
Default bind address |
| Loopback when the binding address is empty |
Scala binary version | 2.12 | 2.13 |
Mpack configuration file |
|
|
Host configuration file |
|
|
Ambari configuration | Spark3 > Advanced spark-connect | Spark4 > Advanced spark4-connect |
Log directory |
|
|
Server log prefix |
|
|
Install the Spark 4 Connect client
For Spark 4.1.1, don't install the Connect client by using pip install pyspark[connect]==4.1.1. This command downloads the full PySpark package, including the JVM JAR files.
Instead, install the lightweight PySpark client and Spark Connect packages provided for ODP.
Prerequisites
Ensure that Python 3.9 or later is installed on the client system.
Install the Python client
Create and activate a Python virtual environment:
python3 -m venv ~/spark4-connect source ~/spark4-connect/bin/activate pip install --upgrade pipInstall the PySpark client package:
pip install https://mirror-stg.odp.acceldata.dev/staging/OCR-2426/pyspark-client-4.1.1.tar.gzInstall the Spark Connect package:
pip install https://mirror-stg.odp.acceldata.dev/staging/OCR-2426/pyspark-connect-4.1.1.tar.gzVerify the installation:
python -c "import pyspark; print(pyspark.__version__)"The command returns:
4.1.1
The combined installation requires approximately 30 MB, including dependencies such as NumPy, pandas, PyArrow, and gRPC.
Configure a Scala client
Spark 4.1.1 uses Scala 2.13. For Maven-based applications, add the following dependency:
Connect to the Spark 4 Connect server
The default Spark 4 Connect gRPC port is 15005.
Python
Use the following example to connect from a Python client:
Scala
Use the following example to connect from a Scala client:
Important: Spark 4 Connect uses port
15005. Spark 3.5.5 Connect uses port15002.
Use distributed storage for file operations
Use a distributed file system, such as HDFS, S3, ABFS, or GCS, for files accessed by Spark Connect workloads.
Avoid using file:// paths for distributed Spark workloads. Local file paths are resolved on the host where the Spark process or executor accesses the file and might not refer to the client system.
For example, use:
instead of:
Known issues and limitations
The following issues apply to Spark 4.1.1 with the ODP 3.3.6.5 Mpack.
Spark Connect binds to the loopback address by default
The spark4-connect configuration includes the following default settings:
When spark.connect.grpc.binding.address is empty, the Spark Connect server binds to the loopback address. As a result, remote clients can't connect to the server.
Configure remote client access
To allow remote clients to connect:
In Ambari, go to Services > Spark4 > Configs.
Expand Advanced spark4-connect.
Set
spark.connect.grpc.binding.addressto:0.0.0.0Save the configuration.
Restart the Spark Connect Server component.
Security: Binding the service to
0.0.0.0makes it reachable on all available network interfaces. Ensure that network access to port15005is restricted to trusted clients.
Use an SSH tunnel
If you don't want to expose the Spark Connect server on a network interface, create an SSH tunnel from the client:
Then connect to:
An empty authentication token can cause authentication failures
In the Spark 4.1.1 build included with ODP 3.3.6.5, the Spark Connect authentication interceptor can be enabled when spark.connect.authenticate.token is present, even when the property has an empty value.
Clients can then fail with the following error:
Use one of the following configurations.
Disable token authentication
If token authentication isn't required, remove the spark.connect.authenticate.token property from Advanced spark4-connect in Ambari, and then restart the Spark Connect Server.
Alternatively, configure spark.connect.grpc.interceptor.classes so that the authentication interceptor isn't loaded.
Configure token authentication
If authentication is required:
Set
spark.connect.authenticate.tokento a nonempty token.Restart the Spark Connect Server.
Configure clients to provide the token:
spark = SparkSession.builder.remote( "sc://<connect-host>:15005/;token=<token>" ).getOrCreate()
Important: PySpark 4.1 automatically enables TLS on the client when a token is included in the connection URL. Configure TLS on the Spark Connect server before using token authentication. Otherwise, the TLS handshake can fail.
spark-connect-shell requires an interactive terminal
The following command wraps the Ammonite REPL:
The shell requires an interactive terminal. Noninteractive methods such as piping a heredoc, using -i with a Scala script, or running the shell with nohup aren't supported.
For noninteractive Scala Spark Connect workloads, build an application with the following client dependency:
Then run the compiled application as a standard Scala application.
--remote conflicts with the configured Spark master
The Spark4 client configuration can define:
If you run the following command while spark.master is defined:
Spark returns the following error:
As a workaround, set SPARK_CONF_DIR to a configuration directory whose spark-defaults.conf doesn't define spark.master, and then start spark-connect-shell.
Parquet writes can fail
Parquet writes in Spark 4.1.1 with the ODP 3.3.6.5 build can fail with the following error:
This issue affects Spark 4.1.1 generally and isn't specific to Spark Connect.
ORC, CSV, and JSON writes are supported. Until the Parquet issue is resolved, use ORC or another supported format when possible.
Spark Connect server runs in local mode by default
The Ambari-managed Spark Connect server starts in local mode by default. Therefore, processing doesn't scale beyond the server host.
To use YARN for Spark Connect workloads:
Ensure that the
sparkuser has permission to submit applications to the required YARN queue.Configure the Spark Connect server to use:
--master yarn --deploy-mode clientRestart the Spark Connect Server.
Note: YARN queue permissions might need to be configured in Ranger before the Spark Connect server can submit applications.
Spark 4 Connect configuration reference
Configure Spark 4 Connect properties in Spark4 > Configs > Advanced spark4-connect.
Property | Recommended value | Description |
|
| Allows remote clients to connect to the Spark Connect server. |
|
| Specifies the Spark 4 Connect gRPC port. |
| Remove the property when authentication isn't required, or specify a nonempty token and configure TLS | Controls Spark Connect token authentication. |
|
| Retains the default setting when Spark authentication isn't required. |
Spark Connect version compatibility
Spark version | Python client | Scala client artifact | Default port | ODP configuration |
Spark 3.5.5 |
|
|
|
|
Spark 4.1.1 |
|
|
|
|
Validation
Spark 4 Connect was validated with ODP 3.3.6.5 for the following scenarios:
PySpark Connect from an ODP cluster host.
PySpark Connect from a remote client to the cluster.
Cross-client access to data written from the cluster.
ORC, CSV, and JSON read and write operations.
Related information
For Spark 3.5.5 Connect configuration and usage, see Spark Connect.