Metadata-Version: 2.4
Name: spark-logicalplan-sql-restorer
Version: 0.1.0
Summary: Restore SQL from Apache Spark Catalyst LogicalPlan JSON
Author: mt
License: MIT
Project-URL: Homepage, https://pypi.org/project/spark-logicalplan-sql-restorer/
Keywords: spark,sql,catalyst,logicalplan,json
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# spark-logicalplan-sql-restorer

Restore SQL from Apache Spark Catalyst `LogicalPlan` JSON payloads.

## Install

```bash
pip install spark-logicalplan-sql-restorer
```

## Python API

```python
from pathlib import Path
import json
from spark_logicalplan_sql_restorer import (
    restore_sql,
    restore_sql_from_json_file,
    restore_sql_from_json_string,
)

json_str = Path("test_json/001_00_setup_schema_01.json").read_text(encoding="utf-8")
sql1 = restore_sql_from_json_string(json_str)

payload = json.loads(json_str)
sql2 = restore_sql(payload)

sql3 = restore_sql_from_json_file(Path("test_json/001_00_setup_schema_01.json"))
print(sql1, sql2, sql3)
```

## CLI

Restore one file:

```bash
logicalplan-sql-restorer test_json/001_00_setup_schema_01.json
```

Restore directory:

```bash
logicalplan-sql-restorer test_json --output restored_sql
```
