Package com.ontology2.bakemono.pse3

Source Code of com.ontology2.bakemono.pse3.Uniq

package com.ontology2.bakemono.pse3;

import java.io.IOException;

import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.mapreduce.Counter;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.Reducer.Context;

import com.hp.hpl.jena.graph.Triple;
import com.ontology2.bakemono.jena.WritableTriple;

public class Uniq extends Reducer<WritableTriple, LongWritable, Triple, LongWritable> {
    private static org.apache.commons.logging.Log logger = LogFactory.getLog(Uniq.class);
   

    @Override
    protected void reduce(WritableTriple key, Iterable<LongWritable> value,
            Context context)
            throws IOException, InterruptedException {
        context.write(key.getTriple(), new LongWritable(1));
        incrementCounter(context,UniqCounters.DISTINCT_KEYS,1);
        for(LongWritable v:value) {
            incrementCounter(context,UniqCounters.TOTAL_VALUES,1);
        };
    }
  
    //
    // this code prevents failing test because the mock object Context we are passing back
    // always returns null from getCounter...  With a more sophisticated mock object perhaps
    // the system will produce individual mocks for each counter so we can watch what
    // happens with counters
    //
   
    private void incrementCounter(Context context,Enum <?> counterId,long amount) {
        Counter counter=context.getCounter(counterId);
        if(counter!=null) {
            counter.increment(amount);
        };
    };

}
TOP

Related Classes of com.ontology2.bakemono.pse3.Uniq

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.