Example usage for org.apache.hadoop.io FloatWritable FloatWritable

List of usage examples for org.apache.hadoop.io FloatWritable FloatWritable

Introduction

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

Prototype

public FloatWritable(float value) 

Source Link

Usage

From source file:Assignment2_P2_StockExchangeCount.StockPrice_Mapper.java

public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
    //System.out.println("Content on line " + key.toString() + " :- " + value.toString() );

    String[] stockInfo = value.toString().split(",");
    //System.out.println("String is split now ");

    if (!stockInfo[1].trim().equals("stock_symbol")) {
        Text stockName = new Text(stockInfo[1]);
        //System.out.println("Stockname extracted " + stockName.toString());

        FloatWritable highestPrice = new FloatWritable(Float.parseFloat(stockInfo[4]));
        //System.out.println("So is the price " + highestPrice);

        context.write(stockName, highestPrice);
    }//from  w w w. ja  v  a2  s  . c  o m
}

From source file:Assignment3_P5_Top25Movies.Top25MovieRating_Mapper.java

public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
    String[] movieInfo = value.toString().split("::");

    if (!movieInfo[1].trim().toLowerCase().equals("movieid")) {
        movieID = new IntWritable(Integer.parseInt(movieInfo[1]));
        rating = new FloatWritable(Float.parseFloat(movieInfo[2]));
        //System.out.println("MovieId extracted " + movieID.toString());

        context.write(movieID, rating);/*  w  w w. j a  v a  2s .  co m*/
    }
}

From source file:Assignment3_P5_Top25Movies.Top25MovieRating_Mapper1.java

public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
    String[] movieInfo = value.toString().split("\t");

    movieID = new IntWritable(Integer.parseInt(movieInfo[0]));
    rating = new FloatWritable(Float.parseFloat(movieInfo[1]));

    context.write(rating, movieID);/*  w w  w.j  ava 2s  . c  o m*/
}

From source file:Assignment4_P3_InMemoryStdDeviation.MovieRatingStdDev_Mapper.java

public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
    String[] movieInfo = value.toString().split("::");

    if (!movieInfo[1].trim().toLowerCase().equals("movieid")) {
        movieID = new IntWritable(Integer.parseInt(movieInfo[1]));
        rating = new FloatWritable(Float.parseFloat(movieInfo[2]));

        context.write(movieID, rating);/*from w w w . j a  v  a 2 s  . c  o  m*/
    }
}

From source file:Assignment4_P4_MemoryConscious.MovieRatingMemConscious_Mapper.java

public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
    String[] movieInfo = value.toString().split("::");

    if (!movieInfo[1].trim().toLowerCase().equals("movieid")) {
        // extract movieID and rating
        movieID = new IntWritable(Integer.parseInt(movieInfo[1]));
        rating = new FloatWritable(Float.parseFloat(movieInfo[2]));

        // push rating in sorted hashmap
        outSortMap.put(rating, ONE);//from   w w w.  j  a  va2 s .c om

        // send this fellow to combiner now, come on, do it bleeeeeedy
        context.write(movieID, outSortMap);
    }
}

From source file:BU.MET.CS755.SpeciesViewerMapper.java

public void map(WritableComparable key, Writable value, OutputCollector output, Reporter reporter)
        throws IOException {
    // get the current page
    String data = ((Text) value).toString();
    int index = data.indexOf(":");

    // Can happen if no outlinks
    if (index == -1) {
        index = data.length();//from   www.j  a  v a2 s .  c  om
    }

    // split into title and PR (tab or variable number of blank spaces)
    String toParse = data.substring(0, index).trim();
    String[] splits = toParse.split("\t");

    if (splits.length == 0) {
        splits = toParse.split(" ");

        if (splits.length == 0) {
            return;
        }
    }

    String pagetitle = splits[0].trim();
    String pagerank = splits[splits.length - 1].trim();

    // parse score
    double currScore = 0.0;
    try {
        currScore = Double.parseDouble(pagerank);
    } catch (Exception e) {
        currScore = 0.0;
    }

    // collect
    //output.collect(new FloatWritable((float) - currScore), key);
    output.collect(new FloatWritable((float) -currScore * 1000), new Text(pagetitle));
}

From source file:cascading.hive.ORCFile.java

License:Apache License

private void tuple2Struct(Tuple tuple, OrcStruct struct) {
    Object value = null;//  w ww .  ja  v  a 2 s  .  c  om
    for (int i = 0; i < types.length; i++) {
        switch (typeMapping.get(types[i].toLowerCase())) {
        case INT:
            value = tuple.getObject(i) == null ? null : new IntWritable(tuple.getInteger(i));
            break;
        case BOOLEAN:
            value = tuple.getObject(i) == null ? null : new BooleanWritable(tuple.getBoolean(i));
            break;
        case TINYINT:
            value = tuple.getObject(i) == null ? null : new ByteWritable(Byte.valueOf(tuple.getString(i)));
            break;
        case SMALLINT:
            value = tuple.getObject(i) == null ? null : new ShortWritable(tuple.getShort(i));
            break;
        case BIGINT:
            value = tuple.getObject(i) == null ? null : new LongWritable(tuple.getLong(i));
            break;
        case FLOAT:
            value = tuple.getObject(i) == null ? null : new FloatWritable(tuple.getFloat(i));
            break;
        case DOUBLE:
            value = tuple.getObject(i) == null ? null : new DoubleWritable(tuple.getDouble(i));
            break;
        case BIGDECIMAL:
            value = tuple.getObject(i) == null ? null
                    : new HiveDecimalWritable(HiveDecimal.create((new BigDecimal(tuple.getString(i)))));
            break;
        case STRING:
        default:
            value = tuple.getObject(i) == null ? null : new Text(tuple.getString(i));
        }
        struct.setFieldValue(i, value);
    }
}

From source file:co.nubetech.hiho.dedup.TestHashUtility.java

License:Apache License

@Test
public void testMD5HashForFloatWritableKey() throws IOException {
    FloatWritable key = new FloatWritable(1.025f);
    MD5Hash md5HashKey1 = HashUtility.getMD5Hash(key);
    MD5Hash md5HashKey2 = HashUtility.getMD5Hash(key);
    assertEquals(md5HashKey1, md5HashKey2);
}

From source file:com.asakusafw.directio.hive.serde.FloatOptionInspector.java

License:Apache License

@Override
public Object getPrimitiveWritableObject(Object o) {
    FloatOption object = (FloatOption) o;
    if (object == null || object.isNull()) {
        return null;
    }/*from  ww  w  .j  av  a2 s.  c  om*/
    return new FloatWritable(object.get());
}

From source file:com.axiomine.largecollections.kryo.serializers.FloatWritableSerializer.java

License:Apache License

public FloatWritable read(Kryo kryo, Input input, Class<FloatWritable> type) {
    return new FloatWritable(input.readFloat());
}