0
我有2(2)日誌文件包含相同的信息與類似的結構(認爲日誌B作爲'備份')。在地圖過濾性能調整
Log A: branchId, createdAt, value, subBranchId, etc..
Log B: branchId, createdAt, value
現在A.value
失蹤,我想B.value
來取代它。
這是我的嘗試。它在我的本地主機上以小數據運行良好,但在生產環境中運行時會永久存在。
JavaRDD<String> logA = sc.textFile(oldFilePath).cache();
JavaRDD<String> logB = sc.textFile(newFilePath).cache();
mappedLogB = logB.map(new Function<String, LogB>() {
private static final long serialVersionUID = 4815459211285505398L;
public LogB call(String s) throws JsonParseException, JsonMappingException, IOException {
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(s, LogB.class);
}
}).cache();
JavaRDD<String> revisedLogA = logA.map(new Function<String, String>() {
private static final long serialVersionUID = -6211649129122188980L;
public String call(String s) {
String[] splitted = s.split("\t");
String branchId = splitted[0];
String createdAt = splitted[1];
String value = splitted[2];
if (StringUtils.isEmpty(value)) {
JavaRDD<LogB> filtered = mappedLogB.filter(new FilteredLogB(branchId, createdAt));
if (filtered.count() == 1) {
splitted[2] = filtered.first().getValue();
}
}
return StringHelper.toTabSeparatedString(Arrays.asList(splitted));
}
});
revisedLogA.saveAsTextFile(saveOldFilePath);
對於如何優化它你有什麼建議嗎?我認爲mappedLogB.filter
效率不高,但直到現在我還不知道其他方式來獲得我想要的。
謝謝你的回答,我會盡量使用你的想法。 – shankshera