2009-09-29 23 views

答えて

11

あなたはHadoopの中副作用ファイルの一意のIDが必要な場合は、このコードの仕事にしようと一意のIDを活用できます。相手に後期

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

ていますが、TaskAttemptIDを使用することができますクラスを使用してmapred.task.idプロパティを解析します。

int _attemptID; 

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

新しいHadoopのAPIを使用すると:私の場合、私は数字の試行値そのものを望んでいたし、私のマッパーに次のように使用

context.getTaskAttemptID().getTaskID().getId() 
関連する問題