Utilities
Functions
| Name | Description |
|---|---|
create_map_from_dict | Generates a PySpark map column from a provided dictionary. |
join_dataframes_on_column | Joins a list of DataFrames on a specified column using an outer join. |
split_dataframe_by_column | Splits a DataFrame into multiple DataFrames based on distinct values in a specified column. |
split_dataframe_by_column_groups | Splits a DataFrame into multiple DataFrames based on groups of values in a specified column. |
union_dataframes | Unions a list of DataFrames. |
create_map_from_dictfunction#
def create_map_from_dict(dict_: dict[str, int]) -> ColumnGenerates 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.
Returns
ColumnColumn- A PySpark Column object representing the created map.
join_dataframes_on_columnfunction#
def join_dataframes_on_column(column_name: str, *dataframes: DataFrame, how: str = 'outer') -> DataFrameJoins a list of DataFrames on a specified column using an outer join.
Parameters
Returns
DataFrameDataFrame- The resulting DataFrame after performing the outer joins.
split_dataframe_by_columnfunction#
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
| Name | Type | Description |
|---|---|---|
sdf | DataFrame | The input Spark DataFrame. |
column_name | str | The column name to split the DataFrame by. |
split_dataframe_by_column_groupsfunction#
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.
union_dataframesfunction#
def union_dataframes(*dataframes: DataFrame) -> DataFrameUnions a list of DataFrames.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
*dataframes | DataFrame | () | A list of DataFrames to union. |
Returns
DataFrameDataFrame- The resulting DataFrame after performing the unions.