Untitled
unknown
plain_text
a year ago
896 B
18
Indexable
package tn.bigdata.tp1;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import java.io.IOException;
public class SalesMapper extends Mapper<Object, Text, Text, DoubleWritable> {
private Text store = new Text();
private DoubleWritable cost = new DoubleWritable();
public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
String[] fields = value.toString().split("\\s+"); // Délimitation par espaces
if (fields.length == 6) { // Vérifie que la ligne a bien les 6 champs attendus
String storeName = fields[2]; // Nom du magasin
double saleCost = Double.parseDouble(fields[4]); // Coût de la vente
store.set(storeName);
cost.set(saleCost);
context.write(store, cost);
}
}
}
Editor is loading...
Leave a Comment