List of usage examples for org.apache.hadoop.io IntWritable get
public int get()
From source file:com.netease.news.classifier.naivebayes.ThetaMapper.java
License:Apache License
@Override protected void map(IntWritable key, VectorWritable value, Context ctx) throws IOException, InterruptedException { trainer.train(key.get(), value.get()); }
From source file:com.netease.news.classifier.naivebayes.WeightsMapper.java
License:Apache License
@Override protected void map(IntWritable index, VectorWritable value, Context ctx) throws IOException, InterruptedException { Vector instance = value.get(); if (weightsPerFeature == null) { weightsPerFeature = new RandomAccessSparseVector(instance.size(), instance.getNumNondefaultElements()); }/*ww w . j a v a2s . c o m*/ int label = index.get(); weightsPerFeature.assign(instance, Functions.PLUS); weightsPerLabel.set(label, weightsPerLabel.get(label) + instance.zSum()); }
From source file:com.ricemap.spateDB.mapred.GridRecordWriter.java
License:Apache License
@Override public void write(IntWritable key, S value) throws IOException { super.write(key.get(), value); }
From source file:com.skp.experiment.common.mapreduce.ToVectorAndPrefReducer.java
License:Apache License
@Override protected void reduce(IntWritable key, Iterable<VectorOrPrefWritable> values, Context context) throws IOException, InterruptedException { List<Long> userIDs = Lists.newArrayList(); List<Float> prefValues = Lists.newArrayList(); Vector similarityMatrixColumn = null; for (VectorOrPrefWritable value : values) { if (value.getVector() == null) { // Then this is going into list userIDs.add(value.getUserID()); prefValues.add(value.getValue()); } else {/*from w w w .jav a 2 s . c om*/ // Then this is going into vector if (similarityMatrixColumn != null) { throw new IllegalStateException(" " + key.get()); } similarityMatrixColumn = value.getVector(); } } if (similarityMatrixColumn == null) { return; } VectorAndPrefsWritable vectorAndPrefs = new VectorAndPrefsWritable(similarityMatrixColumn, userIDs, prefValues); context.write(key, vectorAndPrefs); }
From source file:com.skp.experiment.common.MathHelper.java
License:Apache License
/** * read a {@link Matrix} from a SequenceFile<IntWritable,VectorWritable> *//* ww w. j a va2 s. c o m*/ public static Matrix readMatrix(Configuration conf, Path path, int rows, int columns) { boolean readOneRow = false; Matrix matrix = new DenseMatrix(rows, columns); for (Pair<IntWritable, VectorWritable> record : new SequenceFileIterable<IntWritable, VectorWritable>(path, true, conf)) { IntWritable key = record.getFirst(); VectorWritable value = record.getSecond(); readOneRow = true; int row = key.get(); Iterator<Vector.Element> elementsIterator = value.get().iterateNonZero(); while (elementsIterator.hasNext()) { Vector.Element element = elementsIterator.next(); matrix.set(row, element.index(), element.get()); } } if (!readOneRow) { throw new IllegalStateException("Not a single row read!"); } return matrix; }
From source file:com.soteradefense.dga.hbse.HBSEComputation.java
License:Apache License
/** * Return the current global state/*from ww w. j a va 2 s . c o m*/ * * @return State that stores the current global state */ private State getCurrentGlobalState() { IntWritable stateInt = this.getAggregatedValue(HBSEMasterCompute.STATE_AGG); return State.values()[stateInt.get()]; }
From source file:com.springdeveloper.hadoop.IntSumReducer.java
License:Apache License
@Override protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException { int sum = 0;// ww w . j av a2s . c o m for (IntWritable value : values) { sum += value.get(); } context.write(key, new IntWritable(sum)); }
From source file:com.sreejith.loganalyzer.mapreduce.LogPartitioner.java
License:Apache License
@Override public int getPartition(IntWritable key, IntWritable value, int numReduceTasks) { logger.info("Partitioner started"); int intKey = key.get(); if (intKey >= 8 && intKey <= 18) { return 1; } else {//w w w.j a v a 2 s .co m return 0; } }
From source file:com.sreejith.loganalyzer.mapreduce.LogReducer.java
License:Apache License
public void reduce(IntWritable key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException { logger.info("Reducer started"); int sum = 0;/*from ww w .j a v a 2s . co m*/ for (IntWritable value : values) { sum = sum + value.get(); } context.write(key, new IntWritable(sum)); logger.info("Reducer completed"); }
From source file:com.sudarmuthu.hadoop.countwords.CountWordsReducer.java
@Override public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException { int sum = 0;//from w w w . j ava 2 s . com for (IntWritable value : values) { sum += value.get(); } context.write(key, new IntWritable(sum)); }