Add your description here
Project description
flatspark
An opinionated pyspark package to handle deeply nested DataFrames with ease.
Key Features
- Flatten deeply nested DataFrames with arrays and structs
- Automatic generation of technical IDs for joins
- Customizable explode strategies for arrays
- Support for incremental loads with existing technical IDs
- Apply additional transformations during flattening
- Select standard columns across all flattened tables
Getting Started
pip install flatspark
from pyspark.sql import SparkSession
from flatspark import get_flattened_dataframes
spark = SparkSession.builder.getOrCreate()
# inital DataFrame contains one array
df = spark.createDataFrame(
[
("Alice", ["reading", "hiking"]),
("Bob", ["cooking"]),
("Charlie", []),
],
["name", "hobbies"],
)
flat_dfs = get_flattened_dataframes(df=df, root_name="friends")
A primary key column has been added to the root DataFrame friends:
flat_dfs["friends"].show()
+-------+--------------------+
|name |friends_technical_id|
+-------+--------------------+
|Alice |0 |
|Bob |1 |
|Charlie|2 |
+-------+--------------------+
The array hobbies has been seperated in its own DataFrame with a primary key and a foreign key column to enable joins:
+--------------------+-------+--------------------+
|friends_technical_id|hobbies|hobbies_technical_id|
+--------------------+-------+--------------------+
|0 |reading|0 |
|0 |hiking |1 |
|1 |cooking|2 |
|2 |NULL |3 |
+--------------------+-------+--------------------+
Additional Examples
Additional examples showing the features of the package can be found here:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flatspark-0.1.0.tar.gz.
File metadata
- Download URL: flatspark-0.1.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
deccea04225cab9b47046111ae0824620c299191096ab978380bad7b460cd43c
|
|
| MD5 |
61f465996cb6322916a21ff610520dd6
|
|
| BLAKE2b-256 |
0f252b5941081fe31e2ee02faccdbccbb2bfd46a3d572bc78a14ffcc511ce909
|
File details
Details for the file flatspark-0.1.0-py3-none-any.whl.
File metadata
- Download URL: flatspark-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6110a03d17f0fee0a4a9991bd929f71c723f6b049985bb81aa454df37cf5162c
|
|
| MD5 |
10d1046be21549f68c20693f8b84554a
|
|
| BLAKE2b-256 |
319f739059b5bd98e350c6223a6aa61db0ad4a9222ffe8de4ee9e5474fde36f0
|