jeudi 24 août 2017

Compatible code of format function in Java

How Can I replace this line String str = String.format("%d\t%f", count, total); Actually this is a Reducer class of a MapReduce join. I want to replace this line with any other compatible code like simple assignment of two strings count and total. Is it possible?

public static class ReduceJoinReducer extends Reducer<Text, Text, Text, Text> {
public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
    String name = ""; //For Cust ID
    double total = 0.0; // For Amount Count
    int count = 0; // For Visit Count
    for (Text t : values) {
        String parts[] = t.toString().split("\t");
        if (parts[0].equals("tnxn")) 
        {
            count++;
            total += Float.parseFloat(parts[1]);
        }
        else if (parts[0].equals("cust")) 
        {
            name = parts[1];
        }
    }
    String str = String.format("%d\t%f", count, total);
    context.write(new Text(name), new Text(str));
}
}

Aucun commentaire:

Enregistrer un commentaire