Skip to main content

easyfabric.fabric.spark_utils

PySpark utilities and helper functions for EasyFabric.

get_df_size​

def get_df_size(df) -> float

Estimated size of a dataframe in bytes, from the optimized plan's statistics.

Reads the JVM plan through df._jdf, which classic Spark (the Fabric runtime) has and Spark Connect does not. Without it the size is unknown and the result is float("inf"), logged so a caller's sizing decision never silently falls back.

Arguments:

  • df - A PySpark DataFrame.

  • Returns - sizeInBytes, or float("inf") when the statistics cannot be read.

current_timestamp​

def current_timestamp()

The driver's local wall-clock time, as collecting Spark's current_timestamp() returns it, without a Spark query.

union_with_schema_alignment​

def union_with_schema_alignment(df1: DataFrame, df2: DataFrame) -> DataFrame

Union two dataframes, aligning schema types and warning about incompatible columns. Only columns with matching types (after possible casting) will be included in the union.

Arguments:

  • df1 - First dataframe
  • df2 - Second dataframe

Returns:

Unified dataframe with compatible columns