# pysparky.decorator

*module*

[View source](https://github.com/PySparky/pysparky-pyspark-helper/blob/327582f8b776fe7638082ce4b5be8153d3ce63d3/pysparky/decorator.py#L1-L1)

## pysparky.decorator.extension_enabler

*function*

```python
def extension_enabler()
```

This enable you to chain the class

[View source](https://github.com/PySparky/pysparky-pyspark-helper/blob/327582f8b776fe7638082ce4b5be8153d3ce63d3/pysparky/decorator.py#L105-L121)

## pysparky.decorator.validate_columns

*function*

```python
def validate_columns(input_cols: list[str] = None, required_cols: list[str] = None, expected_cols: list[str] = None, output_cols: list[str] = None, added_cols: list[str] = None, dropped_cols: list[str] = None) -> Callable
```

Decorator to validate the input and output columns of a PySpark DataFrame transformation.

**Parameters**

- `input_cols` (`list[str]`) (default: `None`) — The exact list of columns that must be present before transformation.
- `required_cols` (`list[str]`) (default: `None`) — The subset of columns that must be present before transformation.
- `expected_cols` (`list[str]`) (default: `None`) — The subset of columns that must be present after transformation.
- `output_cols` (`list[str]`) (default: `None`) — The exact list of columns that must be present after transformation.
- `added_cols` (`list[str]`) (default: `None`) — The exact list of newly added columns (output - input).
- `dropped_cols` (`list[str]`) (default: `None`) — The exact list of dropped columns (input - output).

**Returns**

- `Callable` (`Callable`) — The decorated function.

**Examples**

```pycon
>>> from pyspark.sql import SparkSession
>>> spark = SparkSession.builder.getOrCreate()
>>> df = spark.createDataFrame([(1, 100)], ["user_id", "raw_revenue"])
>>> @validate_columns(required_cols=["user_id"], added_cols=["net_revenue"])
... def calculate_net_revenue(df: DataFrame) -> DataFrame:
...     return df.withColumn("net_revenue", df["raw_revenue"] * 0.8)
>>> result = calculate_net_revenue(df)
>>> result.columns
['user_id', 'raw_revenue', 'net_revenue']
```

[View source](https://github.com/PySparky/pysparky-pyspark-helper/blob/327582f8b776fe7638082ce4b5be8153d3ce63d3/pysparky/decorator.py#L6-L102)
