Skip to content

fabric_utils

sqllocks_spindle.output.fabric_utils

Fabric environment detection and partition spec parsing.

Classes

FabricEnvironment dataclass

Result of Fabric environment detection.

Functions:

detect_fabric_environment()

Detect whether we are running inside a Microsoft Fabric Notebook.

Checks for: 1. FABRIC_RUNTIME or TRIDENT_RUNTIME_VERSION environment variables. 2. Existence of /lakehouse/default/ directory.

Returns:

Name Type Description
A FabricEnvironment

class:FabricEnvironment with detection results.

parse_partition_spec(specs, df)

Parse partition specs and add computed partition columns.

Each spec is "column_name:extraction" where extraction is one of year, month, day, quarter, week.

A spec without a colon (e.g. "region") is treated as a plain column name — no extraction is applied, the column is used as-is.

Parameters:

Name Type Description Default
specs list[str]

List of partition specs, e.g. ["order_date:year", "order_date:month"].

required
df DataFrame

Source DataFrame (not mutated).

required

Returns:

Type Description
tuple[DataFrame, list[str]]

A tuple of (df_with_partition_cols, partition_column_names).

Raises:

Type Description
ValueError

If a source column is missing or extraction is unknown.