Final review
CS224p
1
Key Languages and Frameworks we Learned
2
MapReduce
3
Word count
4
5
6
Hadoop Main Components
HDFS (Hadoop Distributed File System): This is the storage component of Hadoop, which allows for the storage of large amounts of data across multiple machines. It is designed to work with commodity hardware, which makes it cost-effective.
YARN (Yet Another Resource Negotiator): This is the resource management component of Hadoop, which manages the allocation of resources (such as CPU and memory) for processing the data stored in HDFS.
Hadoop is commonly used in big data scenarios such as data warehousing, business intelligence, and machine learning. It’s also used for data processing, data analysis, and data mining. It enables the distributed processing of large data sets across clusters of computers using a simple programming model.
7
8
9
10
MapReduce Code
11
public static class Map extends Mapper<LongWritable,Text,Text,IntWritable> {
public void map(LongWritable key, Text value, Context context) throws IOException,InterruptedException {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
value.set(tokenizer.nextToken());
context.write(value, new IntWritable(1));
}
public static class Reduce extends Reducer<Text,IntWritable,Text,IntWritable> {
public void reduce(Text key, Iterable<IntWritable> values,Context context)
throws IOException,InterruptedException {
int sum=0;
for(IntWritable x: values)
{
sum+=x.get();
}
context.write(key, new IntWritable(sum));
}
}
MapReduce
12
Resilient Distributed Datasets
RDD is a fundamental data structure in Apache Spark. It is an immutable distributed collection of objects that can be processed in parallel across a cluster of machines. RDDs provide fault tolerance, meaning they can recover from failures, and they enable efficient distributed data processing.
13
14
Spark
RDD Actions versus Transformations
RDDs support two types of operations:
15
Spark -intro
16
RDDread. Take (5)
Spark DataFrame
+---+-----+-------+
| id| name|age|
+---+-------+---+
| 1|abhay| 25|
| 2|banti| 25|
+---+------+---+
17
Spark - map
18
confusedRDD = sc.textFile("confused.txt")
mappedconfusion = confusedRDD.map(lambda line : line.split(" "))
mappedconfusion.take(5)
Spark - flatMap
19
flatMappedConfusion = confusedRDD.flatMap(lambda line : line.split(" "))
flatMappedConfusion.take(5)
onlyconfusion = confusedRDD.filter(lambda line : ("confus" in line.lower()))
onlyconfusion.count()
3
Spark - reduceByKey
20
data = [("a", 3), ("b", 4), ("a", 1)]
sc.parallelize(data).reduceByKey(lambda x, y: x + y) # Default parallelism
sc.parallelize(data).reduceByKey(lambda x, y: x + y, 10) # Custom parallelism
Given a collection of names and charges, compute total charge per name
21
22
Links
23