- Big Data Analytics with Hadoop 3
- Sridhar Alla
- 201字
- 2021-06-25 21:26:19
Left anti join
Left anti join gives only those rows from the left hand side table based that are not present in the right hand side table. Use this when you want to keep rows from the left table only when not present in right table. This provides very good performance, as only one table is fully considered and the other is only checked for the join condition:

We will consider the cities and temperatures if the cityID has only, name and no temperature records, as shown in the following code:
private static class LeftAntiJoinReducer
extends Reducer<Text, Text, Text, IntWritable> {
private IntWritable result = new IntWritable();
private Text cityName = new Text("Unknown");
public void reduce(Text key, Iterable<Text> values,
Context context) throws IOException, InterruptedException {
int sum = 0;
int n = 0;
for (Text val : values) {
String strVal = val.toString();
if (strVal.length() <=3)
{
sum += Integer.parseInt(strVal);
n +=1;
} else {
cityName = new Text(strVal);
}
}
if (n==0 ) {
if (n==0) n=1;
result.set(sum / n);
context.write(cityName, result);
}
}
}
The output will be as shown in the following code:
Las Vegas 0 // city of Las vegas has no temperature measurements in temperature.csv
推薦閱讀
- 電氣自動(dòng)化專業(yè)英語(yǔ)(第3版)
- 21天學(xué)通PHP
- Google App Inventor
- 流處理器研究與設(shè)計(jì)
- Hybrid Cloud for Architects
- 變頻器、軟啟動(dòng)器及PLC實(shí)用技術(shù)260問(wèn)
- 信息物理系統(tǒng)(CPS)測(cè)試與評(píng)價(jià)技術(shù)
- 人工智能趣味入門:光環(huán)板程序設(shè)計(jì)
- Docker on Amazon Web Services
- 單片機(jī)原理實(shí)用教程
- INSTANT VMware vCloud Starter
- 嵌入式Linux系統(tǒng)實(shí)用開(kāi)發(fā)
- Mastering OpenStack(Second Edition)
- 電氣控制及Micro800 PLC程序設(shè)計(jì)
- Keras Reinforcement Learning Projects