Forum Discussion
Spark Job Definition vs Notebooks
Hi,
Is there a reason for a spark job definition not accept a notebook from the portal and requires us to download the notebook as a .py file and upload again to the job definition, requiring a manual synchronization if we need to change the script?
Kind Regards,
Dennes
- Anonymous2 years ago
Hi DennesTorres ,
Yes, you are correct we need to use "spark.catalog", it will list out all the lakehouses present inside the workspace, even if not linked to the notebook.
Code:lakehouses = spark.catalog.listDatabases() lakehouse_list = [] for lakehouse in lakehouses: lakehouse_list.append(lakehouse.name) print(lakehouse_list)
In order get list of tables present inside particular lakehouse, you can refer below -
Code:# Get the list of lakehouses to read tables from. lakehouses = ["gopi_lake_house", "gopi_lakehouse_2"] # Loop through the lakehouses and read all tables from each lakehouse. for lakehouse in lakehouses: tables = spark.sql(f"SHOW TABLES IN {lakehouse}") tables.show()
Note: SHOW TABLES IN - will be working even if the lakehouse is not default. In my case only gopi_lakehouse_2 is selected as default, but I am able to see tables present inside gopi_lake_house and gopi_lakehouse_2.
For Example:
Executed in Fabric Notebooks:
Executed in Spark Job Application:
The above code is working fine both in notebook and spark job application.
Hope this was helpful. Hi,
Using the information provided until this point, I was able to write a code to make the maintenance of all lakehouses in the same workspace.
The Spark Job Definition, on the other way, can be linked to multiple workspaces. One of the workspace is turned into the default workspace while the other workspaces become a configuration.
We can loop through the configurations and use mssparkutils to make the mount of the lakehouse addresses as local folders.
Once mounted, we loop through the mounts discovering the tables of each lakehouse and executing the maintenance.
It worked like a charm, I will write an article about it.
Thank you for all the help!
Kind Regards,
Dennes
17 Replies
- AnonymousNot applicable
Hi DennesTorres - Thanks for using Fabric Community,
As I understand you are trying to run/schedule notebook code using Spark Job Definition in MS Fabric.
Accessing notebook directly in spark job definition from the portal - it is not supported as of now.
I would like to understand why are you looking for this feature and what are you trying to do with Spark Job Definition, when we can actually run/schedule the code with the help of notebooks in Fabric.
I have attached screenshots for your reference regarding how to schedule jobs in notebook.
Please do let us know if you have further queries.- DennesTorresImpactful Individual
Hi,
I confess I missed this feature, scheduling a notebook directly, without using a spark job definition. I'm trying to schedule a maintenance job which would run over multiple lakehouses, the spark job definition allows the link with multiple lakehouses, I was in hope this could work.
Kind Regards,Dennes
However, If I understand correctly, this feature will allow the notebook to be executed over one lakehouse.
- AnonymousNot applicable
Hi DennesTorres ,
We can use multiple lakehouses in single notebook.
I have attached screenshot inorder how can we add multiple lakehouses in notebook.
Hope this helps.