| commit | 2d220645087e2860ed7539dc89c5174098f4c5ad | [log] [tgz] |
|---|---|---|
| author | yangjie01 <yangjie01@baidu.com> | Wed Oct 15 10:31:12 2025 +0800 |
| committer | yangjie01 <yangjie01@baidu.com> | Wed Oct 15 10:31:12 2025 +0800 |
| tree | 42bcf2deecd8542a3a55cff0a3dca7bc584c6a6b | |
| parent | 9ae819840bbf2f6c8fc8e7d978c89f3d11b57b05 [diff] |
[SPARK-53897][CONNECT][TESTS] Add dependency checks for Python-related tests in the `connect` module
### What changes were proposed in this pull request?
This pr adds a pre-check for module dependencies to the test cases in the `connect` module that utilize Python client code. This ensures that when the required Python modules are missing, the relevant tests are skipped rather than failing.
### Why are the changes needed?
Some test cases in the `connect` module involve interactions between Python client code and the Connect server. These tests currently fail due to the absence of the required Python modules.
`build/sbt 'connect/test'`
```
[info] - Pipeline with selective full_refresh *** FAILED *** (374 milliseconds)
[info] java.lang.RuntimeException: Pipeline update process failed with exit code 1.
[info] Output:
[info] Error: Traceback (most recent call last):
[info] File "/Users/yangjie01/SourceCode/git/spark-sbt/python/pyspark/sql/connect/utils.py", line 47, in require_minimum_grpc_version
[info] import grpc
[info] ModuleNotFoundError: No module named 'grpc'
[info]
[info] The above exception was the direct cause of the following exception:
[info]
[info] Traceback (most recent call last):
[info] File "/Users/yangjie01/SourceCode/git/spark-sbt/python/pyspark/pipelines/cli.py", line 36, in <module>
[info] from pyspark.pipelines.block_session_mutations import block_session_mutations
[info] File "/Users/yangjie01/SourceCode/git/spark-sbt/python/pyspark/pipelines/block_session_mutations.py", line 21, in <module>
[info] from pyspark.sql.connect.catalog import Catalog
[info] File "/Users/yangjie01/SourceCode/git/spark-sbt/python/pyspark/sql/connect/catalog.py", line 20, in <module>
[info] check_dependencies(__name__)
[info] File "/Users/yangjie01/SourceCode/git/spark-sbt/python/pyspark/sql/connect/utils.py", line 37, in check_dependencies
[info] require_minimum_grpc_version()
[info] File "/Users/yangjie01/SourceCode/git/spark-sbt/python/pyspark/sql/connect/utils.py", line 49, in require_minimum_grpc_version
[info] raise PySparkImportError(
[info] pyspark.errors.exceptions.base.PySparkImportError: [PACKAGE_NOT_INSTALLED] grpcio >= 1.48.1 must be installed; however, it was not found.
...
raceback (most recent call last):
File "/Users/yangjie01/SourceCode/git/spark-sbt/python/pyspark/sql/connect/utils.py", line 47, in require_minimum_grpc_version
import grpc
ModuleNotFoundError: No module named 'grpc'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/yangjie01/SourceCode/gravitino/.gradle/python/MacOSX/Miniforge3/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/Users/yangjie01/SourceCode/gravitino/.gradle/python/MacOSX/Miniforge3/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/Users/yangjie01/SourceCode/git/spark-sbt/python/pyspark/sql/connect/streaming/worker/foreach_batch_worker.py", line 32, in <module>
from pyspark.sql.connect.session import SparkSession
File "/Users/yangjie01/SourceCode/git/spark-sbt/python/pyspark/sql/connect/session.py", line 20, in <module>
check_dependencies(__name__)
File "/Users/yangjie01/SourceCode/git/spark-sbt/python/pyspark/sql/connect/utils.py", line 37, in check_dependencies
require_minimum_grpc_version()
File "/Users/yangjie01/SourceCode/git/spark-sbt/python/pyspark/sql/connect/utils.py", line 49, in require_minimum_grpc_version
raise PySparkImportError(
pyspark.errors.exceptions.base.PySparkImportError: [PACKAGE_NOT_INSTALLED] grpcio >= 1.48.1 must be installed; however, it was not found.
[info] - python foreachBatch process: process terminates after query is stopped *** FAILED *** (14 seconds, 188 milliseconds)
[info] org.apache.spark.SparkException: Python worker failed to connect back.
...
[info] *** 48 TESTS FAILED ***
[error] Failed tests:
[error] org.apache.spark.sql.connect.pipelines.PythonPipelineSuite
[error] org.apache.spark.sql.connect.pipelines.EndToEndAPISuite
[error] org.apache.spark.sql.connect.service.SparkConnectSessionHolderSuite
[error] (connect / Test / test) sbt.TestsFailedException: Tests unsuccessful
```
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
- Pass Github Actions
- Manually verified by running `build/sbt 'connect/test'`
```
[info] - temporary views works !!! CANCELED !!! (0 milliseconds)
[info] org.apache.spark.sql.connect.PythonTestDepsChecker.isConnectDepsAvailable was false (PythonPipelineSuite.scala:52)
...
[info] - create named flow with multipart name will fail !!! CANCELED !!! (1 millisecond)
[info] org.apache.spark.sql.connect.PythonTestDepsChecker.isConnectDepsAvailable was false (PythonPipelineSuite.scala:521)
...
[info] - create flow with multipart target and no explicit name succeeds !!! CANCELED !!! (1 millisecond)
[info] org.apache.spark.sql.connect.PythonTestDepsChecker.isConnectDepsAvailable was false (PythonPipelineSuite.scala:52)
...
[info] Run completed in 3 minutes, 27 seconds.
[info] Total number of tests run: 1088
[info] Suites: completed 37, aborted 0
[info] Tests: succeeded 1088, failed 0, canceled 45, ignored 0, pending 0
[info] All tests passed.
```
### Was this patch authored or co-authored using generative AI tooling?
No
Closes #52588 from LuciferYang/connect-py-tests.
Authored-by: yangjie01 <yangjie01@baidu.com>
Signed-off-by: yangjie01 <yangjie01@baidu.com>
Spark is a unified analytics engine for large-scale data processing. It provides high-level APIs in Scala, Java, Python, and R (Deprecated), and an optimized engine that supports general computation graphs for data analysis. It also supports a rich set of higher-level tools including Spark SQL for SQL and DataFrames, pandas API on Spark for pandas workloads, MLlib for machine learning, GraphX for graph processing, and Structured Streaming for stream processing.
You can find the latest Spark documentation, including a programming guide, on the project web page. This README file only contains basic setup instructions.
| Branch | Status |
|---|---|
| master | |
| branch-4.0 | |
| branch-3.5 | |
Spark is built using Apache Maven. To build Spark and its example programs, run:
./build/mvn -DskipTests clean package
(You do not need to do this if you downloaded a pre-built package.)
More detailed documentation is available from the project site, at “Building Spark”.
For general development tips, including info on developing Spark using an IDE, see “Useful Developer Tools”.
The easiest way to start using Spark is through the Scala shell:
./bin/spark-shell
Try the following command, which should return 1,000,000,000:
scala> spark.range(1000 * 1000 * 1000).count()
Alternatively, if you prefer Python, you can use the Python shell:
./bin/pyspark
And run the following command, which should also return 1,000,000,000:
>>> spark.range(1000 * 1000 * 1000).count()
Spark also comes with several sample programs in the examples directory. To run one of them, use ./bin/run-example <class> [params]. For example:
./bin/run-example SparkPi
will run the Pi example locally.
You can set the MASTER environment variable when running examples to submit examples to a cluster. This can be spark:// URL, “yarn” to run on YARN, and “local” to run locally with one thread, or “local[N]” to run locally with N threads. You can also use an abbreviated class name if the class is in the examples package. For instance:
MASTER=spark://host:7077 ./bin/run-example SparkPi
Many of the example programs print usage help if no params are given.
Testing first requires building Spark. Once Spark is built, tests can be run using:
./dev/run-tests
Please see the guidance on how to run tests for a module, or individual tests.
There is also a Kubernetes integration test, see resource-managers/kubernetes/integration-tests/README.md
Spark uses the Hadoop core library to talk to HDFS and other Hadoop-supported storage systems. Because the protocols have changed in different versions of Hadoop, you must build Spark against the same version that your cluster runs.
Please refer to the build documentation at “Specifying the Hadoop Version and Enabling YARN” for detailed guidance on building for a particular distribution of Hadoop, including building for particular Hive and Hive Thriftserver distributions.
Please refer to the Configuration Guide in the online documentation for an overview on how to configure Spark.
Please review the Contribution to Spark guide for information on how to get started contributing to the project.