# pysparky.utils

*module*

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

## pysparky.utils.create_map_from_dict

*function*

```python
def create_map_from_dict(dict_: dict[str, int]) -> Column
```

Generates a PySpark map column from a provided dictionary.

This function converts a dictionary into a PySpark map column, with each key-value pair represented as a literal in the map.

**Parameters**

- `dict_` (`Dict[str, int]`) — A dictionary with string keys and integer values.

**Returns**

- `Column` (`Column`) — A PySpark Column object representing the created map.

> **Example**
>
> >>> dict_ = {"a": 1, "b": 2}
> >>> map_column = create_map_from_dict(dict_)

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

## pysparky.utils.join_dataframes_on_column

*function*

```python
def join_dataframes_on_column(column_name: str, *dataframes: DataFrame, how: str = 'outer') -> DataFrame
```

Joins a list of DataFrames on a specified column using an outer join.

**Parameters**

- `column_name` (`str`) — The column name to join on.
- `*dataframes` (`DataFrame`) (default: `()`) — A list of DataFrames to join.
- `how` (`str`) (default: `'outer'`) — The type of join to perform, passthrough to pyspark join (default is "outer").

**Returns**

- `DataFrame` (`DataFrame`) — The resulting DataFrame after performing the outer joins.

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

## pysparky.utils.split_dataframe_by_column

*function*

```python
def split_dataframe_by_column(sdf: DataFrame, split_column: str) -> dict[str, DataFrame]
```

Splits a DataFrame into multiple DataFrames based on distinct values in a specified column.

**Parameters**

- `sdf` (`DataFrame`) — The input Spark DataFrame.
- `column_name` (`str`) — The column name to split the DataFrame by.

**Returns**

- (`dict[str, DataFrame]`) — dict[str, DataFrame]: A dictionary where keys are distinct column values and values are DataFrames.

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

## pysparky.utils.split_dataframe_by_column_groups

*function*

```python
def split_dataframe_by_column_groups(df: DataFrame, column_name: str, *value_groups: list[str | list]) -> tuple[DataFrame, ...]
```

Splits a DataFrame into multiple DataFrames based on groups of values in a specified column.

Parameters:
df (DataFrame): The input PySpark DataFrame.
column_name (str): The column to split on.
*value_groups (list): Variable number of value groups (each a list of values).

Returns:
tuple: A tuple of DataFrames, one for each group of values.

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

## pysparky.utils.union_dataframes

*function*

```python
def union_dataframes(*dataframes: DataFrame) -> DataFrame
```

Unions a list of DataFrames.

**Parameters**

- `*dataframes` (`DataFrame`) (default: `()`) — A list of DataFrames to union.

**Returns**

- `DataFrame` (`DataFrame`) — The resulting DataFrame after performing the unions.

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