Skip to content

pysparky.transformations.dedup

Functions

NameDescription
get_latest_record_from_columnFetches the most recent record from a DataFrame based on a specified column, allowing for custom sorting order.
get_only_duplicate_recordRetrieves only the duplicate records from the input DataFrame
get_only_unique_recordRetrieves only the unique records from the input DataFrame
quarantine_duplicate_recordSplits 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) -> DataFrame

Fetches the most recent record from a DataFrame based on a specified column, allowing for custom sorting order.

Parameters

NameTypeDefaultDescription
sdfDataFramerequiredThe DataFrame to process.
window_partition_column_namestrrequiredThe column used to partition the DataFrame.
window_order_by_column_namesstr | listrequiredThe column(s) used to sort the DataFrame.
window_functionColumnF.row_numberThe 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) -> DataFrame

Retrieves only the duplicate records from the input DataFrame based on the specified column.

Parameters

NameTypeDescription
sdfDataFrameThe input Spark DataFrame.
column_namestrThe 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) -> DataFrame

Retrieves only the unique records from the input DataFrame based on the specified column.

Parameters

NameTypeDescription
sdfDataFrameThe input Spark DataFrame.
column_namestrThe 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

NameTypeDescription
sdfDataFrameThe input Spark DataFrame.
column_namestrThe 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.