Apache Spark Connect Client for Rust

This project houses the experimental client for Spark Connect for Apache Spark written in Rust

Current State of the Project

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.

Quick Start

The spark-connect-rs aims to provide an entrypoint to Spark Connect, and provide similar DataFrame API interactions.

docker compose up --build -d
use spark_connect_rs;

use spark_connect_rs::{SparkSession, SparkSessionBuilder};

use spark_connect_rs::functions as F;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let spark: SparkSession = SparkSessionBuilder::remote("sc://127.0.0.1:15002/".to_string())
            .build()
            .await?;

    let mut df = spark
        .sql("SELECT * FROM json.`/opt/spark/examples/src/main/resources/employees.json`")
        .await?;

    df.filter("salary >= 3500")
        .select(F::col("name"))
        .show(Some(5), None, None)
        .await?;

    // +-------------+
    // | show_string |
    // +-------------+
    // | +------+    |
    // | |name  |    |
    // | +------+    |
    // | |Andy  |    |
    // | |Justin|    |
    // | |Berta |    |
    // | +------+    |
    // |             |
    // +-------------+

    Ok(())
}

Getting Started

git clone https://github.com/sjrusso8/spark-connect-rs.git
git submodule update --init --recursive

docker compose up --build -d

cargo build && cargo test

Features

The following section outlines some of the larger functionality that is not yet working with this Spark Connect implementation.

  • open TLS authentication & Databricks compatability
  • open streaming implementation
  • open groupBy, aggregation, and window functions
  • open better error handling
  • open converting RecordBatch output into a polars DataFrame

SparkSession

SparkSessionAPIComment
rangedone
sqldoneDoes not include the new Spark Connect 3.5 feature with “position arguments”
readdone
readStreamopen
createDataFrameopen
getActiveSessionopen
catalogopenPartial. List/Get functions are implemented

DataFrame

DataFrameAPIComment
selectdone
selectExprdoneDoes not include the new Spark Connect 3.5 feature with “position arguments”
filterdone
limitdone
dropDuplicatesdone
withColumnsRenameddone
dropdone
sampledone
repartitiondone
offsetdone
dtypesdone
columnsdone
schemadoneThe output needs to be handled better
explaindoneThe output needs to be handled better
showdone
taildone
collectdone
withColumnsopen
sortdone
groupByopen
createTempViewopenThere is an error right now, and the functions are private till it's fixed
many more!open

DataFrameWriter

Spark Connect should respect the format as long as your cluster supports the specified type and has the required jars

DataFrameAPIComment
formatdone
optiondone
optionsdone
modedone
bucketBydone
sortBydone
partitionBydone
savedone
saveAsTabledone
insertIntodone

Column

Spark Column type object and its implemented traits

ColumnAPIComment
aliasdone
ascdone
asc_nulls_firstdone
asc_nulls_lastdone
astypeopen
betweenopen
castdone
containsdone
descdone
desc_nulls_firstdone
desc_nulls_lastdone
dropFieldsopen
endswithdone
ilikedone
isNotNulldone
isNulldone
isindone
likedone
namedone
otherwiseopen
rlikedone
startswithdone
substropen
whenopen
addition +done
subtration -done
multiplication *done
division /done
OR ``done
AND &done
XOR ^done
Negate ~done

Functions

Only a few of the functions are covered by unit tests.

FunctionsAPIComment
absdone
acosopen
acoshopen
add_monthsdone
aggregateopen
approxCountDistinctopen
approx_count_distinctopen
arraydone
array_appendopen
array_compactdone
array_containsopen
array_distinctdone
array_exceptdone
array_insertopen
array_intersectdone
array_joinopen
array_maxdone
array_mindone
array_positionopen
array_removeopen
array_repeatopen
array_sortopen
array_uniondone
arrays_overlapopen
arrays_zipdone
ascdone
asc_nulls_firstdone
asc_nulls_lastdone
asciidone
asinopen
asinhopen
assert_trueopen
atanopen
atan2open
atanhopen
avgopen
base64done
bindone
bit_lengthdone
bitwiseNOTopen
bitwise_notdone
broadcastopen
broundopen
bucketopen
call_udfopen
castopen
cbrtopen
ceildone
coalescedone
coldone
collect_listopen
collect_setopen
columndone
concatdone
concat_wsopen
convopen
corropen
cosopen
coshopen
cotopen
countopen
countDistinctopen
count_distinctopen
covar_popopen
covar_sampopen
crc32done
create_mapdone
cscopen
cume_distdone
current_datedone
current_timestampopen
date_adddone
date_formatopen
date_subdone
date_truncopen
datediffdone
dayofmonthdone
dayofweekdone
dayofyeardone
daysdone
decodeopen
degreesopen
dense_rankdone
descdone
desc_nulls_firstdone
desc_nulls_lastdone
element_atopen
encodeopen
existsopen
expdone
explodedone
explode_outerdone
expm1open
exprdone
factorialdone
filteropen
firstopen
flattendone
floordone
forallopen
format_numberopen
format_stringopen
from_csvopen
from_jsonopen
from_unixtimeopen
from_utc_timestampopen
functoolsopen
getopen
get_active_spark_contextopen
get_json_objectopen
greatestdone
groupingopen
grouping_idopen
has_numpyopen
hashdone
hexopen
hourdone
hoursdone
hypotopen
initcapdone
inlinedone
inline_outerdone
input_file_namedone
inspectopen
instropen
isnandone
isnulldone
json_tupleopen
kurtosisopen
lagopen
lastopen
last_dayopen
leadopen
leastdone
lengthdone
levenshteinopen
litdone
localtimestampopen
locateopen
logdone
log10done
log1pdone
log2done
lowerdone
lpadopen
ltrimdone
make_dateopen
map_concatdone
map_contains_keyopen
map_entriesdone
map_filteropen
map_from_arraysopen
map_from_entriesdone
map_keysdone
map_valuesdone
map_zip_withopen
maxopen
max_byopen
md5done
meanopen
medianopen
minopen
min_byopen
minutedone
modeopen
monotonically_increasing_iddone
monthdone
monthsdone
months_betweenopen
nanvldone
next_dayopen
npopen
nth_valueopen
ntileopen
octet_lengthdone
overlayopen
overloadopen
pandas_udfopen
percent_rankdone
percentile_approxopen
pmodopen
posexplodedone
posexplode_outerdone
powdone
productopen
quarterdone
radiansopen
raise_erroropen
randdone
randndone
rankdone
regexp_extractopen
regexp_replaceopen
repeatopen
reversedone
rintopen
rounddone
row_numberdone
rpadopen
rtrimdone
schema_of_csvopen
schema_of_jsonopen
secopen
seconddone
sentencesopen
sequenceopen
session_windowopen
sha1done
sha2open
shiftLeftopen
shiftRightopen
shiftRightUnsignedopen
shiftleftopen
shiftrightopen
shiftrightunsignedopen
shuffledone
signumopen
sinopen
sinhopen
sizedone
skewnessopen
sliceopen
sort_arrayopen
soundexdone
spark_partition_iddone
splitopen
sqrtdone
stddevopen
stddev_popopen
stddev_sampopen
structopen
substringopen
substring_indexopen
sumopen
sumDistinctopen
sum_distinctopen
sysopen
tanopen
tanhopen
timestamp_secondsdone
toDegreesopen
toRadiansopen
to_csvopen
to_dateopen
to_jsonopen
to_stropen
to_timestampopen
to_utc_timestampopen
transformopen
transform_keysopen
transform_valuesopen
translateopen
trimdone
truncopen
try_remote_functionsopen
udfopen
unbase64done
unhexopen
unix_timestampopen
unwrap_udtopen
upperdone
var_popopen
var_sampopen
varianceopen
warningsopen
weekofyeardone
whenopen
windowopen
window_timeopen
xxhash64done
yeardone
yearsdone
zip_withopen