Forum Discussion

Charline_74's avatar
Charline_74
Resolver I
1 year ago
Solved

Change Default Lakehouse

Hello, In a notebook which is in DEV I use this code to get the ID of the Lakehouse in DEV and the ID of the Workspace DEV : df_Lakehouse = labs.list_lakehouses() lakehouse_row = df_Lakehouses[df_...
  • nilendraFabric's avatar
    1 year ago

    Hi Charline_74 

    To change the default lakehouse in a Microsoft Fabric notebook, you can use the %%configure magic command with the defaultLakehouse parameter. However, the issue in your code is that you're trying to use Python variables directly within the JSON configuration, which isn't possible. Instead, you need to format the JSON string with the variable values.

     

    could you please give this a try :


    df_Lakehouses = labs.list_lakehouses()
    lakehouse_row = df_Lakehouses[df_Lakehouses["Lakehouse Name"] == "Lakehouse"]
    lakehouse_id = lakehouse_row.iloc[0]["Lakehouse ID"]
    workspace_id = spark.conf.get("trident.workspace.id")

    %%configure -f
    {
    "defaultLakehouse": {
    "name": "Lakehouse",
    "id": "%s",
    "workspaceId": "%s"
    }
    }
    """ % (lakehouse_id, workspace_id)


    Please give kudos and mark this as solution if this helps.

    Thanks