Skip to content

[GH-3338] Support Spark 4.x in the R interface - #3340

Merged
jiayuasu merged 3 commits into
apache:masterfrom
jiayuasu:fix/r-spark4-support
Sep 10, 2026
Merged

jiayuasu merged 3 commits into
apache:masterfrom
jiayuasu:fix/r-spark4-support

Conversation

@jiayuasu

@jiayuasu jiayuasu commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

Did you read the Contributor Guide?

Is this PR related to a ticket?

What changes were proposed in this PR?

spark_dependencies() in R/R/dependencies.R only accepted Spark major version 3 and defaulted the Scala suffix to 2.12, so spark_connect() on Spark 4.x failed with Unsupported Spark version: 4.0 before any jar or Maven coordinate was considered.

  • Accept Spark 4.x and pin its Scala suffix to 2.13. Pinning is deliberate: sparklyr 1.9.5 hands every extension scala_version = "2.12" for any Spark release at or above 3.0, so honouring that value would request the non-existent sedona-spark-shaded-4.0_2.12. Spark 4 and Sedona's Spark 4 artifacts are Scala 2.13 only. Spark 3.x keeps the previous behaviour (2.12 unless a Scala version is passed), and Spark 2.x and earlier are still rejected.
  • R/DESCRIPTION: SystemRequirements now reads Spark 3.x or 4.x.
  • R/tests/testthat/test-dependencies.R: unit tests for the artifact selection (Spark 3.5 -> 3.5_2.12; Spark 4.0 with 2.12 passed in -> 4.0_2.13; Spark 4.1 -> 4.1_2.13; Spark 2.4 rejected; SEDONA_JAR_FILES swaps the Sedona coordinate for local jars). They run without a Spark connection.
  • .github/workflows/r.yml: list the matrix explicitly, one entry per Spark/Scala/Java/R combination like the Java and Python workflows, and add Spark 4.0.2 and 4.1.1 (Scala 2.13.16, Java 17) so the R test suite also runs on Spark 4.
  • R/R/spatial_queries.R: the sparklyr backend for Spark 3 unwraps java.util.List results that wrap a Scala Seq (JavaRDD.take(), collect(), KNNQuery) into R lists, while the backend for Spark 4 returns them as a single Java object. sedona_knn_query() and sedona_range_query() now convert on the JVM side with toArray, so result_type = "raw" returns an R list of geometries on both backends, and the KNN result RDD is built from the Java list directly when that is what came back. Two tests that index take() / takeOrdered() results now call toArray like the neighbouring tests already do.

How was this patch tested?

  • The new unit tests pass locally.
  • First CI run on Spark 4.0.2: the package check, the 4.0_2.13 build and the connection worked; 6 of 267 tests failed because of the Java list serialisation difference described above, which the second commit addresses.
  • On EMR release emr-spark-8.0.0 (Spark 4.0.2, Scala 2.13.16, Java 17) with sparklyr 1.9.5: the CRAN 1.9.1 package fails with Unsupported Spark version: 4.0. With this patch installed from source, spark_connect(master = "yarn", spark_home = "/usr/lib/spark") connects both with SEDONA_JAR_FILES pointing at sedona-spark-shaded-4.0_2.13-1.9.1.jar and with it unset, in which case Maven resolves org.apache.sedona:sedona-spark-shaded-4.0_2.13:1.9.1. ST_Point, ST_Transform and an executor-side aggregation over 100k points return correct results.
  • Spark 3.5 behaviour was re-checked on EMR 7.9.0 (Spark 3.5.5) and is unchanged.
  • The new CI matrix entry runs the full R test suite on Spark 4.0.2 as part of this PR.

Did this PR include necessary documentation updates?

  • No, this PR does not affect any public API so no need to change the documentation.

spark_dependencies() only accepted Spark major version 3 and defaulted
the Scala suffix to 2.12, so spark_connect() on Spark 4.x stopped with
"Unsupported Spark version" before any jar was considered.

Accept Spark 4.x and pin its Scala suffix to 2.13: Spark 4 and Sedona
Spark 4 artifacts are Scala 2.13 only, while sparklyr still hands
extensions 2.12 for every Spark release at or above 3.0. Add unit tests
for the artifact selection and a Spark 4.0.2 / Java 17 entry to the R
CI matrix.
…ackend

The sparklyr backend for Spark 3 unwraps java.util.List results that wrap
a Scala Seq (JavaRDD.take/collect, KNNQuery) into R lists; the backend for
Spark 4 hands them back as a single Java object. Normalise on the JVM
side with toArray so sedona_knn_query() and sedona_range_query() return
the same shape on both, accept an already-Java list when building the
result RDD, and make the two tests that index take()/takeOrdered()
results use toArray like the neighbouring tests already do.
@jiayuasu jiayuasu added this to the sedona-2.0.0 milestone Sep 10, 2026
Use one include entry per Spark/Scala/Java/R combination, as the Java
and Python workflows do, instead of a cross product patched with an
extra entry. Add Spark 4.1.1 alongside 4.0.2 and fold the constant
Hadoop version into the job environment.
@jiayuasu
jiayuasu merged commit 4045a0f into apache:master Sep 10, 2026
16 checks passed
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.

R interface rejects Spark 4.x with "Unsupported Spark version"

1 participant