Example usage for org.apache.hadoop.io IntWritable get

List of usage examples for org.apache.hadoop.io IntWritable get

Introduction

In this page you can find the example usage for org.apache.hadoop.io IntWritable get.

Prototype

public int get() 

Source Link

Document

Return the value of this IntWritable.

Usage

From source file:ch.epfl.data.bigdata.markov.CounterReducer.java

@Override
protected void reduce(Text key, Iterable<IntWritable> values, Context context)
        throws IOException, InterruptedException {
    int sum = 0;//from ww w  .ja  va2 s. c o  m
    for (IntWritable val : values) {
        sum += val.get();
    }
    context.write(key, new IntWritable(sum));
}

From source file:ch.ethz.las.wikimining.mr.io.IntegerSequenceFileReader.java

@Override
protected void readContent(FileStatus status) throws IOException {
    try (SequenceFile.Reader reader = new SequenceFile.Reader(fs, status.getPath(), config)) {
        IntWritable key = (IntWritable) ReflectionUtils.newInstance(reader.getKeyClass(), config);
        IntWritable value = (IntWritable) ReflectionUtils.newInstance(reader.getValueClass(), config);
        while (reader.next(key, value)) {
            map.put(key.get(), value.get());
        }/*from  w ww .  j  a v  a2  s  .c  o  m*/
    }
}

From source file:clustering.io.tuple.IntIntTupleWritable.java

License:Apache License

public void set(IntWritable left, IntWritable right) {
    this.left.set(left.get());
    this.right.set(right.get());
}

From source file:clustering.tf_idf.DocCntReducer.java

License:Apache License

@Override
protected void reduce(NullWritable key, Iterable<IntWritable> values, Context context)
        throws IOException, InterruptedException {
    for (IntWritable value : values) {
        this.counter += value.get();
    }/*from   w  ww .  j  av  a  2  s. c  o m*/
    this.outputValue.set(this.counter);
    context.write(NullWritable.get(), this.outputValue);
}

From source file:clustering.tf_idf.TermCountReducer.java

License:Apache License

/**
 * @param key    term@@@group_id::position
 * @param values count/*from  www  .  j  av  a2s  .  co m*/
 *               {@inheritDoc}
 */
@Override
protected void reduce(Text key, Iterable<IntWritable> values, Context context)
        throws IOException, InterruptedException {

    int sum = 0;
    for (IntWritable val : values) {
        sum += val.get();
    }
    this.outputValue.set(sum);
    // term@@@entry_id@@g_no::position \t count
    context.write(key, this.outputValue);
}

From source file:cn.ac.ncic.mastiff.io.coding.ORCStringEcnodingUtil.java

License:Apache License

/**
 * Checks the validity of the entire tree. Also ensures that the number of
 * nodes visited is the same as the size of the set.
 *///ww  w. j  a  v a2  s.c  o  m
public void checkTree(StringRedBlackTree tree) throws IOException {
    IntWritable count = new IntWritable(0);
    if (tree.isRed(tree.root)) {
        printTree(tree, "", tree.root);
        throw new IllegalStateException("root is red");
    }
    checkSubtree(tree, tree.root, count);

    if (count.get() != tree.size) {
        printTree(tree, "", tree.root);
        throw new IllegalStateException("Broken tree! visited= " + count.get() + " size=" + tree.size);
    }
}

From source file:cn.ac.ncic.mastiff.io.coding.ORCStringEcnodingUtil.java

License:Apache License

/**
 * Checks the red-black tree rules to make sure that we have correctly built
 * a valid tree./*  www  .  j ava  2  s . c om*/
 *
 * Properties:
 *   1. Red nodes must have black children
 *   2. Each node must have the same black height on both sides.
 *
 * @param node The id of the root of the subtree to check for the red-black
 *        tree properties.
 * @return The black-height of the subtree.
 */
public int checkSubtree(RedBlackTree tree, int node, IntWritable count) throws IOException {
    if (node == RedBlackTree.NULL) {
        return 1;
    }
    count.set(count.get() + 1);
    boolean is_red = tree.isRed(node);
    int left = tree.getLeft(node);
    int right = tree.getRight(node);
    if (is_red) {
        if (tree.isRed(left)) {
            printTree(tree, "", tree.root);
            throw new IllegalStateException("Left node of " + node + " is " + left + " and both are red.");
        }
        if (tree.isRed(right)) {
            printTree(tree, "", tree.root);
            throw new IllegalStateException("Right node of " + node + " is " + right + " and both are red.");
        }
    }
    int left_depth = checkSubtree(tree, left, count);
    int right_depth = checkSubtree(tree, right, count);
    if (left_depth != right_depth) {
        printTree(tree, "", tree.root);
        throw new IllegalStateException(
                "Lopsided tree at node " + node + " with depths " + left_depth + " and " + right_depth);
    }
    if (is_red) {
        return left_depth;
    } else {
        return left_depth + 1;
    }
}

From source file:cn.com.diditaxi.hive.cf.UDFChr.java

License:Apache License

public Text evaluate(IntWritable ascii_number) {
    if (ascii_number == null) {
        return null;
    }/*  w  w  w .  ja  v  a 2 s .  com*/

    result.set(Character.toString((char) ascii_number.get()));
    return result;
}

From source file:cn.com.diditaxi.hive.cf.UDFStrToDate.java

License:Apache License

public Text evaluate(Text dateText, Text patternText, IntWritable days) {
    if (dateText == null || patternText == null || days == null) {
        return null;
    }//from  w  w  w  . java 2 s. co m

    t = evaluate(dateText, patternText);
    try {
        calendar.setTime(standardFormatter.parse(t.toString()));
        calendar.add(Calendar.DAY_OF_MONTH, days.get());
        Date newDate = calendar.getTime();
        result.set(standardFormatter.format(newDate));
        return result;
    } catch (ParseException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:cn.com.diditaxi.hive.cf.UDFSysDate.java

License:Apache License

public Text evaluate(Text format, IntWritable days) {
    if (format == null) {
        format.set("yyyy-MM-dd HH:mm:ss");
    }/*from ww w . ja va2 s.  c o m*/

    formatter.applyPattern(format.toString());
    Date date = new Date();
    calendar.setTime(date);
    calendar.add(Calendar.DAY_OF_MONTH, days.get());
    Date newDate = calendar.getTime();
    result.set(formatter.format(newDate));
    return result;
}