VinsData

Deep-dive technical essays & reference architecture on data mesh, Microsoft Fabric, Azure Synapse, and distributed computing architectures.

  • LinkedIn
contact@vinsdata.in

Curated Taxonomies

Microsoft FabricAzure SynapseETL & PipelinesData MeshReal-Time StreamingCost Optimization

Stay Connected

Get architectural summaries and high-speed notifications directly in your inbox every Tuesday.

Strictly technical content. We respect your privacy. No spam ever.

© 2026 VinsData Engineering & Architecture Journal. Written by Vinodh Kumar.

Privacy PolicyTerms of Service
Back to All Publications
Fabric Synapse4 MIN READ

Create Synapse Notebook and run Python and SQL under Spark Pool

Vinodh Kumar
Vinodh Kumar

Principal Data Architect · Mar 3, 2022

In this article we will look into how could we run both Python and SparkSQL queries in a single notebook workspace under the built-in Apache Spark Pools to transform the data in a single window.

Introduction:
In Azure synapse analytics, a notebook is where you can write live code, visualize and also comment text on them. It lets you test and get the output of the each cells rather than executing the entire script. The initial setup is very easy and you can leverage the built-in security features which helps your data stay secure. The notebooks can process across multiple data formats like RAW(csv, txt json), Processed(parquet, delta lake, orc) and SQL(tabular data files against spark & sql) formats. Apart from all the above benefits the built-in data visualization feature saves a lot of time and comes handy when dealing with subsets of data.

Notebooks can support multiple languages in different cells of a single notebook by specifying the magic commands at the start of the cell.

Magic commandLanguageDescription
%%pysparkPythonExecute a Python query against Spark Context.
%%sparkScalaExecute a Scala query against Spark Context.
%%sqlSparkSQLExecute a SparkSQL query against Spark Context.
%%csharp.NET for Spark C#Execute a .NET for Spark C# query against Spark Context.

Steps: This demo will be run on spark pool which has to be created first. Verify if the spark pool is already available if in case you have done some labs earlier or create a new one. The spark pool is similar to cluster that we create to run the queries, here in this demo ‘synsparkpool’ is the apache spark pool we are going to use for running the queries.

Go to development tab from the left side and create a new notebook as below.

Once created you can enter and query results block by block as you would do in Jupyter for python queries. Make sure the newly created notebook is attached to the spark pool which we created in the first step. You will also have an option to change the query language between pyspark, scala, c# and sparksql from the Language dropdown option.

From the first cell let’s try to create a PySpark data frame and display the results. I am going to generate some dummy data for this demo. Synapse notebooks comes with Intellisense loaded which autocompletes the keywords when you are typing the first letter in the cells.

Click the play button on top left to execute the queries in the cell. Please note that it might take some time to start the session when execution the first time, it took me 4.22 Mins to complete this but it is normal.

Now with the dataframe is created lets save them into temp table as you cannot reference data or variables directly across different languages.

See the above image where we are querying the dataframe using SQL query in the same session with another cell which proves that it is not restricted to only Python or Scala only.

Not only with few lines of sample data, most of the times you will have to import a complete CSV or Excel data from storage location directly onto the dataframe which can later be queried through SQL. In the next step we will demo how to import huge amount of data. I am going to load the ‘Financial_Sample_Jan2021_MINI.csv’ file saved in my ADLS Gen2 storage into a spark dataframe. For this I am copying the abfss path from file properties

Using the below spark query I have read the csv file data into the dataframe now.

dataframe_2 = spark.read.csv(“abfss://adlsfssyn@synadlsgen2.dfs.core.windows.net/Financial_Sample_Jan2021_MINI.csv”,header=True)

dataframe_2.show()

The same dataframe can be used to create a temp table or view and then queried through sql. Please note that if you try to query the dataframe directly from SQL you will get the following error.

Summary:

This is basic and simple exercise to show how synapse notebook helps query multiple languages in a single window. One can use python to load/transform and sql language query to query the same data from temp table.

Article Topics & Tags

#Microsoft Fabric#Python#SQL
0 responses
Vinodh Kumar

Written by

Vinodh Kumar

Principal Data Architect · Author of VinsData

Hands-on enterprise architectural advice, bench-marked patterns, and field notes on Microsoft Fabric, Synapse, Databricks, and modern data platforms.

Published in VinsData JournalView Full Profile

Subscribe to Architectural Insights

Get field essays on Fabric, Synapse, and data architectures directly in your inbox every Tuesday.

Responses (0)

Community discussion

No responses yet

Be the first to share your perspective or ask a question about this architecture.

Recommended Reading

More From VinsData

View all publications
Lakehouse Architecture

Rethinking Modern Data Architecture: How to Design Data Systems That Actually Matter

An inquiry into over-engineered pipelines, real-time obsessions, and how simplicity in Microsoft Fabric and Lakehouses beats high-power compute every single time.

Jul 27, 20266 min read
Practical Guide

Fabric as an App Platform: Evaluating the Rayfin Shift

Microsoft introduced Rayfin at Build 2026, positioning it as a way to build and run application backends directly inside Microsoft Fabric. I...

Jun 8, 20265 min read
Cost Optimization

How Fabric Data Agent Actually Consumes Your Capacity: A Practical Guide to Cost Optimisation

When you first roll out the Fabric data agent, it usually feels like a big win. Suddenly, business users do not need to depend on SQL or dat...

May 12, 20265 min read