When you use Microsoft Fabric Lakehouse as Prepare instance storage, you can use the customize code feature to add a custom script that is executed along with the table. To be specific, the script will be added as a custom cell in table deployment notebook. This cell is executed as the last step before persisting all tables.
A custom script can be added to multiple tables and can reference other existing tables, fields and custom scripts. An initial deployment is necessary before adding custom code. The script is entered as a ‘Custom Fabric Script’ and then mapped to the table using the customize code feature.
Add a Custom Fabric Script
To add a Custom Fabric Script, follow the steps below.
- Right-click the Scripts menu in the data area and click Add Custom Fabric Script
- In the script window, write a PySpark script compatible with the supported environment (Spark 3.4, Delta 2.4). Tables, fields and other custom scripts can be dragged into the editor and added as parameters.
Add a script to deployment notebook
To add the script to the table where code should be customized, follow the steps below.
- Right-click the table you want to add the script to, click Advanced and then click Customize Code.
- Click Add Fabric Script and, in the window that appears, select the script you want to use from Script list.
- Check that the script has been added to the notebook right before the “Persist Data” block, then click OK.