2009-09-29 21 views

Respuesta

11

Si necesita un identificador único para un archivo de efectos secundarios en Hadoop, puede aprovechar el intento de identificación única en el trabajo con este código:

public static String getAttemptId(Configuration conf) throws IllegalArgumentException 
    { 
     if (conf == null) { 
      throw new NullPointerException("conf is null"); 
     } 

     String taskId = conf.get("mapred.task.id"); 
     if (taskId == null) { 
      throw new IllegalArgumentException("Configutaion does not contain the property mapred.task.id"); 
     } 

     String[] parts = taskId.split("_"); 
     if (parts.length != 6 || 
       !parts[0].equals("attempt") || 
       (!"m".equals(parts[3]) && !"r".equals(parts[3]))) { 
      throw new IllegalArgumentException("TaskAttemptId string : " + taskId + " is not properly formed"); 
     } 

     return parts[4] + "-" + parts[5]; 
    } 
4

tarde a la fiesta, pero se puede utilizar el TaskAttemptID clase para analizar la propiedad mapred.task.id.

En mi caso, yo quería que el valor numérico intento de sí mismo y utilizó la siguiente en mi Mapper:

int _attemptID; 

@Override 
public void configure(JobConf conf) { 
    TaskAttemptID attempt = TaskAttemptID.forName(conf.get("mapred.task.id")); 
    _attemptID = attempt.id(); 
} 
9

Con la nueva API de Hadoop:

context.getTaskAttemptID().getTaskID().getId() 
Cuestiones relacionadas