考えられる解決策は、ジョブを実行する前に stopwords.txt を HDFS にコピーし、Mapper のsetupメソッドで適切なデータ構造に読み込むことです。例えば:
MyMapper クラス:
...
private Map<String, Object> stopwords = null;
@Override
public void setup(Context context) {
Configuration conf = context.getConfiguration();
//hardcoded or set it in the jobrunner class and retrieve via this key
String location = conf.get("job.stopwords.path");
if (location != null) {
BufferedReader br = null;
try {
FileSystem fs = FileSystem.get(conf);
Path path = new Path(location);
if (fs.exists(path)) {
stopwords = new HashMap<String, Object>();
FSDataInputStream fis = fs.open(path);
br = new BufferedReader(new InputStreamReader(fis));
String line = null;
while ((line = br.readLine()) != null && line.trim().length() > 0) {
stopwords.put(line, null);
}
}
}
catch (IOException e) {
//handle
}
finally {
IOUtils.closeQuietly(br);
}
}
}
...
次に、map メソッドでストップワードを使用できます。
もう 1 つのオプションは、jobrunner クラスでストップワードを使用してマップ オブジェクトを作成し、それを Base64 でエンコードされた文字列にシリアル化し、それを Configuration オブジェクトのキーの値としてマッパーに渡し、setup メソッドで逆シリアル化することです。
最初のオプションを選択したのは、簡単だからというだけでなく、Configuration オブジェクトを介して大量のデータを渡すのは得策ではないからです。