commit | 3e2b146eb81d9a5727f07b58f7bb1760a71a8697 | [log] [tgz] |
---|---|---|
author | Vsevolod Stepanov <vsevolod.stepanov@databricks.com> | Wed Oct 25 21:35:07 2023 -0400 |
committer | Herman van Hovell <herman@databricks.com> | Wed Oct 25 21:35:07 2023 -0400 |
tree | bbb7bc62e0f774e0ade58b87eae08d9ee2d4861f | |
parent | 0219eb5984f0f4a7209deb091b713ded10aebba3 [diff] |
[SPARK-45136][CONNECT] Enhance ClosureCleaner with Ammonite support ### What changes were proposed in this pull request? This PR enhances existing ClosureCleaner implementation to support cleaning closures defined in Ammonite. Please refer to [this gist](https://gist.github.com/vsevolodstep-db/b8e4d676745d6e2d047ecac291e5254c) to get more context on how Ammonite code wrapping works and what problems I'm trying to solve here. Overall, it contains these logical changes in `ClosureCleaner`: 1. Making it recognize and clean closures defined in Ammonite (previously it was checking if capturing class name starts with `$line` and ends with `$iw`, which is native Scala REPL specific thing 2. Making it clean closures if they are defined inside a user class in a REPL (see corner case 1 in the gist) 3. Making it clean nested closures properly for Ammonite REPL (see corner case 2 in the gist) 4. Making it transitively follow other Ammonite commands that are captured by the target closure. Please note that `cleanTransitively` option of `ClosureCleaner.clean()` method refers to following references transitively within enclosing command object, but it doesn't follow other command objects. As we need `ClosureCleaner` to be available in Spark Connect, I also moved the implementation to `common-utils` module. This brings a new `xbean-asm9-shaded` which is fairly small. Also, this PR moves `checkSerializable` check from `ClosureCleaner` to `SparkClosureCleaner`, as it is specific to Spark core The important changes affect `ClosureCleaner` only. They should not affect existing codepath for normal Scala closures / closures defined in a native Scala REPL and cover only closures defined in Ammonite. Also, this PR modifies SparkConnect's `UserDefinedFunction` to actually use `ClosureCleaner` and clean closures in SparkConnect ### Why are the changes needed? To properly support closures defined in Ammonite, reduce UDF payload size and avoid possible `NonSerializable` exceptions. This includes: - lambda capturing outer command object, leading in a circular dependency - lambda capturing other command objects transitively, exploding payload size ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Existing tests. New tests in `ReplE2ESuite` covering various scenarios using SparkConnect + Ammonite REPL to make sure closures are actually cleaned. ### Was this patch authored or co-authored using generative AI tooling? No Closes #42995 from vsevolodstep-db/SPARK-45136/closure-cleaner. Authored-by: Vsevolod Stepanov <vsevolod.stepanov@databricks.com> Signed-off-by: Herman van Hovell <herman@databricks.com>
Spark is a unified analytics engine for large-scale data processing. It provides high-level APIs in Scala, Java, Python, and R, 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.
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.