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

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

Introduction

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

Prototype

public long get() 

Source Link

Document

Return the value of this LongWritable.

Usage

From source file:nl.gridline.zieook.inx.dc.DCMap.java

License:Apache License

@Override
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
    // process the input:
    String object = value.toString();
    long keyLng = key.get();

    if (object.isEmpty() || object.trim().isEmpty()) {
        LOG.error("the key " + keyLng + " has no data");
        return;/*from  w ww  .  j a  v a2 s .  co  m*/
    } else {
        CollectionItem item = null;
        try {
            item = DCRecordParseXML.getRecordFromXmlString(object);
        } catch (ParserConfigurationException e) {
            LOG.error("failed to parse key" + keyLng, e);
        } catch (SAXException e) {
            LOG.error("failed to parse key" + keyLng, e);
        } catch (ParseException e) {
            LOG.error("failed to parse key" + keyLng, e);
        }

        if (item != null) {
            item.setCp(cp);

            // create a HBase PUT object:
            Put put = HBasePUTFactory.getCollectionItemCompl(collection, item.getId(), object, item);

            // reuse the key:

            // write the result:
            context.write(key, put);
        }
    }

    context.progress();
}

From source file:nl.gridline.zieook.inx.movielens.categories.CategoriesExtractReduce.java

License:Apache License

protected void reduce(Text key, Iterable<LongWritable> values, Context context)
        throws IOException, InterruptedException {
    long cnt = 0;
    for (LongWritable w : values) {
        cnt += w.get();
    }//  www .jav a2 s . c o m
    context.write(key, new LongWritable(cnt));
}

From source file:nl.gridline.zieook.inx.movielens.categories.CategoriesImportMap.java

License:Apache License

@Override
protected void map(Text key, LongWritable value, Context context) throws IOException, InterruptedException {
    String category = key.toString();
    Put put = new Put(RowKeys.getCategoriesKey(collection, category));
    put.add(COLUMN, NAME, Bytes.toBytes(category));
    put.add(COLUMN, COUNT, Bytes.toBytes(value.get()));
    // add category & count (count
    context.write(key, put);/* ww w . j  av  a2s  .com*/
    context.progress();
}

From source file:nl.gridline.zieook.statistics.popularity.PopularityCountReduce.java

License:Apache License

@Override
protected void reduce(LongWritable keyIn, Iterable<LongWritable> values, Context context)
        throws IOException, InterruptedException {
    long count = 0;
    for (LongWritable value : values) {
        count += value.get();
    }//from  www .  jav a  2 s . com
    outValue.set(count);
    // LOG.info("counting for date: " + keyIn.get() + " " + count);
    context.write(keyIn, outValue);
}

From source file:nl.gridline.zieook.statistics.popularity.PopularityReduce.java

License:Apache License

@Override
protected void reduce(ItemTime key, java.lang.Iterable<LongWritable> values, Context context)
        throws IOException, InterruptedException {
    long count = 0;
    for (LongWritable i : values) {
        count += i.get();
    }/*from  w  w  w  .  ja v  a  2 s  . c o m*/
    // LOG.info("writing: " + key.getCollection() + "/" + key.getItem() + " date: " + key.getTime() + " count: " +
    // count);
    valueOut.set(count);
    context.write(key, valueOut);
}

From source file:nl.gridline.zieook.statistics.popularity.PopularityScoreMap.java

License:Apache License

@Override
protected void map(ItemTime key, LongWritable value, Context context) throws IOException, InterruptedException {
    Long total = types.get(key.getTime());
    long count = value.get();
    if (total == null) {
        throw new IOException("no total for the given time-unit: '" + key.getTime() + "'");
    }//w  ww. j a va  2  s . c o m
    // LOG.info("writing popularity: total,percentage: " + total + " " + ((count / (double) total) * 100));
    context.write(key, popularity.set(count, (count / (double) total) * 100));
}

From source file:nl.gridline.zieook.statistics.RatingsPerCollectionItemReduce.java

License:Apache License

@Override
protected void reduce(LongWritable key, Iterable<LongWritable> values, Context context)
        throws IOException, InterruptedException {
    long item = key.get();
    long count = 0;
    for (LongWritable v : values) {
        count += v.get();//from w  w w. j  a  va2s.c  o m
    }
    Put put = HBasePUTFactory.putStatisticsItemRatings(collection, item, date, count);
    LOG.debug("reduce  <[" + item + "," + date + "]," + count + ">");
    context.write(key, put);
}

From source file:nl.gridline.zieook.statistics.RatingsPerCPUserReduce.java

License:Apache License

@Override
protected void reduce(LongWritable key, java.lang.Iterable<LongWritable> values, Context context)
        throws IOException, InterruptedException {
    long user = key.get();
    long count = 0;
    for (LongWritable v : values) {
        count += v.get();//from   w ww . jav  a  2s .co  m
    }
    Put put = HBasePUTFactory.putStatisticsRatingsUser(collection, user, date, count);
    LOG.debug("reduce  <[" + user + "," + date + "]," + count + ">");
    context.write(key, put);
}

From source file:nl.gridline.zieook.statistics.RecommendedItemToUserReduce.java

License:Apache License

@Override
protected void reduce(UserCollectionItem key, Iterable<LongWritable> values, Context context)
        throws IOException, InterruptedException {
    long count = 0;
    for (LongWritable c : values) {
        count += c.get();
    }// w ww  .jav a 2s .  co m

    final long user = key.getUser();
    final long item = key.getItem();
    final String collection = key.getCollection();
    LOG.debug("reduce: <[" + collection + "," + user + "," + item + "," + date + "]," + count + ">");
    final Put put = HBasePUTFactory.putRecommendedUser(collection, user, item, count, date);

    context.write(key, put);
}

From source file:nl.gridline.zieook.statistics.RecommendedToUserReduce.java

License:Apache License

@Override
protected void reduce(UserCollection key, Iterable<LongWritable> values, Context context)
        throws IOException, InterruptedException {
    long count = 0;
    for (LongWritable c : values) {
        count += c.get();
    }/*from ww w.  java 2 s. c  om*/

    final long user = key.getUser();
    final String collection = key.getCollection();
    LOG.debug("reduce: <[" + collection + "," + user + "," + date + "]," + count + ">");
    final Put put = HBasePUTFactory.putRecommendedCollectionUser(collection, user, count, date);

    context.write(key, put);
}