-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExemploIGTI_games.java
121 lines (81 loc) · 4.02 KB
/
ExemploIGTI_games.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
114
115
116
117
118
119
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{
// objeto conf para empacotar o programa
JobConf conf = new JobConf(getConf(), ExemploIGTI.class);
conf.setJobName("Dados de Games");
final FileSystem fs = FileSystem.get(conf);
Path diretorioEntrada = new Path("DADOS_GAME"), diretorioSaida = new Path("pastaSaida");
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 txtValor = new Text();
String[] dadosGame = value.toString().split(",");
// value é usado do metodo aqui temos um vetor de Strings que vai receber cada posiçao da linha porque esta separada por virgula split faz a separaçao dos elementos que estao separados por virgula
String nomeJogo = dadosGame[1];
String anoLancamento = dadosGame[3];
double vendasAmerica = Double.parseDouble(dadosGame[6]);
double vendasEuropa = Double.parseDouble(dadosGame[7]);
String strValor = nomeJogo + "|" + String.valueOf(vendasAmerica + vendasEuropa);
txtChave.set(anoLancamento);
txtValor.set(strValor);
output.collect(txtChave,txtValor);
}
}
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 {
double maiorFaturamento = 0, valorVenda = 0;
String[] dadosVendas = new String[2];
String nomeJogo ="";
Text value = new Text();
while (values.hasNext()){
value = values.next();
dadosVendas = value.toString().split("\\|");
valorVenda = Double.parseDouble(dadosVendas[1]);
if(valorVenda > maiorFaturamento){
maiorFaturamento = valorVenda;
nomeJogo = dadosVendas[0];
}
}
String strValor = nomeJogo + "|" + String.valueOf(maiorFaturamento);
value.set(strValor);
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 {
}
}
}