Forum Discussion

smpa01's avatar
smpa01
Community Champion
1 year ago
Solved

DeltaTableBuilder without Lakehouse Context

delta =DeltaTable.createIfNotExists(spark).tableName("lakehouse_testing.t1").addColumn("id",IntegerType()).execute() ## the above fails but I see the following method doc (method) def tableName(ide...
  • v-lgarikapat's avatar
    1 year ago

    Hi smpa01 ,

    Thanks for reaching out to the Microsoft fabric community forum.

    BhaveshPatel 

    Thanks for your prompt response

     In Addition to BhaveshPatel ,

     

    In Microsoft Fabric not quite. The DeltaTableBuilder API requires an attached Lakehouse context to function properly. Without it, you'll hit errors like:

    • Spark SQL queries are only possible in the context of a lakehouse
    • SCHEMA_NOT_FOUND or IllegalArgumentException when resolving table paths

    Workaround: Use File Paths Instead
    If you're working outside Fabric (e.g., Databricks, Synapse, or even Fabric with advanced setup), you can bypass the Lakehouse attachment by writing directly to a file path:

    df.write \
    .format("delta") \
    .mode("overwrite") \
    .save("abfss://<workspace_id>@onelake.dfs.fabric.microsoft.com/<lakehouse_id>/Tables/<table_name>")

     

    This approach uses OneLake ABFS paths and doesn’t require the Lakehouse to be attached in the notebook UI.

     

     Alternative: Use CREATE EXTERNAL TABLE or %sql Magic You can also define Delta tables using SQL magic or external table syntax:

    %sql

    CREATE TABLE my_table (

      id INT

    ) USING DELTA

    LOCATION 'abfss://...'

     

    This works only when a Lakehouse is attached

     

     

     

    If you are still facing any challenges, we would be happy to assist you further.

    We appreciate your engagement and thank you for being an active member of the community.

    Best regards,
    LakshmiNarayana