Metadata-Version: 2.4
Name: skewsplit
Version: 0.1.0
Summary: Balanced, index-friendly JDBC partition predicates for Spark, planned from the column's real distribution.
Keywords: spark,jdbc,postgresql,partitioning,skew,predicates
Author: The skewsplit authors
License-Expression: Apache-2.0
License-File: LICENSE
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Database
Classifier: Typing :: Typed
Requires-Dist: psycopg>=3.2 ; python_full_version < '3.10' and extra == 'postgres'
Requires-Dist: psycopg>=3.3 ; python_full_version >= '3.10' and extra == 'postgres'
Requires-Python: >=3.9
Project-URL: Repository, https://github.com/Diafyx/skewsplit
Project-URL: Issues, https://github.com/Diafyx/skewsplit/issues
Provides-Extra: postgres
Description-Content-Type: text/markdown

# skewsplit

skewsplit reads a database column's distribution and returns balanced,
index-friendly range predicates for the `predicates` argument of Spark's JDBC
reader, together with a report of the remaining skew.

For PostgreSQL, it plans from the column's statistics in `pg_stats`, without
scanning the table. `NULL` rows get their own predicate, a value too frequent
to split gets its own `col = value` predicate, and the predicates match every
row exactly once whatever the data.

> **Status: early development (pre-alpha).** The API can change in any 0.x
> release.

## Install

```sh
pip install "skewsplit[postgres]"
```

The `postgres` extra installs psycopg, which also needs libpq: add
`psycopg[binary]` if your system has none.

## Use

```python
from skewsplit import postgres

plan = postgres.plan("host=db dbname=shop user=reader", "public.orders", "customer_id", 16)
print(plan.report)
df = spark.read.jdbc(url, "public.orders", predicates=plan.predicates, properties=properties)
```

The planner itself needs no database:

```python
>>> import skewsplit
>>> plan = skewsplit.plan(
...     {
...         "column": "customer_id",
...         "type": "int4",
...         "null_rows": 100,
...         "mcv": [{"value": "7", "rows": 60}, {"value": "42", "rows": 500}],
...         "histogram": {"bounds": ["1", "250", "500", "750", "1000"], "rows": 400},
...     },
...     4,
... )
>>> for predicate in plan.predicates:
...     print(predicate)
"customer_id" IS NULL
"customer_id" < 42
"customer_id" = 42
"customer_id" > 42 AND "customer_id" < 520
"customer_id" >= 520

```

From the command line, `skewsplit plan --table public.orders --column
customer_id --partitions 16` prints the same report, and `--format pyspark`
prints the code that reads the table.

**The output contains real values from the column**: treat plans, reports and
logs like the data they describe.

The [repository](https://github.com/Diafyx/skewsplit#readme) has the full
documentation: the command line, when to use hash-mod instead, limitations and
supported versions.
