Fondamenti di Big Data con PySpark
Upendra Devisetty
Science Analyst, CyVerse


Trasformazioni RDD di base
map(), filter(), flatMap() e union()
RDD = sc.parallelize([1,2,3,4])
RDD_map = RDD.map(lambda x: x * x)

RDD = sc.parallelize([1,2,3,4])
RDD_filter = RDD.filter(lambda x: x > 2)

RDD = sc.parallelize(["hello world", "how are you"])
RDD_flatmap = RDD.flatMap(lambda x: x.split(" "))

inputRDD = sc.textFile("logs.txt")
errorRDD = inputRDD.filter(lambda x: "error" in x.split())
warningsRDD = inputRDD.filter(lambda x: "warnings" in x.split())
combinedRDD = errorRDD.union(warningsRDD)
Operazioni che restituiscono un valore dopo aver eseguito un calcolo sull'RDD
Azioni RDD di base
collect()
take(N)
first()
count()
collect() restituisce tutti gli elementi del dataset come array
take(N) restituisce un array con i primi N elementi del dataset
RDD_map.collect()
[1, 4, 9, 16]
RDD_map.take(2)
[1, 4]
RDD_map.first()
[1]
RDD_flatmap.count()
5
Fondamenti di Big Data con PySpark