5. 모든 일을 MapReduce화 하라!
근데 이런 SQL을 어떻
게 MapReduce로 만들
지?
SELECT LAT_N, CITY,
TEMP_F
FROM STATS, STATION
WHERE MONTH = 7
AND STATS.ID =
STATION.ID
ORDER BY TEMP_F;
6. 모든 일을 MapReduce화 하라!
이런 Machine
learning/Data 분석 업
무는?
“지난 2007년부터 매월 나오
는 전국 부동산 실거래가 정
보에서 영향을 미칠 수 있는
변수 140개중에 의미있는 변
수 5개만 뽑아.”
“아, 마감은 내일이다.”
7. 코드도 이정도면 뭐? (단순히 단어세는 코드가…)
package org.myorg;
import java.io.IOException;
import java.util.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
public class WordCount {
public static class Map extends Mapper<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value, Context context) throws IOException,
InterruptedException {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
word.set(tokenizer.nextToken());
context.write(word, one);
}
}
}
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 val : values) {
sum += val.get();
}
context.write(key, new IntWritable(sum));
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = new Job(conf, "wordcount");
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
job.setMapperClass(Map.class);
job.setReducerClass(Reduce.class);
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
job.waitForCompletion(true);
}
19. Wordcount : Scala
val f = sc.textFile("README.md")
val wc = f.flatMap(l => l.split(" ")).map(word => (word,
1)).reduceByKey(_ + _)
wc.saveAsTextFile("wc_out.txt")
20. Wordcount : Scala
val f = sc.textFile("README.md")
===================
def textFile(path: String, minPartitions:
Int = defaultMinPartitions):RDD[String]
===================
Read a directory of text files from HDFS, a local file system
(available on all nodes), or any Hadoop-supported file
system URI.
32. Spark Model
● 데이타를 변환해가는 프로그램을 작성하는
것
● Resilient Distributed Dataset(RDDs)
○ Cluster로 전달할 memory나 disk에 저장될 object들
의 집합
○ 병렬 변환 ( map, filter…)등등으로 구성
○ 오류가 생기면 자동으로 재구성
55. 각 code 한 줄이 RDD!
val f = sc.textFile("README.md")
val wc = f.flatMap(l => l.split(" ")).map(word => (word,
1)).reduceByKey(_ + _)
wc.saveAsTextFile("wc_out.txt")