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:org.huahinframework.core.io.RecordTest.java

License:Apache License

@Test
public void testGroupingFloatWritable() {
    Record record = new Record();
    FloatWritable o = new FloatWritable(10.0F);
    record.addGrouping("Object", o);
    assertEquals(record.getGroupingFloatWritable("Object"), o);
    assertEquals(record.getGroupingFloatWritable("Object2"), null);

    try {// www . j a v  a2  s.  c o  m
        record.getGroupingInteger("Object");
        fail("fail ClassCastException");
    } catch (Exception e) {
        assertTrue(e instanceof ClassCastException);
    }
}

From source file:org.huahinframework.core.io.RecordTest.java

License:Apache License

@Test
public void testValueFloatWritable() {
    Record record = new Record();
    FloatWritable o = new FloatWritable(10.0F);
    record.addValue("Object", o);
    assertEquals(record.getValueFloatWritable("Object"), o);
    assertEquals(record.getValueFloatWritable("Object2"), null);

    try {// w  ww  . ja  v  a  2  s  .c  o m
        record.getValueIntWritable("Object");
        fail("fail ClassCastException");
    } catch (Exception e) {
        assertTrue(e instanceof ClassCastException);
    }
}

From source file:org.huahinframework.core.util.ObjectUtil.java

License:Apache License

/**
 * Convert the HadoopObject from Java primitive.
 * @param object Java primitive object/* ww  w  . j  a v  a 2  s  .c om*/
 * @return HadoopObject
 */
public static HadoopObject primitive2Hadoop(Object object) {
    if (object == null) {
        return new HadoopObject(NULL, NullWritable.get());
    }

    if (object instanceof Byte) {
        return new HadoopObject(BYTE, new ByteWritable((Byte) object));
    } else if (object instanceof Integer) {
        return new HadoopObject(INTEGER, new IntWritable((Integer) object));
    } else if (object instanceof Long) {
        return new HadoopObject(LONG, new LongWritable((Long) object));
    } else if (object instanceof Double) {
        return new HadoopObject(DOUBLE, new DoubleWritable((Double) object));
    } else if (object instanceof Float) {
        return new HadoopObject(FLOAT, new FloatWritable((Float) object));
    } else if (object instanceof Boolean) {
        return new HadoopObject(BOOLEAN, new BooleanWritable((Boolean) object));
    } else if (object instanceof String) {
        return new HadoopObject(STRING, new Text((String) object));
    } else if (object.getClass().isArray()) {
        return arrayPrimitive2Hadoop(object);
    } else if (object instanceof Collection<?>) {
        Collection<?> collection = (Collection<?>) object;
        return arrayPrimitive2Hadoop(collection.toArray());
    } else if (object instanceof Map<?, ?>) {
        Map<?, ?> map = (Map<?, ?>) object;
        if (map.size() == 0) {
            throw new ClassCastException("object not found");
        }

        MapWritable mapWritable = new MapWritable();
        for (Entry<?, ?> entry : map.entrySet()) {
            mapWritable.put(primitive2Hadoop(entry.getKey()).getObject(),
                    primitive2Hadoop(entry.getValue()).getObject());
        }

        return new HadoopObject(MAP, mapWritable);
    }

    throw new ClassCastException("cast object not found");
}

From source file:org.huahinframework.core.util.ObjectUtilTest.java

License:Apache License

@Test
public void testPrimitive2HadoopIOFloat() {
    float o = 123;
    HadoopObject ho = ObjectUtil.primitive2Hadoop(o);
    assertEquals(ObjectUtil.FLOAT, ho.getType());
    assertEquals(new FloatWritable(o), ho.getObject());
}

From source file:org.huahinframework.core.util.ObjectUtilTest.java

License:Apache License

@Test
public void testHadoopIO2PrimitiveFloat() {
    float o = 123;
    PrimitiveObject no = ObjectUtil.hadoop2Primitive(new FloatWritable(o));
    assertEquals(ObjectUtil.FLOAT, no.getType());
    assertEquals(o, no.getObject());//from  www  .j ava 2s .co m
}

From source file:org.openflamingo.mapreduce.aggregator.FloatMaxAggregator.java

License:Apache License

@Override
public FloatWritable getAggregatedValue() {
    return new FloatWritable(max);
}

From source file:org.openflamingo.mapreduce.aggregator.FloatMinAggregator.java

License:Apache License

@Override
public FloatWritable getAggregatedValue() {
    return new FloatWritable(min);
}

From source file:org.openflamingo.mapreduce.aggregator.FloatOverwriteAggregator.java

License:Apache License

@Override
public FloatWritable getAggregatedValue() {
    return new FloatWritable(result);
}

From source file:org.openflamingo.mapreduce.aggregator.FloatProductAggregator.java

License:Apache License

@Override
public FloatWritable getAggregatedValue() {
    return new FloatWritable(product);
}

From source file:org.openflamingo.mapreduce.aggregator.FloatSumAggregator.java

License:Apache License

@Override
public FloatWritable getAggregatedValue() {
    return new FloatWritable(sum);
}