import pandas as pd import struct import sqlalchemy import pyodbc import notebookutils import sempy.fabric as fabric from sqlalchemy import text import time # ----------------------------------------------------------------------------- # Helper function: Create a SQLAlchemy engine with Fabric token-based auth # ----------------------------------------------------------------------------- def create_fabric_engine(connection_string: str) -> sqlalchemy.engine.Engine: """ Create a SQLAlchemy engine for connecting to a Fabric SQL endpoint using token-based authentication. Args: connection_string (str): ODBC connection string. Returns: sqlalchemy.engine.Engine: SQLAlchemy engine configured for Fabric. """ # Retrieve Fabric token token = notebookutils.credentials.getToken( 'https://analysis.windows.net/powerbi/api' ).encode("UTF-16-LE") # Pack token into binary structure required by ODBC token_struct = struct.pack(f'