Fabric¶
Microsoft Fabric platform implementation (Synapse / OneLake).
- class scamander.processor.fabric.Fabric(*args, **kwargs)¶
Basisklassen:
PlatformPlatform implementation for Microsoft Fabric (Synapse / OneLake environments).
Instantiated automatically by
Platform.__new__when the runtime is identified as Fabric (via theMMLSPARK_PLATFORM_INFOenvironment variable containing"SYNAPSE"or"FABRIC"). Usesnotebookutilsfor all filesystem and workspace operations.Example:
from scamander import Platform # Running in a Fabric notebook: Platform() auto-detects and returns # a Fabric instance transparently. platform = Platform() platform.log.info(f"Attached lakehouses: {platform.lakehouses}")
- check_file_exists(file_name: str, raise_exceptions=False) bool¶
Checks whether a file or directory exists on the Fabric / OneLake filesystem.
- Parameters:
file_name (str) – OneLake / ABFS path to check.
raise_exceptions (bool) – When
True, raisesFileNotFoundErrorif the path does not exist. Defaults toFalse.
- Returns:
Trueif the path exists,Falseotherwise.- Return type:
bool
- Veroorzaakt:
FileNotFoundError – Only when
raise_exceptions=Trueand the path is missing.
- create_empty_table_from_metadata(metadata: dict)¶
Creates an empty Delta table from a metadata definition dictionary.
Fabric does not support PRIMARY KEY or FOREIGN KEY constraints in Delta DDL, so only column definitions and NOT NULL constraints are generated. When
metadata["track_history"]isTrue, the five SCD Type-2 columns are appended automatically.- Parameters:
metadata (dict) – Metadata dictionary with
"table","columns", and"track_history"keys.
- find_lakehouse(lakehouse_name: str) str | None¶
Searches the cached list of workspace Lakehouses for an exact name match.
- Parameters:
lakehouse_name (str) – The display name of the Lakehouse to look up.
- Returns:
The Lakehouse display name if found,
Noneotherwise.- Return type:
str | None
- get_notebook_name() str¶
Returns the display name of the currently executing Fabric notebook.
- Returns:
The notebook name as reported by
notebookutils.runtime.context.- Return type:
str
- get_notebook_url() str¶
Returns a browser-accessible URL to the currently executing Fabric notebook.
- Returns:
A full HTTPS URL pointing to the notebook in the Fabric workspace UI.
- Return type:
str
- get_workspace_lakehouses() List[str]¶
Retrieves the display names of all Lakehouse items in the current Fabric workspace.
- Returns:
A list of Lakehouse display names available in the workspace.
- Return type:
list[str]
- move_file(source: str, destination: str, overwrite=True, create_missing_dirs: bool = False) bool¶
Moves a file from source to destination on OneLake using
notebookutils.fs.mv.- Parameters:
source (str) – OneLake / ABFS source path.
destination (str) – OneLake / ABFS destination path.
overwrite (bool) – If
True(default), remove an existing destination file before moving.create_missing_dirs (bool) – If
True, create the destination directory when it does not exist. Defaults toFalse.
- Returns:
Trueon success,Falseon any failure.- Return type:
bool
- resolve_filemask(mask_path: str, case_sensitive: bool = False, full_path: bool = False) List[str]¶
Resolves a filemask with wildcard into a list of matching file names. Matching is case-insensitive by default.
- Parameters:
mask_path (str) – Full path including a wildcard, e.g.
"abfss://raw@account.dfs.core.windows.net/exports/sales_*.csv".case_sensitive (bool) – When
True, match file names exactly as cased. Defaults toFalse.full_path (bool) – When
True, return full paths (folder ofmask_pathjoined with each name). Defaults toFalse.
- Returns:
- Sorted list of matching file base names, or full paths when
full_path=True. Returns an empty list if the folder does not exist or no files match.
- Return type:
list[str]
- static to_local_path(abfs_path: str, local_root: str = '/lakehouse/default') str¶
Convert an ABFS OneLake path to the local Lakehouse mount path.
The Fabric runtime mounts the default Lakehouse at
/lakehouse/default. This method strips theabfss://workspace@onelake…/lakehouse-id/prefix and rebuilds the path underlocal_root.- Parameters:
abfs_path – An
abfss://OneLake path.local_root – Mount point of the default Lakehouse. Defaults to
"/lakehouse/default".
- Returns:
Absolute local path under
local_root.- Veroorzaakt:
ValueError – When
abfs_pathdoes not match the expected OneLake pattern.
- validate_compatibility()¶
Validates that the Fabric environment meets the prerequisites required by the framework.
- Checks:
A default Lakehouse is attached to the currently running notebook.
The configured logging Lakehouse exists in the workspace.
The logging Lakehouse has schemas enabled (
defaultSchemaproperty set).
- Veroorzaakt:
PlatformValidationException – If any of the three checks above fail, with a descriptive message explaining what is missing and how to resolve it.