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:com.cloudera.crunch.type.writable.WritablesTest.java

License:Open Source License

@Test
public void testFloats() throws Exception {
    float j = 55.5f;
    FloatWritable w = new FloatWritable(j);
    testInputOutputFn(Writables.floats(), j, w);
}

From source file:com.cloudera.impala.hive.executor.TestUdf.java

License:Apache License

public FloatWritable evaluate(FloatWritable a) {
    if (a == null)
        return null;
    return new FloatWritable(a.get());
}

From source file:com.dasasian.chok.lucene.FieldSortComparatorTest.java

License:Apache License

@Test
public void testStringFieldScoreCompare() {
    SortField[] sortFields = new SortField[] { new SortField("stringField", SortField.STRING),
            new SortField("scoreField", SortField.SCORE) };
    WritableType[] sortFieldTypes = new WritableType[] { WritableType.TEXT, WritableType.FLOAT };
    FieldSortComparator fieldSortComparator = new FieldSortComparator(sortFields, sortFieldTypes);

    Hit hit1 = new Hit("shard", "node", 0.5f, 1, sortFieldTypes);
    Hit hit2 = new Hit("shard", "node", 0.2f, 2, sortFieldTypes);

    hit1.setSortFields(new WritableComparable[] { new Text("a"), new FloatWritable(hit1.getScore()) });
    hit2.setSortFields(new WritableComparable[] { new Text("a"), new FloatWritable(hit2.getScore()) });

    assertEquals(0, fieldSortComparator.compare(hit1, hit1));
    assertEquals(1, fieldSortComparator.compare(hit2, hit1));
    assertEquals(-1, fieldSortComparator.compare(hit1, hit2));
}

From source file:com.dasasian.chok.util.WritableType.java

License:Apache License

/**
 * Convert a java primitive type wrapper (like String, Integer, Float, etc...)
 * to the corresponding hadoop {@link WritableComparable}.
 * @param object the object to convert/*ww w .  jav  a2 s.co  m*/
 * @return the writable comparable
 */
public WritableComparable convertComparable(Object object) {
    switch (this) {
    case TEXT:
        return new Text((String) object);
    case BYTE:
        return new ByteWritable((Byte) object);
    case INT:
        return new IntWritable((Integer) object);
    case LONG:
        return new LongWritable(((Long) object));
    case FLOAT:
        return new FloatWritable((Float) object);
    case DOUBLE:
        return new DoubleWritable((Double) object);
    }
    throw getUnhandledTypeException();
}

From source file:com.datasalt.pangool.utils.test.AbstractHadoopTestLibrary.java

License:Apache License

public Writable writable(Object obj) {
    if (obj instanceof Integer) {
        return new IntWritable((Integer) obj);
    } else if (obj instanceof Double) {
        return new DoubleWritable((Double) obj);
    } else if (obj instanceof Long) {
        return new LongWritable((Long) obj);
    } else if (obj instanceof String) {
        return new Text((String) obj);
    } else if (obj instanceof Float) {
        return new FloatWritable((Float) obj);
    } else if (obj instanceof Boolean) {
        return new BooleanWritable((Boolean) obj);
    }// w  w w  . j av a2s  .  c o m
    return null;
}

From source file:com.ebay.nest.io.sede.lazy.LazyFloat.java

License:Apache License

public LazyFloat(LazyFloat copy) {
    super(copy);
    data = new FloatWritable(copy.data.get());
}

From source file:com.ebay.nest.io.sede.lazybinary.LazyBinaryFloat.java

License:Apache License

LazyBinaryFloat(LazyBinaryFloat copy) {
    super(copy);
    data = new FloatWritable(copy.data.get());
}

From source file:com.ebay.nest.io.sede.objectinspector.primitive.JavaFloatObjectInspector.java

License:Apache License

@Override
public Object getPrimitiveWritableObject(Object o) {
    return o == null ? null : new FloatWritable(((Float) o).floatValue());
}

From source file:com.ebay.nest.io.sede.objectinspector.primitive.WritableFloatObjectInspector.java

License:Apache License

@Override
public Object copyObject(Object o) {
    return o == null ? null : new FloatWritable(((FloatWritable) o).get());
}

From source file:com.ebay.nest.io.sede.objectinspector.primitive.WritableFloatObjectInspector.java

License:Apache License

@Override
public Object create(float value) {
    return new FloatWritable(value);
}