Advent of 2021, Day 8 – Creating RDD files

Series of Apache Spark posts:

Spark is created around the concept of resilient distributed datasets (RDD). RDD is a fault-tolerant collection of files that can be used in parallel. RDDs can be created in two ways:
– parallelising an existing data collection in driver program
– referencing a datasets in external storage (HDFS, blob storage, shared filesystem, Hadoop InputFormat,…)

In a simple way, Spark RDD has two opeartions:
– transformations – creating a new RDD dataset on top of already existing one with the last transformation
– actions – to the action, and return a value to the driver program after running a computation on the dataset.

Map and reduce is where a map is a transformation that uses a function on each dataset and returns a new RDD file that holds the result. Reduce is a action that aggregates all the elements of RDD using a function and returns the result from last created RDD to driver program.

By default, each transformed of the RDD can be recomputed each time you run an action on it. But you can also persist RDD in the memory, and makes faster access to data, because it is cached.

Spark RDD (Low Level API) Basics using Pyspark | by Sercan Karagoz |  Analytics Vidhya | Medium

Using Python, we can run the cluster and start tinkering with a simple file (using my Advent of Code input data puzzle for day 7 , because 🙂 )

from pyspark.sql import SparkSession

spark:SparkSession = SparkSession.builder()
      .master("local[1]")
      .appName("UsingAoCData")
      .getOrCreate() 

And we prepare for parallelisation of the RDD:

data = [1,2,3,4,5,6,7,8,9,10,11,12]
rdd=spark.sparkContext.parallelize(data)

These files can be created on many different platforms (HDFS, local file,…) and will still have the same characteristics.

Furthermore, you can also create an empty RDD file and later populate it, you can partition the RDD files, create the whole text files and many other options.

When you use the methods:  parallelize()textFile() or wholeTextFiles() methods to store data into RDD, these will be automatically split into partitions (with limitations of resources available). Number of partitions – as we have already discussed – will be based upon the number of cores available in the system.

Tomorrow we will look into RDD operations (transformations and actions) 🙂

Compete set of code, documents, notebooks, and all of the materials will be available at the Github repository: https://github.com/tomaztk/Spark-for-data-engineers

Happy Spark Advent of 2021! 🙂

Tagged with: , , , ,
Posted in Spark, Uncategorized
19 comments on “Advent of 2021, Day 8 – Creating RDD files

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 ...