This project houses the experimental client for Spark Connect for Apache Spark written in Rust
Currently, the Spark Connect client for Rust is highly experimental and should not be used in any production setting. This is currently a "proof of concept" to identify the methods of interacting with Spark cluster from rust.
The spark-connect-rs
aims to provide an entrypoint to Spark Connect, and provide similar DataFrame API interactions.
├── crates <- crates for the implementation of the client side spark-connect bindings
│ └─ connect <- crate for 'spark-connect-rs'
│ └─ protobuf <- connect protobuf for apache/spark
├── examples <- examples of using different aspects of the crate
├── datasets <- sample files from the main spark repo
Future state would be to have additional crates that allow for easier creation of other language bindings.
This section explains how run Spark Connect Rust locally starting from 0.
Step 1: Install rust via rustup: https://www.rust-lang.org/tools/install
Step 2: Ensure you have a cmake and protobuf installed on your machine
Step 3: Run the following commands to clone the repo
git clone https://github.com/sjrusso8/spark-connect-rs.git
cargo build
Step 4: Setup the Spark Driver on localhost either by downloading spark or with docker.
With local spark:
-
Download Spark distribution (3.5.1 recommended), unzip the package.
-
Set your
SPARK_HOME
environment variable to the location where spark was extracted to, -
Start the Spark Connect server with the following command (make sure to use a package version that matches your Spark distribution):
$ $SPARK_HOME/sbin/start-connect-server.sh --packages "org.apache.spark:spark-connect_2.12:3.5.1,io.delta:delta-spark_2.12:3.0.0" \
--conf "spark.driver.extraJavaOptions=-Divy.cache.dir=/tmp -Divy.home=/tmp" \
--conf "spark.sql.extensions=io.delta.sql.DeltaSparkSessionExtension" \
--conf "spark.sql.catalog.spark_catalog=org.apache.spark.sql.delta.catalog.DeltaCatalog"
With docker:
- Start the Spark Connect server by leveraging the created
docker-compose.yml
in this repo. This will start a Spark Connect Server running on port 15002
$ docker compose up --build -d
Step 5: Run an example from the repo under /examples
The following section outlines some of the larger functionality that are not yet working with this Spark Connect implementation.
- TLS authentication & Databricks compatability via the feature flag
feature = 'tls'
- StreamingQueryManager
- UDFs or any type of functionality that takes a closure (foreach, foreachBatch, etc.)
Spark Session type object and its implemented traits
SparkSession | API | Comment |
---|---|---|
active | ||
addArtifact(s) | ||
addTag | ||
clearTags | ||
copyFromLocalToFs | ||
createDataFrame | Partial. Only works for RecordBatch |
|
getActiveSessions | ||
getTags | ||
interruptAll | ||
interruptOperation | ||
interruptTag | ||
newSession | ||
range | ||
removeTag | ||
sql | ||
stop | ||
table | ||
catalog | Catalog | |
client | unstable developer api for testing only | |
conf | Conf | |
read | DataFrameReader | |
readStream | DataStreamReader | |
streams | Streams | |
udf | Udf - may not be possible | |
udtf | Udtf - may not be possible | |
version |
SparkSessionBuilder | API | Comment |
---|---|---|
appName | ||
config | ||
master | ||
remote | Validate using spark connection string |
StreamingQueryManager | API | Comment |
---|---|---|
awaitAnyTermination | ||
get | ||
resetTerminated | ||
active |
StreamingQuery | API | Comment |
---|---|---|
awaitTermination | ||
exception | ||
explain | ||
processAllAvailable | ||
stop | ||
id | ||
isActive | ||
lastProgress | ||
name | ||
recentProgress | ||
runId | ||
status |
DataStreamReader | API | Comment |
---|---|---|
csv | ||
format | ||
json | ||
load | ||
option | ||
options | ||
orc | ||
parquet | ||
schema | ||
table | ||
text |
DataFrameReader | API | Comment |
---|---|---|
csv | ||
format | ||
json | ||
load | ||
option | ||
options | ||
orc | ||
parquet | ||
schema | ||
table | ||
text |
Start a streaming job and return a StreamingQuery
object to handle the stream operations.
DataStreamWriter | API | Comment |
---|---|---|
foreach | ||
foreachBatch | ||
format | ||
option | ||
options | ||
outputMode | Uses an Enum for OutputMode |
|
partitionBy | ||
queryName | ||
start | ||
toTable | ||
trigger | Uses an Enum for TriggerMode |
StreamingQueryListener | API | Comment |
---|---|---|
onQueryIdle | ||
onQueryProgress | ||
onQueryStarted | ||
onQueryTerminated |
UDFRegistration | API | Comment |
---|---|---|
register | ||
registerJavaFunction | ||
registerJavaUDAF |
UDTFRegistration | API | Comment |
---|---|---|
register |
RuntimeConfig | API | Comment |
---|---|---|
get | ||
isModifiable | ||
set | ||
unset |
Spark DataFrame type object and its implemented traits.
Spark Connect should respect the format as long as your cluster supports the specified type and has the required jars
DataFrameWriter | API | Comment |
---|---|---|
bucketBy | ||
csv | ||
format | ||
insertInto | ||
jdbc | ||
json | ||
mode | ||
option | ||
options | ||
orc | ||
parquet | ||
partitionBy | ||
save | ||
saveAsTable | ||
sortBy | ||
text |
DataFrameWriterV2 | API | Comment |
---|---|---|
append | ||
create | ||
createOrReplace | ||
option | ||
options | ||
overwrite | ||
overwritePartitions | ||
partitionedBy | ||
replace | ||
tableProperty | ||
using |
Spark Column type object and its implemented traits
Only a few of the functions are covered by unit tests.
Data types are used for creating schemas and for casting columns to specific types
Create Spark literal types from these rust types. E.g. lit(1_i64)
would be a LongType()
in the schema.
An array can be made like lit([1_i16,2_i16,3_i16])
would result in an ArrayType(Short)
since all the values of the slice can be translated into literal type.
For ease of use it's recommended to use Window
to create the WindowSpec
.