Fundamentos de big data con PySpark
Upendra Devisetty
Science Analyst, CyVerse


Transformaciones básicas de RDD
map(), filter(), flatMap() y 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)
Operaciones que devuelven un valor tras calcular sobre el RDD
Acciones básicas de RDD
collect()
take(N)
first()
count()
collect() devuelve todos los elementos del conjunto como un array
take(N) devuelve un array con los primeros N elementos
RDD_map.collect()
[1, 4, 9, 16]
RDD_map.take(2)
[1, 4]
RDD_map.first()
[1]
RDD_flatmap.count()
5
Fundamentos de big data con PySpark