官术网_书友最值得收藏!

Right outer join

Right outer join gives all rows in right side table, as well as the common rows on both the left and right (inner join). Use this to get all of the rows in the right table, along with the rows found in both left and right tables. Fills in NULL if not in left. The performance here is similar to the left outer join previously mentioned in this table:

We will consider the cities and temperatures only if the cityID has both records or only temperature measurements are included, as shown in the following code:

private static class RightOuterJoinReducer
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) {
result.set(sum / n);
context.write(cityName, result);
}
}
}

The output will be as follows:

Boston 22
New York 23
Chicago 23
Philadelphia 23
San Francisco 22
city-6 22 //city ID 6 has no name in cities.csv only temperature measurements
主站蜘蛛池模板: 富阳市| 贡觉县| 丽水市| 靖江市| 蒲城县| 永新县| 阿坝| 珲春市| 青铜峡市| 建平县| 兴宁市| 丹江口市| 萨嘎县| 西宁市| 正宁县| 布尔津县| 浮山县| 大洼县| 榆社县| 乌恰县| 阿拉尔市| 陵川县| 莫力| 永清县| 汝阳县| 额济纳旗| 故城县| 正宁县| 山东省| 本溪市| 栾城县| 鹤庆县| 溆浦县| 汝南县| 和龙市| 石泉县| 水城县| 瑞昌市| 商河县| 昌宁县| 名山县|