pysparky.transformations.dedup
Functions
| Name | Description |
|---|---|
get_latest_record_from_column | Fetches the most recent record from a DataFrame based on a specified column, allowing for custom sorting order. |
get_only_duplicate_record | Retrieves only the duplicate records from the input DataFrame |
get_only_unique_record | Retrieves only the unique records from the input DataFrame |
quarantine_duplicate_record | Splits the input DataFrame into two DataFrames: one containing unique records |
get_latest_record_from_columnfunction#
def get_latest_record_from_column(sdf: DataFrame, window_partition_column_name: str, window_order_by_column_names: str | list[str], window_function: Callable = F.row_number) -> DataFrameFetches the most recent record from a DataFrame based on a specified column, allowing for custom sorting order.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
sdf | DataFrame | required | The DataFrame to process. |
window_partition_column_name | str | required | The column used to partition the DataFrame. |
window_order_by_column_names | str | list | required | The column(s) used to sort the DataFrame. |
window_function | Column | F.row_number | The window function for ranking records. Defaults to F.row_number. |
Returns
DataFrameDataFrame- A DataFrame with the most recent record for each partition.
get_only_duplicate_recordfunction#
def get_only_duplicate_record(sdf: DataFrame, column_name: str) -> DataFrameRetrieves only the duplicate records from the input DataFrame based on the specified column.
Parameters
| Name | Type | Description |
|---|---|---|
sdf | DataFrame | The input Spark DataFrame. |
column_name | str | The column name to check for duplicates. |
Returns
DataFrameDataFrame- A DataFrame containing only the duplicate records.
get_only_unique_recordfunction#
def get_only_unique_record(sdf: DataFrame, column_name: str) -> DataFrameRetrieves only the unique records from the input DataFrame based on the specified column.
Parameters
| Name | Type | Description |
|---|---|---|
sdf | DataFrame | The input Spark DataFrame. |
column_name | str | The column name to check for duplicates. |
Returns
DataFrameDataFrame- A DataFrame containing only the unique records.
quarantine_duplicate_recordfunction#
def quarantine_duplicate_record(sdf: DataFrame, column_name: str) -> tuple[DataFrame, DataFrame]Splits the input DataFrame into two DataFrames: one containing unique records based on the specified column, and the other containing duplicate records.
Parameters
| Name | Type | Description |
|---|---|---|
sdf | DataFrame | The input Spark DataFrame. |
column_name | str | The column name to check for duplicates. |
Returns
DataFrame- tuple[DataFrame, DataFrame]: A tuple containing two DataFrames. The first DataFrame
DataFrame- contains unique records, and the second DataFrame contains duplicate records.