tv.icntv.recommend.algorithm.correlate.CorrelateOutPutReducer.java Source code

Java tutorial

Introduction

Here is the source code for tv.icntv.recommend.algorithm.correlate.CorrelateOutPutReducer.java

Source

/* Copyright 2013 Future TV, Inc.
 *
 *      Licensed under the Apache License, Version 2.0 (the "License");
 *      you may not use this file except in compliance with the License.
 *      You may obtain a copy of the License at
 *
 *          http://www.apache.org/licenses/LICENSE-2.0
 *
 *      Unless required by applicable law or agreed to in writing, software
 *      distributed under the License is distributed on an "AS IS" BASIS,
 *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *      See the License for the specific language governing permissions and
 *      limitations under the License.
 */

package tv.icntv.recommend.algorithm.correlate;

import com.google.common.collect.Sets;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.Iterator;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * User: xiaowu lei
 * Date: 13-12-6
 * Time: ?5:33
 */
public class CorrelateOutPutReducer extends Reducer<Text, Text, Text, Text> {
    @Override
    protected void reduce(Text key, Iterable<Text> values, Context context)
            throws IOException, InterruptedException {
        Set<String> result = Sets.newHashSet();
        for (Iterator<Text> it = values.iterator(); it.hasNext();) {
            result.add(it.next().toString());
        }
        context.write(key, new Text(result.toString()));
    }
}