Forum Discussion

mmcanelly's avatar
mmcanelly
Helper II
6 months ago
Solved

Difference between PySpark .saveAsTable() and .save()

I am loading many different flat files from the Files section of my lakehouse to delta tables via a Notebook. Most of the files I'm working with are relatively small (from 5 to 50,000 rows), with a h...
  • deborshi_nag's avatar
    6 months ago

    Hello mmcanelly That's an interesting observation! I have not experienced that myself, but it is probably because of the order of things in which data is written to using those methods. By the way, both methods end up producing a managed Delta table, however internally it interprets as "path-write" (.save) and "table-write" (.saveAsTable). 

     

    When you're using table-write Fabric registers with catalog and sql_endpoint so that the table is immediately visible, whereas using path-write it simply writes to the /Tables area and let Fabric auto-register to the catalog, that will eventually surface the table on the sql_endpoint. That explains your experience with latency using the saveAsTable method. 

     

    If your use case doesn't demand that the table is immediately available on sql_endpoint, you could follow the appraoch of using save() rather than saveAsTable(). 

     

    I would like to point out that I could not find any documentation on Fabric that explains the internal working. In documentation it always uses .save to write to /Files and .saveAsTable to write to /Tables.