MSSparkUtils is the Swiss Army knife inside Synapse Spark
I've been reviewing customer questions centered around "Have I tried using MSSparkUtils to solve the problem?"
One of the questions asked was how to share results between notebooks. Every time you hit "run" in a notebook, it starts a new Spark cluster which means that each notebook would be using different sessions. Making it impossible to share results between executions of notebooks. MSSparkUtils offers a solution to handle this exact scenario.
What is MSSparkUtils?
MSSparkUtils is a built-in package to help you easily perform common tasks called Microsoft Spark utilities. It is like a Swiss knife inside of the Synapse Spark environment.
Some scenarios where it could be used are for example:
- Work with file systems
- Get environment variables
- Chain notebooks together
- Get a data frame shared execution between notebooks
These scenarios are covered in more detail in the doc: Introduction to Microsoft Spark utilities - Azure Synapse Analytics
This blog will focus on the chained execution and sharing results between notebooks.
Chain notebooks together
You can execute more than one notebook through a root notebook using the method run or exit.
- Run allows running another notebook referenced on the same session of the main notebook
- Exit allows a run of another notebook referenced on the same session of the main notebook
Azure Synapse will return an exit value, complete the pipeline run, and stop the Spark session.
Follow an example in 2 steps:
- A notebook called Simple_read_ is just reading data from a test.parquet into a data frame called df shown in Fig. 1- simple_read:
Fig. 1 - simple_read
2. Now, I created a second notebook called sharing_results which is executing the first notebook - Simple_read_ created in step 1. Fig. 2 - sharing_results will show the results of the chained execution:
Fig. 2 - sharing_results
How to share a data frame execution between notebooks?
That is a quite simple enhancement of the chaining notebook logic. If we transfer the results from the simple_read_ notebook into a view and execute it from the main notebook the execution will be happening on the same session. Therefore, the Sharing_results notebook will be able to see the results from the simple_read notebook.
For more information about what it means same session, review the docs:
Code example for the notebook Simple_read_ in Pyspark:
The following Fig. 3 - Enhanc. Simple_read_ shows this idea:
Fig. 3 - Enhanc. Simple_read_
Code example for the notebook Sharing_results in Pyspark:
Fig 4- Enhance, shows the results for the notebook that was chained and kept on the same session:
Fig 4 - Enhance
The following image shows the process of how it works:
Fig. 5 - Flux
Summary
MSSparkUtils is like a Swiss knife inside the Synapse Spark environment. That allows you to achieve more from the Synapse Spark environment and even share the same session between notebooks which could be also used even in other scenarios for example when you want to reuse parameters between notebooks on the same session.
That's it for this blog and I hope this can help you and your learning journey with Synapse!
Published on:
Learn moreWe can help you with MSSparkUtils is the Swiss Army knife inside Synapse Spark
If you want help implementing, troubleshooting, or improving this product, contact us and we’ll point you in the right direction.
Related posts
We're moving!
We’re moving to the Analytics on Azure Tech Community! All new Azure Synapse Analytics content will be published there. In the next few days a...
Upgrade to Azure Synapse runtimes for Apache Spark 3.4 & previous runtimes deprecation
It is important to stay ahead of the curve and keep services up to date. That's why we encourage all Azure Synapse customers with Apache ...
ADF\Synapse Analytics - Replace Columns names using Rule based mapping in Mapping data flows
In real time, the column names from source might not be uniform, some columns will have a space in it, some other columns will not. For exampl...
Interpreting Script activity output json with Azure Data Factory\Synapse analytics
Script activity in Azure Data Factory\ Synapse analytics is very helpful to run queries against data sources mentioned here in this document.&...
Synapse Connectivity Series Part #4 - Advanced network troubleshooting and network trace analysis
Continuing the series of this blog posts I would like to go more advanced on troubleshooting connectivity issues. I would like to thank also&n...
Boost your CICD automation for Synapse SQL Serverless by taking advantage of SSDT and SqlPackage CLI
Introduction Azure Synapse Analytics Serverless SQL is a query service mostly used over the data in your data lake, for data discovery,...
Metadata-Based Ingestion in Synapse with Delta Lake
Overview The crucial first step in any ETL (extract, transform, load) process or data engineering program is ingestion, w...
Missing Fields Added to Dedicated SQL pool Diagnostic Settings Logs
Over the past year, customers have informed the team there were a set of key columns missing in the standalone Dedicated SQL pools (formerly S...
Using Azure DevOps with Synapse Workspaces to create hot fixes in production environments
Have you ever deployed a release to production only to find out a bug has escaped your testing process and now users are being severely impact...
Azure Synapse MVP Corner - March 2023
About this blog series Microsoft Most Valuable Professionals, or MVPs, are technology experts who passionately share their knowledge with the ...