List of usage examples for org.apache.hadoop.io DoubleWritable DoubleWritable
public DoubleWritable(double value)
From source file:org.archive.giraph.WeightedPageRankVertex.java
License:Apache License
public void compute(Iterable<DoubleWritable> messages) { if (getSuperstep() >= 1) { double sum = 0; for (DoubleWritable message : messages) { sum += message.get();//from ww w . j ava2 s . c o m } // add in the dangling factor sum += this.<DoubleWritable>getAggregatedValue(DANGLING_SUM_AGG).get(); float jump_probability = JUMP_PROBABILITY.get(getConf()); DoubleWritable vertexValue = new DoubleWritable(jump_probability + (1 - jump_probability) * sum); setValue(vertexValue); aggregate(NUMVERTICES_SUM_AGG, new LongWritable(1)); } if (getSuperstep() < MAX_SUPERSTEPS.get(getConf())) { long edges = getNumEdges(); double vertexValue = getValue().get(); //dangling nodes -- transfer score evenly to all nodes if (0 == edges) aggregate(DANGLING_SUM_AGG, new DoubleWritable(vertexValue / getTotalNumVertices())); else { //Pass 1: Sum up all neighbor weights float totalEdgeWeight = 0; for (Edge<Text, FloatWritable> edge : getEdges()) totalEdgeWeight += edge.getValue().get(); //Pass 2: send weighted PR value to each neighbor if (totalEdgeWeight > 0) { for (Edge<Text, FloatWritable> edge : getEdges()) { sendMessage(edge.getTargetVertexId(), new DoubleWritable((vertexValue * edge.getValue().get()) / totalEdgeWeight)); } } } } else { voteToHalt(); } }
From source file:org.archive.hadoop.pig.SequenceFileStorage.java
License:Apache License
/** * Convert the Pig tupleValue to the corresponding Hadoop object. *///from ww w.ja v a 2s.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.data2semantics.giraph.SimpleInDegreeCountComputation.java
License:Apache License
@Override public void compute(Vertex<Text, LongWritable, NullWritable> vertex, Iterable<DoubleWritable> messages) throws IOException { if (getSuperstep() == 0) { Iterable<Edge<Text, NullWritable>> edges = vertex.getEdges(); for (Edge<Text, NullWritable> edge : edges) { sendMessage(edge.getTargetVertexId(), new DoubleWritable(1.0)); }//ww w . j a v a2 s .co m } else { long sum = 0; for (@SuppressWarnings("unused") DoubleWritable message : messages) { sum++; } LongWritable vertexValue = vertex.getValue(); vertexValue.set(sum); vertex.setValue(vertexValue); vertex.voteToHalt(); } }
From source file:org.data2semantics.giraph.SimpleOutDegreeCountComputation.java
License:Apache License
@Override public void compute(Vertex<Text, LongWritable, NullWritable> vertex, Iterable<DoubleWritable> messages) throws IOException { if (getSuperstep() == 0) { LongWritable vertexValue = vertex.getValue(); vertexValue.set(vertex.getNumEdges()); vertex.setValue(vertexValue);// www . j a v a2s . c o m //we want to send a message to our target vertices as well. otherwise, our output only contains the vertices with an outdegree > 0 Iterable<Edge<Text, NullWritable>> edges = vertex.getEdges(); for (Edge<Text, NullWritable> edge : edges) { sendMessage(edge.getTargetVertexId(), new DoubleWritable(1.0)); } } else { if (vertex.getNumEdges() == 0) { LongWritable vertexValue = vertex.getValue(); vertexValue.set(0); vertex.setValue(vertexValue); } else { //if it has a number of outgoing edges, the proper value is already set in the first step } vertex.voteToHalt(); } }
From source file:org.elasticsearch.hadoop.mr.WritableValueReader.java
License:Apache License
@Override protected Object processDouble(Double value) { return new DoubleWritable(value); }
From source file:org.elasticsearch.hadoop.serialization.WritableTypeToJsonTest.java
License:Apache License
@Test public void testDouble() { writableTypeToJson(new DoubleWritable(Double.MAX_VALUE)); }
From source file:org.elasticsearch.hadoop.serialization.WritableValueReaderTest.java
License:Apache License
@Override public void checkDouble(Object typeFromJson) { assertEquals(new DoubleWritable(Double.MAX_VALUE), typeFromJson); }
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 www.j ava 2s.co m*/ 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.types.message.DoubleMessage.java
License:Apache License
/** * Constructor//from ww w.j a va 2 s.com * * @param destinationVertex * - String * @param value * - double */ public DoubleMessage(String destinationVertex, double value) { super(DoubleWritable.class); this.setDestinationVertex(destinationVertex); this.setMessageValue(new DoubleWritable(value)); }
From source file:org.goldenorb.types.message.SampleDoubleMessageTest.java
License:Apache License
/** * Constructor * */ public SampleDoubleMessageTest() { dm0.setMessageValue(new DoubleWritable(MESSAGE_VALUE)); dm0.setDestinationVertex(DESTINATION_VALUE); }