Advent of 2023, Day 4 – Delta lake and delta tables in Microsoft Fabric

In this Microsoft Fabric series:

  1. Dec 01: What is Microsoft Fabric?
  2. Dec 02: Getting started with Microsoft Fabric
  3. Dec 03: What is lakehouse in Fabric?

Yesterday we looked into lakehouse and learned that Delta tables are the storing format. So, let’s explore what and how we can go around understanding and working with delta tables. But first we must understand delta lake.

Delta Lake is an open-source storage framework that enables building the lakehouse data layers. With Spark-based data lake processing, it adds the relational database framework to data lake processing.

Delta Lake brings so many outstanding and needed features to end users in Microsoft Fabric. Just to name a few: bringing ACID transactions (great serializability, strongest level of isolation(s)), time travel to revert to earlier states of data, scalable metadata to handle petabyte-scale tables, efficient DML operations (with interoperable APIs), history auditing and many more.

Based on this layer, delta tables in Microsoft Fabric, are created (signified by the triangular Delta () icon on tables in the lakehouse user interface). Delta tables are schema abstractions over data files, that are stored in Delta format. For each table, the lakehouse stores a folder containing Parquet data files and a _delta_Log folder in which transaction details are logged in JSON format.

Create a delta table

In the same lakehouse, we have created in previous blogpost, we will create a new notebook.

But before we start writing any Spark code, let’s upload a sample file (iris.csv) that is available my github repository.

In the dialog window select the file from your preferred location and upload it

And the file will be available in the lakehouse explorer under files:

Let’s go back to notebook, we created earlier and run the following PySpark code:

# Welcome to your new notebook
# Type here in the cell editor to add code!

# Load a file into a dataframe
df = spark.read.load('Files/iris.csv', format='csv', header=True)

# Save the dataframe as a delta table
df.write.format("delta").saveAsTable("iris_data")

And congratulations, we have created a first delta table (table is signified with triangle code)

Data can be introduced to Delta lake in so many ways, this one is – for the sake of demo – the easiest to replicate. We can introduce the external files (abfss://..) or get data through API.

With delta table now available, we can choose the language of choice and drill the data. How about using Spark SQL.

%%sql

SELECT 
'Sepal.Length'
,'Sepal.Width'
,Species
FROM iris_data
WHERE Species = "setosa"
LIMIT 5;

Or using R:

%%sparkr
library(SparkR)

deltaDataframe <- read.df(path = "abfss://18xxxx-xxxxxxxxx@onelake.dfs.fabric.microsoft.com/{yourGUID}/Tables/iris_data", source = "delta")

Or Python:

from delta.tables import *
from pyspark.sql.functions import *

# Create a DeltaTable object
delta_path = "abfss://18xxxx-xxxxxxxxx@onelake.dfs.fabric.microsoft.com/{yourGUID}/Tables/iris_data"
deltaTable = DeltaTable.forPath(spark, delta_path)

Tomorrow we will look continue exploring the delta tables and it’s great features!

Complete set of code, documents, notebooks, and all of the materials will be available at the Github repository: https://github.com/tomaztk/Microsoft-Fabric

Happy Advent of 2023! 🙂

Tagged with: , , , , , , ,
Posted in Fabric, Uncategorized
23 comments on “Advent of 2023, Day 4 – Delta lake and delta tables in Microsoft Fabric
  1. […] article was first published on R – TomazTsql, and kindly contributed to R-bloggers]. (You can report issue about the content on this page […]

    Like

  2. […] Dec 04: Delta lake and delta tables in Microsoft Fabric […]

    Like

  3. […] Dec 04: Delta lake and delta tables in Microsoft Fabric […]

    Like

  4. […] Dec 04: Delta lake and delta tables in Microsoft Fabric […]

    Like

  5. […] Dec 04: Delta lake and delta tables in Microsoft Fabric […]

    Like

  6. […] Dec 04: Delta lake and delta tables in Microsoft Fabric […]

    Like

  7. […] Dec 04: Delta lake and delta tables in Microsoft Fabric […]

    Like

  8. […] Dec 04: Delta lake and delta tables in Microsoft Fabric […]

    Like

  9. […] Dec 04: Delta lake and delta tables in Microsoft Fabric […]

    Like

  10. […] Dec 04: Delta lake and delta tables in Microsoft Fabric […]

    Like

  11. […] Dec 04: Delta lake and delta tables in Microsoft Fabric […]

    Like

  12. […] Dec 04: Delta lake and delta tables in Microsoft Fabric […]

    Like

  13. […] Dec 04: Delta lake and delta tables in Microsoft Fabric […]

    Like

  14. […] Dec 04: Delta lake and delta tables in Microsoft Fabric […]

    Like

  15. […] Dec 04: Delta lake and delta tables in Microsoft Fabric […]

    Like

  16. […] Dec 04: Delta lake and delta tables in Microsoft Fabric […]

    Like

  17. […] Dec 04: Delta lake and delta tables in Microsoft Fabric […]

    Like

  18. […] Dec 04: Delta lake and delta tables in Microsoft Fabric […]

    Like

  19. […] Dec 04: Delta lake and delta tables in Microsoft Fabric […]

    Like

  20. […] Kaštrun has a blog series on getting into fabric which shows how easy it is to create a PySpark notebook. I am a bit frustrated that I didn’t realize notebooks were a valid ETL tool, I always thought of […]

    Like

Leave a comment

Follow TomazTsql on WordPress.com
Programs I Use: SQL Search
Programs I Use: R Studio
Programs I Use: Plan Explorer
Rdeči Noski – Charity

Rdeči noski

100% of donations made here go to charity, no deductions, no fees. For CLOWNDOCTORS - encouraging more joy and happiness to children staying in hospitals (http://www.rednoses.eu/red-noses-organisations/slovenia/)

€2.00

Top SQL Server Bloggers 2018
TomazTsql

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

Discover WordPress

A daily selection of the best content published on WordPress, collected for you by humans who love to read.

Revolutions

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

tenbulls.co.uk

tenbulls.co.uk - attaining enlightenment with the Microsoft Data and Cloud Platforms with a sprinkling of Open Source and supporting technologies!

SQL DBA with A Beard

He's a SQL DBA and he has a beard

Reeves Smith's SQL & BI Blog

A blog about SQL Server and the Microsoft Business Intelligence stack with some random Non-Microsoft tools thrown in for good measure.

SQL Server

for Application Developers

Business Analytics 3.0

Data Driven Business Models

SQL Database Engine Blog

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

Search Msdn

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

R-bloggers

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

R-bloggers

R news and tutorials contributed by hundreds of R bloggers

Data Until I Die!

Data for Life :)

Paul Turley's SQL Server BI Blog

sharing my experiences with the Microsoft data platform, SQL Server BI, Data Modeling, SSAS Design, Power Pivot, Power BI, SSRS Advanced Design, Power BI, Dashboards & Visualization since 2009

Grant Fritchey

Intimidating Databases and Code

Madhivanan's SQL blog

A modern business theme

Alessandro Alpi's Blog

DevOps could be the disease you die with, but don’t die of.

Paul te Braak

Business Intelligence Blog

Sql Insane Asylum (A Blog by Pat Wright)

Information about SQL (PostgreSQL & SQL Server) from the Asylum.

Gareth's Blog

A blog about Life, SQL & Everything ...