Updating Spark Version
INFO
This guide is for the project maintainers.
This page outlines the work required to support a new Spark version in the codebase. Each Spark release may introduce features or incompatibilities with our scripts, so updating the codebase may require manual changes.
This page assumes that the Spark source code is available in the opt/spark directory, as described in Spark Setup.
Standard Procedures
Project Settings
Update the PySpark version pins in pyproject.toml.
- Update the
testoptional dependency when updating the latest supported Spark version. - Update the
defaultenvironment when updating the latest supported Spark version. - Update the
testenvironment when adding or updating a supported Spark minor version. - Update the
test-discoveryenvironment when updating the latest supported Spark version. - Update the
test-sparkenvironment when changing a Spark version used for parity tests. - Update the
test-ibisenvironment only when changing the Spark patch version used for Ibis tests, unless the Ibis version is also being updated.
When adding a Spark minor version, keep the existing versions in the test matrix and update its environment path and dependency overrides.
Spark Configuration
The scripts/spark-config/generate.py script collects Spark configuration into data files in crates/sail-spark-connect/data/config. The data files are used to generate the related Rust code.
In the project root directory, run a command like the following for each supported Spark minor version to update its configuration data file.
env SPARK_LOCAL_IP=127.0.0.1 \
hatch run test.spark-3.5.9:scripts/spark-config/generate.py \
-o crates/sail-spark-connect/data/config/spark-3.5.jsonUpdate crates/sail-spark-connect/build.rs when adding support for a new Spark minor version. Also update the runtime configuration selection in crates/sail-spark-connect/src/config.rs so that it recognizes the new version. Review configuration defaults and update the overrides in Sail if necessary.
Documentation
Please search for all mentions of Spark versions in the documentation in the docs directory and update them accordingly. Keep historical version references accurate, such as those in changelog entries and benchmark results.
GitHub Actions Workflows
Please search for all mentions of Spark versions in the GitHub Actions workflows in the .github directory and update them accordingly. Check build and test matrices, package artifacts, and test reports. Update related agent instructions as needed.
Spark Connect Protocol Buffers
When updating the latest supported Spark version, copy the .proto files from the corresponding Spark release tag to the crates/sail-spark-connect/proto directory. Make sure each file ends with a newline.
You may need to adjust the Rust code to work with the generated Spark Connect gRPC service code. Review new relation, expression, literal, and data type variants. Return an unsupported error for features that Sail does not implement yet.
Parity Tests
Update the parity test patch whenever changing a Spark version in the test-spark environment.
We build patched PySpark packages to run parity tests for the supported Spark major versions.
First, update the patch file. Here are example steps for updating from Spark 3.5.8 to 3.5.9.
- Create a branch
patch-v3.5.8from thev3.5.8tag. - Run
git -C opt/spark apply ../../scripts/spark-tests/spark-3.5.8.patchto apply the current patch. Commit the changes. - Create another branch
patch-v3.5.9from thev3.5.9tag. - Merge branch
patch-v3.5.8into branchpatch-v3.5.9and resolve any merge conflicts. - Run
git -C opt/spark diff -p v3.5.9 patch-v3.5.9 > scripts/spark-tests/spark-3.5.9.patchto generate the new patch. - Remove the old patch
scripts/spark-tests/spark-3.5.8.patch.
The patch must include all PySpark tests in the built package. Make sure the patched setup.py includes all test subpackages in the corresponding Spark version. Compare the package list against test directories containing __init__.py in the new release. Make sure the package also includes the required test data files. Verify that the generated patch applies cleanly to the unmodified release tag.
Run the following command to verify that the patched PySpark package can be built successfully for the new Spark version. The script builds Spark from source before packaging PySpark. Note that the command may take a long time to run. For example, in GitHub Actions, it takes about 30 minutes.
env SPARK_VERSION=3.5.9 scripts/spark-tests/build-pyspark.shGold Data
Update the gold data patch whenever changing the Spark version used by scripts/spark-gold-data/bootstrap.sh. Also update the Spark checkout tag in .github/workflows/gold-data-script-validation.yml.
First, update the patch file. Here are example steps for updating from Spark 3.5.8 to 3.5.9.
- Create a branch
gold-patch-v3.5.8from thev3.5.8tag. - Run
git -C opt/spark apply ../../scripts/spark-gold-data/spark-3.5.8.patchto apply the current patch. Commit the changes. - Create another branch
gold-patch-v3.5.9from thev3.5.9tag. - Merge branch
gold-patch-v3.5.8into branchgold-patch-v3.5.9and resolve any merge conflicts. - Run
git -C opt/spark diff -p v3.5.9 gold-patch-v3.5.9 > scripts/spark-gold-data/spark-3.5.9.patchto generate the new patch. - Remove the old patch
scripts/spark-gold-data/spark-3.5.8.patch.
Then update the Spark version mentioned in scripts/spark-gold-data/bootstrap.sh.
In the project root directory, run the following command to collect test cases from the Spark project. This rewrites the gold data files with the new test input only.
scripts/spark-gold-data/bootstrap.shThe command requires the JAVA_HOME environment variable to be set. On macOS, you can specify the Java installation path in the following way.
env JAVA_HOME="$(/usr/libexec/java_home)" scripts/spark-gold-data/bootstrap.shThen generate the Sail test output using the following command.
env SAIL_UPDATE_GOLD_DATA=1 cargo testValidation
Run the project formatting and linting checks and rebuild the native extension before testing. Run the Spark session, configuration, UDF, and UDTF tests with the new version. When changing code shared by multiple Spark versions, also run the relevant tests with older supported versions.
Verify that tests can be collected with all supported Spark versions and without building the native extension. Build the documentation after updating it.
Non-standard Procedures
Review changes to the PySpark UDF and UDTF code in worker.py and related Spark files. Check how function payloads are loaded and how inputs and outputs are converted. Update version checks and compatibility code in Sail accordingly.
Review integration dependencies that require a particular Spark version. Update the dependencies or test version requirements as needed.
Review the patch files closely, especially if they are edited directly after being generated. Patch files edited manually can have incorrect line numbers or file hashes even if the patch applies cleanly. It is recommended to generate the patch again using only git commands (git apply and git diff) to ensure the patch is correct.
