List of usage examples for org.apache.hadoop.io FloatWritable FloatWritable
public FloatWritable(float value)
From source file:org.archive.bacon.io.SequenceFileStorage.java
License:Apache License
/** * Convert the Pig tupleValue to the corresponding Hadoop object. *///ww w. j a v a 2s. c om public Writable getWritable(Object tupleValue, Writable nullWritable) throws IOException { switch (DataType.findType(tupleValue)) { case DataType.BOOLEAN: return new BooleanWritable((boolean) tupleValue); case DataType.BYTE: return new ByteWritable((byte) tupleValue); case DataType.CHARARRAY: return new Text((String) tupleValue); case DataType.INTEGER: return new IntWritable((int) tupleValue); case DataType.LONG: return new LongWritable((long) tupleValue); case DataType.DOUBLE: return new DoubleWritable((double) tupleValue); case DataType.FLOAT: return new FloatWritable((float) tupleValue); case DataType.BYTEARRAY: return new BytesWritable((byte[]) tupleValue); // If we get a 'null' from Pig, just pass through the // already-instantiated Hadoop nullWritable. case DataType.NULL: return nullWritable; // Don't know what to do with these complex data types. case DataType.BAG: case DataType.ERROR: case DataType.MAP: case DataType.TUPLE: case DataType.UNKNOWN: default: throw new IOException("Cannot write values of type: " + DataType.findTypeName(tupleValue)); } }
From source file:org.archive.hadoop.pig.SequenceFileStorage.java
License:Apache License
/** * Convert the Pig tupleValue to the corresponding Hadoop object. *//*from w w w. java2 s.c o m*/ public Writable getWritable(Object tupleValue, Writable nullWritable) throws IOException { switch (DataType.findType(tupleValue)) { case DataType.BOOLEAN: return new BooleanWritable((Boolean) tupleValue); case DataType.BYTE: return new ByteWritable((Byte) tupleValue); case DataType.CHARARRAY: return new Text((String) tupleValue); case DataType.INTEGER: return new IntWritable((Integer) tupleValue); case DataType.LONG: return new LongWritable((Long) tupleValue); case DataType.DOUBLE: return new DoubleWritable((Double) tupleValue); case DataType.FLOAT: return new FloatWritable((Float) tupleValue); case DataType.BYTEARRAY: return new BytesWritable((byte[]) tupleValue); // If we get a 'null' from Pig, just pass through the // already-instantiated Hadoop nullWritable. case DataType.NULL: return nullWritable; // Don't know what to do with these complex data types. case DataType.BAG: case DataType.ERROR: case DataType.MAP: case DataType.TUPLE: case DataType.UNKNOWN: default: throw new IOException("Cannot write values of type: " + DataType.findTypeName(tupleValue)); } }
From source file:org.elasticsearch.hadoop.mr.WritableValueReader.java
License:Apache License
@Override protected Object processFloat(Float value) { return new FloatWritable(value); }
From source file:org.elasticsearch.hadoop.serialization.HiveTypeToJsonTest.java
License:Apache License
@Test public void testFloat() { assertEquals("3.4028235E38", hiveTypeToJson(new MyHiveType(new FloatWritable(Float.MAX_VALUE), floatTypeInfo))); }
From source file:org.elasticsearch.hadoop.serialization.WritableTypeToJsonTest.java
License:Apache License
@Test public void testFloat() { writableTypeToJson(new FloatWritable(Float.MAX_VALUE)); }
From source file:org.elasticsearch.hadoop.util.WritableUtils.java
License:Apache License
@SuppressWarnings({ "unchecked", "rawtypes" }) public static Writable toWritable(Object object) { if (object instanceof Writable) { return (Writable) object; }//from ww w . j av a2 s . com if (object == null) { return NullWritable.get(); } if (object instanceof String) { return new Text((String) object); } if (object instanceof Long) { return new VLongWritable((Long) object); } if (object instanceof Integer) { return new VIntWritable((Integer) object); } if (object instanceof Byte) { return new ByteWritable((Byte) object); } if (object instanceof Short) { return WritableCompatUtil.availableShortWritable((Short) object); } if (object instanceof Double) { return new DoubleWritable((Double) object); } if (object instanceof Float) { return new FloatWritable((Float) object); } if (object instanceof Boolean) { return new BooleanWritable((Boolean) object); } if (object instanceof byte[]) { return new BytesWritable((byte[]) object); } if (object instanceof List) { List<Object> list = (List<Object>) object; if (!list.isEmpty()) { Object first = list.get(0); Writable[] content = new Writable[list.size()]; for (int i = 0; i < content.length; i++) { content[i] = toWritable(list.get(i)); } return new ArrayWritable(toWritable(first).getClass(), content); } return new ArrayWritable(NullWritable.class, new Writable[0]); } if (object instanceof SortedSet) { SortedMapWritable smap = new SortedMapWritable(); SortedSet<Object> set = (SortedSet) object; for (Object obj : set) { smap.put((WritableComparable) toWritable(obj), NullWritable.get()); } return smap; } if (object instanceof Set) { MapWritable map = new MapWritable(); Set<Object> set = (Set) object; for (Object obj : set) { map.put(toWritable(obj), NullWritable.get()); } return map; } if (object instanceof SortedMap) { SortedMapWritable smap = new SortedMapWritable(); Map<Object, Object> map = (Map) object; for (Map.Entry<?, ?> entry : map.entrySet()) { smap.put((WritableComparable) toWritable(entry.getKey()), toWritable(entry.getValue())); } return smap; } if (object instanceof Map) { MapWritable result = new MapWritable(); Map<Object, Object> map = (Map) object; for (Map.Entry<?, ?> entry : map.entrySet()) { result.put(toWritable(entry.getKey()), toWritable(entry.getValue())); } return result; } // fall-back to bytearray return new BytesWritable(object.toString().getBytes(StringUtils.UTF_8)); }
From source file:org.goldenorb.io.checkpoint.CheckPointDataTest.java
License:Apache License
/** * Tests the CheckPointDataOutput class by writing several different types of Writables to the checkpoint. * //w ww .java 2s .c o m * @throws Exception */ @Test public void testCheckpointOutput() throws Exception { int superStep = 0; int partition = 0; OrbConfiguration orbConf = new OrbConfiguration(); orbConf.set("fs.default.name", "hdfs://localhost:" + cluster.getNameNodePort()); orbConf.setJobNumber("0"); orbConf.setFileOutputPath("test"); CheckPointDataOutput checkpointOutput = new CheckPointDataOutput(orbConf, superStep, partition); IntWritable intOutput = new IntWritable(4); intOutput.write(checkpointOutput); LongWritable longOutput = new LongWritable(9223372036854775807L); longOutput.write(checkpointOutput); Text textOutput = new Text("test"); textOutput.write(checkpointOutput); FloatWritable floatOutput = new FloatWritable(3.14159F); floatOutput.write(checkpointOutput); checkpointOutput.close(); assertThat(checkpointOutput, notNullValue()); }
From source file:org.goldenorb.types.message.FloatMessage.java
License:Apache License
/** * Constructor//from w w w . ja va 2 s . c om * * @param destinationVertex * - String * @param value * - float */ public FloatMessage(String destinationVertex, float value) { super(FloatWritable.class); this.setDestinationVertex(destinationVertex); this.setMessageValue(new FloatWritable(value)); }
From source file:org.goldenorb.types.message.SampleFloatMessageTest.java
License:Apache License
/** * Constructor * */ public SampleFloatMessageTest() { fm0.setMessageValue(new FloatWritable(MESSAGE_VALUE)); fm0.setDestinationVertex(DESTINATION_VALUE); }
From source file:org.goldenorb.types.message.SampleFloatMessageTest.java
License:Apache License
@Test public void testRPC() { FloatMessage fm1 = client.sendAndReceiveMessage(fm0, DESTINATION_VALUE, new FloatWritable(MESSAGE_VALUE)); assertTrue(fm0.get() == client.getMessage().get()); assertEquals(fm0.getDestinationVertex(), client.getMessage().getDestinationVertex()); assertEquals(fm1.getDestinationVertex(), DESTINATION_VALUE); assertTrue(((FloatWritable) fm1.getMessageValue()).get() == MESSAGE_VALUE); }