-
Notifications
You must be signed in to change notification settings - Fork 17.4k
Add Scala Spark ETL example to Java-SDK e2e tests #68939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jason810496
merged 5 commits into
apache:main
from
jason810496:ci/java-sdk/add-scala-spark-example
Jul 1, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8dad3bd
Add Scala Spark ETL example bundle to the Java SDK e2e tests
jason810496 00c5ae2
Avoid copying jars for docker build
jason810496 f46122a
Verify the Scala Spark transform stage in the Java-SDK e2e test
jason810496 05770a1
Carry Spark's full Java 17 module options in the Scala Spark e2e test
jason810496 0a2f586
Standardize Scala Spark example layout and document Spark JVM options
jason810496 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| <!-- | ||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, | ||
| software distributed under the License is distributed on an | ||
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations | ||
| under the License. | ||
| --> | ||
|
|
||
| # Scala Spark example bundle | ||
|
|
||
| A Scala + Apache Spark bundle for the Java SDK, exercised by the `java_sdk` | ||
| end-to-end test. It shows a non-Java JVM language driving Spark from a | ||
| `@task.stub` task and routing Log4j 2 logs into Airflow via `airflow-sdk-log4j2`. | ||
|
|
||
| The `scala_spark_example` Dag chains three tasks, each running in its own JVM | ||
| with a local `SparkSession` and passing scalar results over XCom: | ||
|
|
||
| - `spark_extract` - builds a DataFrame, pushes its row count. | ||
| - `spark_transform` - aggregates total revenue. | ||
| - `spark_load` - returns the persisted total. | ||
|
|
||
| ## Build | ||
|
|
||
| ```bash | ||
| # From java-sdk/: publish the SDK to the local Maven repository first. | ||
| ./gradlew publishToMavenLocal -PskipSigning=true | ||
|
|
||
| cd scala_spark_example | ||
| ../gradlew bundle | ||
| ``` | ||
|
|
||
| `fatJar` is disabled, so `build/bundle/` holds the bundle JAR plus every runtime | ||
| JAR (Spark included) — copy it into a Java coordinator's `jars_root`. | ||
|
|
||
| ## Running Spark under the Java SDK | ||
|
|
||
| Spark on Java 17 needs a set of `--add-opens` / `--add-exports` options that open | ||
| internal JDK modules (reflection, NIO, the off-heap cleaner, Kerberos, ...) to | ||
| Spark. `spark-submit` and the `SparkSession` builder inject these through Spark's | ||
| own launcher, but the Java SDK's `JavaCoordinator` starts the bundle JVM directly | ||
| and bypasses that launcher, so the coordinator has to pass them itself via | ||
| `jvm_args`: | ||
|
|
||
| ```json | ||
| { | ||
| "scala-jdk": { | ||
| "classpath": "airflow.sdk.coordinators.java.JavaCoordinator", | ||
| "kwargs": { | ||
| "jars_root": ["/path/to/scala-jars"], | ||
| "main_class": "org.apache.airflow.example.ScalaSparkBundleBuilder", | ||
| "jvm_args": [ | ||
| "-Xmx512m", | ||
| "-XX:+IgnoreUnrecognizedVMOptions", | ||
| "--add-opens=java.base/java.lang=ALL-UNNAMED", | ||
| "--add-opens=java.base/jdk.internal.ref=ALL-UNNAMED", | ||
| "--add-opens=java.base/sun.nio.ch=ALL-UNNAMED" | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| The full list mirrors `org.apache.spark.launcher.JavaModuleOptions` for the Spark | ||
| version pinned in `build.gradle`. Spark may add or drop openings between releases, | ||
| so revisit it whenever you bump Spark. The end-to-end test keeps the authoritative, | ||
| complete copy in `airflow-e2e-tests/tests/airflow_e2e_tests/conftest.py` | ||
| (`_SPARK_JAVA_MODULE_OPTIONS`). |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.