pysparky.spark_ext
Functions
| Name | Description |
|---|---|
check_table_exists | Checks if a specific table exists in the given catalog. |
column_function | Evaluates a Column expression in the context of a single-row DataFrame. |
convert_1d_list_to_dataframe | Converts a 1-dimensional list into a PySpark DataFrame. |
convert_dict_to_dataframe | Transforms a dictionary with list values into a Spark DataFrame. |
createDataFrame_from_dict | Creates a Spark DataFrame from a dictionary in a pandas-like style. |
check_table_existsfunction#
def check_table_exists(spark: SparkSession, catalog: str, database: str, table_name: str) -> boolChecks if a specific table exists in the given catalog.
Parameters
Returns
boolbool- True if the table exists, False otherwise.
column_functionfunction#
def column_function(spark: SparkSession, column_obj: Column) -> DataFrameEvaluates a Column expression in the context of a single-row DataFrame.
This function creates a DataFrame with a single row and applies the given Column expression to it. This is particularly useful for testing Column expressions, evaluating complex transformations, or creating sample data based on Column operations.
Parameters
| Name | Type | Description |
|---|---|---|
spark | pyspark.sql.SparkSession | The SparkSession object. |
column_obj | pyspark.sql.Column | The Column object or expression to evaluate. |
Returns
DataFrame- pyspark.sql.DataFrame: A single-row DataFrame containing the result of the Column expression.
convert_1d_list_to_dataframefunction#
def convert_1d_list_to_dataframe(spark: SparkSession, list_: list[Any], column_names: str | list[str], axis: str = 'column') -> DataFrameConverts a 1-dimensional list into a PySpark DataFrame.
This function takes a 1-dimensional list and converts it into a PySpark DataFrame with the specified column names. The list can be converted into a DataFrame with either a single column or a single row, based on the specified axis.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
spark | SparkSession | required | The Spark session to use for creating the DataFrame. |
list_ | list | required | The 1-dimensional list to convert. |
column_names | str or list of str | required | The name(s) of the column(s) for the DataFrame. |
axis | str | 'column' | Specifies whether to convert the list into a single column or a single row. Acceptable values are “column” (default) and “row”. |
Returns
DataFrameDataFrame- A PySpark DataFrame created from the 1-dimensional list.
Raises
AttributeError- If the axis parameter is not “column” or “row”.
convert_dict_to_dataframefunction#
def convert_dict_to_dataframe(spark: SparkSession, dict_: dict[str, Any], column_names: list[str], explode: bool = False) -> DataFrameTransforms a dictionary with list values into a Spark DataFrame.
Parameters
Returns
DataFrame- pyspark.sql.DataFrame: A DataFrame with the dictionary keys and their corresponding exploded list values.
createDataFrame_from_dictfunction#
def createDataFrame_from_dict(spark: SparkSession, dict_: dict) -> DataFrameCreates a Spark DataFrame from a dictionary in a pandas-like style.
Parameters
| Name | Type | Description |
|---|---|---|
spark | SparkSession | The SparkSession object. |
dict_ | dict | The dictionary to convert, where keys are column names and values are lists of column data. |
Returns
DataFrameDataFrame- The resulting Spark DataFrame.