Skip to main content

No project description provided

Project description

congruity

GitHub Actions Build PyPI Downloads

In many ways, the migration from using classic Spark applications using the full power and flexibility to be using only the Spark Connect compatible DataFrame API can be challenging.

The goal of this library is to provide a compatibility layer that makes it easier to adopt Spark Connect. The library is designed to be simply imported in your application and will then monkey-patch the existing API to provide the legacy functionality.

Non-Goals

This library is not intended to be a long-term solution. The goal is to provide a compatibility layer that becomes obsolete over time. In addition, we do not aim to provide compatibility for all methods and features but only a select subset. Lastly, we do not aim to achieve the same performance as using some of the native RDD APIs.

Usage

Spark JVM & Spark Connect compatibility library.

pip install spark-congruity
import congruity

Example

Here is code that works on Spark JVM:

from pyspark.sql import SparkSession

spark = SparkSession.builder.remote("sc://localhost").getOrCreate()
data = [("Java", "20000"), ("Python", "100000"), ("Scala", "3000")]
spark.sparkContext.parallelize(data).toDF()

This code doesn't work with Spark Connect. The congruity library rearranges the code under the hood, so the old syntax works on Spark Connect clusters as well:

import congruity  # noqa: F401
from pyspark.sql import SparkSession

spark = SparkSession.builder.remote("sc://localhost").getOrCreate()
data = [("Java", "20000"), ("Python", "100000"), ("Scala", "3000")]
spark.sparkContext.parallelize(data).toDF()

Contributing

We very much welcome contributions to this project. The easiest way to start is to pick any of the below RDD or SparkContext methods and implement the compatibility layer. Once you have done that open a pull request and we will review it.

What's supported?

RDD

RDD API Comment
aggregate :white_check_mark:
aggregateByKey :x:
barrier :x:
cache :x:
cartesian :x:
checkpoint :x:
cleanShuffleDependencies :x:
coalesce :x:
cogroup :x:
collect :white_check_mark:
collectAsMap :x:
collectWithJobGroup :x:
combineByKey :x:
count :white_check_mark:
countApprox :x:
countByKey :x:
countByValue :x:
distinct :x:
filter :white_check_mark:
first :white_check_mark:
flatMap :x:
fold :white_check_mark: First version
foreach :x:
foreachPartition :x:
fullOuterJoin :x:
getCheckpointFile :x:
getNumPartitions :x:
getResourceProfile :x:
getStorageLevel :x:
glom :white_check_mark:
groupBy :white_check_mark:
groupByKey :white_check_mark:
groupWith :x:
histogram :white_check_mark:
id :x:
intersection :x:
isCheckpointed :x:
isEmpty :x:
isLocallyCheckpointed :x:
join :x:
keyBy :white_check_mark:
keys :white_check_mark:
leftOuterJoin :x:
localCheckpoint :x:
lookup :x:
map :white_check_mark:
mapPartitions :white_check_mark: First version, based on mapInArrow.
mapPartitionsWithIndex :x:
mapPartitionsWithSplit :x:
mapValues :white_check_mark:
max :white_check_mark:
mean :white_check_mark:
meanApprox :x:
min :white_check_mark:
name :x:
partitionBy :x:
persist :x:
pipe :x:
randomSplit :x:
reduce :white_check_mark:
reduceByKey :x:
repartition :x:
repartitionAndSortWithinPartition :x:
rightOuterJoin :x:
sample :x:
sampleByKey :x:
sampleStdev :white_check_mark:
sampleVariance :white_check_mark:
saveAsHadoopDataset :x:
saveAsHadoopFile :x:
saveAsNewAPIHadoopDataset :x:
saveAsNewAPIHadoopFile :x:
saveAsPickleFile :x:
saveAsTextFile :x:
setName :x:
sortBy :x:
sortByKey :x:
stats :white_check_mark:
stdev :white_check_mark:
subtract :x:
substractByKey :x:
sum :white_check_mark: First version.
sumApprox :x:
take :white_check_mark: Ordering might not be guaranteed in the same way as it is in RDD.
takeOrdered :x:
takeSample :x:
toDF :white_check_mark:
toDebugString :x:
toLocalIterator :x:
top :x:
treeAggregate :x:
treeReduce :x:
union :x:
unpersist :x:
values :white_check_mark:
variance :white_check_mark:
withResources :x:
zip :x:
zipWithIndex :x:
zipWithUniqueId :x:

SparkContext

RDD API Comment
parallelize :white_check_mark: Does not support numSlices yet.

Limitations

  • Error handling and checking is kind of limited right now. We try to emulate the existing behavior, but this is not always possible because the invariants are not encode in Python but rather somewhere in Scala.
  • numSlices - we don't emulate this behavior for now.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spark_congruity-0.0.1rc4.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

spark_congruity-0.0.1rc4-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

Details for the file spark_congruity-0.0.1rc4.tar.gz.

File metadata

  • Download URL: spark_congruity-0.0.1rc4.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for spark_congruity-0.0.1rc4.tar.gz
Algorithm Hash digest
SHA256 eb13c804c391cb8adeaad7ddbf5a529e17f0fcc576405c3ab787657b25157493
MD5 819597f84375f880d2b732b532b030a8
BLAKE2b-256 60765878598d2e8955028fb41f2db8ad9976f14f54db0877921a131c6e197ace

See more details on using hashes here.

File details

Details for the file spark_congruity-0.0.1rc4-py3-none-any.whl.

File metadata

File hashes

Hashes for spark_congruity-0.0.1rc4-py3-none-any.whl
Algorithm Hash digest
SHA256 533926de6ca1342e60463f4e9e5b03260bdacdf52a7ba3d0abc35abb04d310e7
MD5 9c34d3dce6c34ecb43e17ba75c11c779
BLAKE2b-256 e906052f8d74de0f8dc31a60994e57c049ba5558fd08b3ee671a7e552ab7391d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page