-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExemploIGTIMES.java
114 lines (83 loc) · 4.1 KB
/
ExemploIGTIMES.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package IGTI;
import java.io.*;
import java.util.*;
import java.util.Random;
import java.text.*;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.fs.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;
public class ExemploIGTI extends Configured implements Tool
{
public static void main (final String[] args) throws Exception {
int res = ToolRunner.run(new Configuration(), new ExemploIGTI(), args);
System.exit(res);
}
public int run (final String[] args) throws Exception {
try{
JobConf conf = new JobConf(getConf(), ExemploIGTI.class);
conf.setJobName("Calculo Covid19");
final FileSystem fs = FileSystem.get(conf);
Path diretorioEntrada = new Path("PastaEntrada"), diretorioSaida = new Path("PastaSaida");
fs.mkdirs(diretorioEntrada);
fs.copyFromLocalFile(new Path("/usr/local/hadoop/Dados/covidData.txt"), diretorioEntrada);
FileInputFormat.setInputPaths(conf, diretorioEntrada);
FileOutputFormat.setOutputPath(conf, diretorioSaida);
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(Text.class);
conf.setMapperClass(MapIGTI.class);
conf.setReducerClass(ReduceIGTI.class);
JobClient.runJob(conf);
}
catch ( Exception e ) {
throw e;
}
return 0;
}
public static class MapIGTI extends MapReduceBase implements Mapper<LongWritable, Text, Text, Text> {
public void map(LongWritable key, Text value, OutputCollector<Text, Text> output, Reporter reporter) throws IOException {
Text txtChave = new Text();
Text txtValue = new Text();
String[] dadosCovid = value.toString().split(",");
String mesEvento = dadosCovid[0].substring(5, 7);
String paisEvento = dadosCovid[2];
int novosCasos = Integer.parseInt(dadosCovid[4]);
int novosObitos = Integer.parseInt(dadosCovid[6]);
String strChave = mesEvento + "|" + paisEvento;
String strValor = String.valueOf(novosCasos) + "|" + String.valueOf(novosObitos);
txtChave.set(strChave);
txtValue.set(strValor);
output.collect(txtChave, txtValue);
}
}
public static class ReduceIGTI extends MapReduceBase implements Reducer<Text, Text, Text, Text> {
public void reduce (Text key, Iterator<Text> values, OutputCollector<Text, Text> output, Reporter reporter) throws IOException {
int somaCasos = 0, somaObitos = 0;
Text value = new Text();
String[] campos = new String[2];
String[] camposChave = new String[2];
String strSaida = "";
camposChave = key.toString().split("\\|");
while (values.hasNext()) {
value = values.next();
campos = value.toString().split("\\|");
somaCasos += Integer.parseInt(campos[0]);
somaObitos += Integer.parseInt(campos[1]);
}
strSaida = "Mes: " + camposChave[0] + " em " + camposChave[1] + ":";
strSaida += "Total casos:: " + String.valueOf(somaCasos);
strSaida += "Total obitos: " + String.valueOf(somaObitos);
value.set(strSaida);
output.collect(key, value);
}
}
public static class MapIGTIMaior extends MapReduceBase implements Mapper<LongWritable, Text, Text, Text> {
public void map(LongWritable key, Text value, OutputCollector<Text, Text> output, Reporter reporter) throws IOException {
}
}
public static class ReduceIGTIMaior extends MapReduceBase implements Reducer<Text, Text, Text, Text> {
public void reduce (Text key, Iterator<Text> values, OutputCollector<Text, Text> output, Reporter reporter) throws IOException {
}
}
}