Skip to content

[GH-3522] Make sedona.spark importable on pyspark-client (Spark Connect only) - #3523

Merged
jiayuasu merged 1 commit into
apache:masterfrom
james-willis:connect-only-import
Nov 7, 2026
Merged

jiayuasu merged 1 commit into
apache:masterfrom
james-willis:connect-only-import

Conversation

@james-willis

Copy link
Copy Markdown
Collaborator

Did you read the Contributor Guide?

Is this PR related to a ticket?

What changes were proposed in this PR?

pyspark-client, the Spark Connect-only distribution of PySpark (4.0+), ships no RDD API, SparkContext or py4j. sedona.spark imported all three at module level, so from sedona.spark import * failed there (No module named 'py4j'), although SedonaContext and the DataFrame functions already support Spark Connect.

  • sedona/spark/__init__.py: the RDD-API exports (SpatialRDD and friends, the readers, the spatial queries, Adapter, StructuredAdapter) are imported only when pyspark.util.is_remote_only() is false, the check PySpark itself uses in its own __init__; everything else stays exported. On PySpark < 4.0, which has no is_remote_only, nothing changes.
  • sedona/spark/core/__init__.py: RangeQueryRaw is resolved lazily (PEP 562 module __getattr__), so the pure-Python geometries and enums under core no longer pull in the RDD API. from sedona.spark.core import RangeQueryRaw still works.
  • sql/dataframe_api.py, register/geo_registrator.py: SparkContext and py4j are imported where the JVM path runs, not at module level.
  • utils/binary_parser.py: SparkContext was an annotation only; it moves under TYPE_CHECKING.
  • Docs: install-python.md and cluster.md say pyspark-client is supported and that the RDD API is not available with it.

Nothing changes for the full pyspark: the same names are exported, in the same order.

How was this patch tested?

  • New python/tests/connect_only/test_import.py (skips unless is_remote_only()): sedona.spark imports and exports the DataFrame API names; from sedona.spark import * works and does not export PointRDD; SedonaContext.builder() is SparkSession.Builder with the Kryo options; sedona.spark.core.RangeQueryRaw resolves lazily and fails with ImportError where the RDD API is absent.
  • New CI step in python.yml for the Spark 4.x matrix entries: uninstall pyspark, install pyspark-client==<spark>, assert is_remote_only(), run tests/connect_only.
  • Locally: a venv with pyspark-client==4.1.1 and this branch: the 4 tests pass; before the change import sedona.spark fails as in the issue.
  • The existing suites run unchanged in CI under the full pyspark, where the tests skip.

Did this PR include necessary documentation updates?

  • Yes, I have updated the documentation.

… Connect only)

pyspark-client, the Spark Connect-only distribution of PySpark (4.0+), ships no RDD API, SparkContext or py4j. sedona.spark imported all three at module level, so 'from sedona.spark import *' failed there with ModuleNotFoundError: No module named 'py4j', although SedonaContext and the DataFrame functions already support Spark Connect.

- sedona.spark: the RDD-API exports (SpatialRDD and friends, the readers, the spatial queries, Adapter, StructuredAdapter) are imported only when pyspark.util.is_remote_only() is false, the check pyspark itself uses; everything else stays exported.
- sedona.spark.core: RangeQueryRaw is resolved lazily (PEP 562), so the pure-Python geometries and enums under core no longer pull in the RDD API.
- sql.dataframe_api, register.geo_registrator: SparkContext and py4j are imported where the JVM path runs.
- utils.binary_parser: SparkContext was an annotation only.
- tests/connect_only and a CI step that installs pyspark-client (Spark 4.x matrix entries) and runs them; they skip under the full pyspark.
- docs: note pyspark-client support and what is not available with it.
@james-willis
james-willis marked this pull request as ready for review November 6, 2026 22:01
@jiayuasu
jiayuasu merged commit 0a61b7d into apache:master Nov 7, 2026
35 checks passed
@jiayuasu jiayuasu added this to the sedona-2.0.0 milestone Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sedona.spark does not import on pyspark-client (Spark Connect only): No module named 'py4j'

2 participants