List of usage examples for org.apache.hadoop.io LongWritable LongWritable
public LongWritable(long value)
From source file:graphvis.test.FruchtermanReingoldGraphVisTest.java
License:MIT License
/** * Test the messages after finishes superstep3 *//*w ww. j a v a 2 s. co m*/ @Test public void testSuperstep3() throws Exception { //messages: positions of other vertices ArrayList<MessageWritable> messages = new ArrayList<MessageWritable>(); messages.add(new MessageWritable(new LongWritable(2L), new VectorWritable(10, 20))); messages.add(new MessageWritable(new LongWritable(3L), new VectorWritable(10, 20))); Vertex<LongWritable, VertexValueWritable, EdgeValueWritable> vertex = new DefaultVertex<LongWritable, VertexValueWritable, EdgeValueWritable>(); FruchtermanReingoldGraphVis computation = new FruchtermanReingoldGraphVis(); computation.setAggregator(mockAggregator); MockUtils.MockedEnvironment<LongWritable, VertexValueWritable, EdgeValueWritable, MessageWritable> env = MockUtils .prepareVertexAndComputation(vertex, new LongWritable(1L), new VertexValueWritable(), false, computation, 3L); //Mockito.when(SOURCE_ID.get(env.getConfiguration())).thenReturn(2L); vertex.setValue(new VertexValueWritable(new VectorWritable(10, 20), new VectorWritable(0, 0))); vertex.addEdge(EdgeFactory.create(new LongWritable(2L), new EdgeValueWritable())); vertex.addEdge(EdgeFactory.create(new LongWritable(3L), new EdgeValueWritable())); computation.compute(vertex, messages); //assertTrue(vertex.isHalted()); env.verifyMessageSent(new LongWritable(2L), new MessageWritable(new LongWritable(1L), new VectorWritable())); env.verifyMessageSent(new LongWritable(3L), new MessageWritable(new LongWritable(1L), new VectorWritable())); }
From source file:graphvis.test.FruchtermanReingoldGraphVisTest.java
License:MIT License
/** * Test the messages after finishes superstep4 *///from ww w .j ava 2s .c o m @Test public void testSuperstep4() throws Exception { //messages: positions of other vertices ArrayList<MessageWritable> messages = new ArrayList<MessageWritable>(); messages.add(new MessageWritable(new LongWritable(2), new VectorWritable(545, 234))); messages.add(new MessageWritable(new LongWritable(3), new VectorWritable(242, 677))); Vertex<LongWritable, VertexValueWritable, EdgeValueWritable> vertex = new DefaultVertex<LongWritable, VertexValueWritable, EdgeValueWritable>(); FruchtermanReingoldGraphVis computation = new FruchtermanReingoldGraphVis(); MockUtils.MockedEnvironment<LongWritable, VertexValueWritable, EdgeValueWritable, MessageWritable> env = MockUtils .prepareVertexAndComputation(vertex, new LongWritable(1L), new VertexValueWritable(), false, computation, 4L); vertex.setValue(new VertexValueWritable(new VectorWritable(10, 20), new VectorWritable(0, 0))); vertex.addEdge(EdgeFactory.create(new LongWritable(2L), new EdgeValueWritable())); vertex.addEdge(EdgeFactory.create(new LongWritable(3L), new EdgeValueWritable())); computation.compute(vertex, messages); assertTrue(vertex.isHalted()); env.verifyMessageSent(new LongWritable(2), new MessageWritable(new LongWritable(1L), new VectorWritable(10, 20))); env.verifyMessageSent(new LongWritable(3), new MessageWritable(new LongWritable(1L), new VectorWritable(10, 20))); }
From source file:graphvis.test.FruchtermanReingoldGraphVisTest.java
License:MIT License
/** * Test superstep5//from w w w.j a v a2 s . co m */ @Test public void testSuperstep5() throws Exception { //messages: positions of other vertices ArrayList<MessageWritable> messages = new ArrayList<MessageWritable>(); messages.add(new MessageWritable(new LongWritable(2L), new VectorWritable(545, 234))); messages.add(new MessageWritable(new LongWritable(3L), new VectorWritable(242, 677))); Vertex<LongWritable, VertexValueWritable, EdgeValueWritable> vertex = new DefaultVertex<LongWritable, VertexValueWritable, EdgeValueWritable>(); FruchtermanReingoldGraphVis computation = new FruchtermanReingoldGraphVis(); MockUtils.prepareVertexAndComputation(vertex, new LongWritable(1L), new VertexValueWritable(), false, computation, 5L); vertex.setValue(new VertexValueWritable(new VectorWritable(10, 20), new VectorWritable(0, 0))); vertex.addEdge(EdgeFactory.create(new LongWritable(2L), new EdgeValueWritable())); vertex.addEdge(EdgeFactory.create(new LongWritable(3L), new EdgeValueWritable())); computation.compute(vertex, messages); assertTrue(vertex.isHalted()); assertEquals(new VectorWritable(545, 234), vertex.getEdgeValue(new LongWritable(2L)).getTargetPos()); assertEquals(new VectorWritable(242, 677), vertex.getEdgeValue(new LongWritable(3L)).getTargetPos()); }
From source file:graphvis.test.FruchtermanReingoldGraphVisTest.java
License:MIT License
/** * Test superstep6//from w ww . j av a2s . co m */ @Test public void testSuperstep6() throws Exception { Vertex<LongWritable, VertexValueWritable, EdgeValueWritable> vertex = new DefaultVertex<LongWritable, VertexValueWritable, EdgeValueWritable>(); FruchtermanReingoldGraphVis computation = mock(FruchtermanReingoldGraphVis.class); when(computation.getAggregatedValue("T")).thenReturn(new DoubleWritable(1000)); when(computation.getAggregatedValue("k")).thenReturn(new DoubleWritable(4000000)); //double tBefore = computation.getT(); MockUtils.prepareVertexAndComputation(vertex, new LongWritable(1L), new VertexValueWritable(), false, computation, 6L); vertex.setValue(new VertexValueWritable()); vertex.addEdge(EdgeFactory.create(new LongWritable(2), new EdgeValueWritable())); vertex.addEdge(EdgeFactory.create(new LongWritable(3), new EdgeValueWritable())); computation.compute(vertex, new ArrayList<MessageWritable>()); //double tAfter = computation.getT(); //assertTrue(vertex.isHalted()); //cool should be called in superstep6 //assertEquals(10,tBefore-tAfter,0); }
From source file:graphvis.test.FruchtermanReingoldGraphVisTest.java
License:MIT License
/** * Test superstep606/*ww w .j av a 2 s . com*/ */ @Test public void testSuperstep606() throws Exception { Vertex<LongWritable, VertexValueWritable, EdgeValueWritable> vertex = new DefaultVertex<LongWritable, VertexValueWritable, EdgeValueWritable>(); FruchtermanReingoldGraphVis computation = mock(FruchtermanReingoldGraphVis.class); when(computation.getAggregatedValue("T")).thenReturn(new DoubleWritable(1000)); when(computation.getAggregatedValue("k")).thenReturn(new DoubleWritable(4000000)); //double tBefore = computation.getT(); MockUtils.MockedEnvironment<LongWritable, VertexValueWritable, EdgeValueWritable, MessageWritable> env = MockUtils .prepareVertexAndComputation(vertex, new LongWritable(1L), new VertexValueWritable(), false, computation, 606L); vertex.setValue(new VertexValueWritable()); vertex.addEdge(EdgeFactory.create(new LongWritable(2L), new EdgeValueWritable())); vertex.addEdge(EdgeFactory.create(new LongWritable(3L), new EdgeValueWritable())); computation.compute(vertex, new ArrayList<MessageWritable>()); //double tAfter = computation.getT(); //assertTrue(vertex.isHalted()); //cool should be called in superstep6 //assertEquals(10,tBefore-tAfter,0); //computation should stop after this superstep, so no messages should be sent env.verifyNoMessageSent(); }
From source file:hivemall.classifier.GeneralClassifierUDTFTest.java
License:Apache License
@Test public void testWritableLongFeature() throws Exception { List<LongWritable> x = Arrays.asList(new LongWritable(111L), new LongWritable(222L)); ObjectInspector featureOI = PrimitiveObjectInspectorFactory.writableLongObjectInspector; testFeature(x, featureOI, LongWritable.class, Long.class); }
From source file:hivemall.mix.MixMessageDecoder.java
License:Open Source License
private static Object decodeObject(final ByteBuf in) throws IOException { final byte type = in.readByte(); switch (type) { case INTEGER_TYPE: { int i = in.readInt(); return Integer.valueOf(i); }// w w w. j a v a2 s .com case TEXT_TYPE: { int length = in.readInt(); byte[] b = new byte[length]; in.readBytes(b, 0, length); Text t = new Text(b); return t; } case STRING_TYPE: { return readString(in); } case INT_WRITABLE_TYPE: { int i = in.readInt(); return new IntWritable(i); } case LONG_WRITABLE_TYPE: { long l = in.readLong(); return new LongWritable(l); } default: break; } throw new IllegalStateException("Illegal type: " + type); }
From source file:hivemall.tools.mapred.RowNumberUDF.java
License:Apache License
public RowNumberUDF() { this.sequence = 0L; this.taskId = -1; this.result = new LongWritable(Double.doubleToLongBits(Double.NaN)); }
From source file:hivemall.utils.hadoop.WritableUtils.java
License:Open Source License
public static LongWritable val(final long v) { return new LongWritable(v); }
From source file:hydrograph.engine.cascading.scheme.hive.parquet.ParquetWritableUtils.java
License:Apache License
private static Writable createPrimitive(final Object obj, final PrimitiveObjectInspector inspector) throws SerDeException { if (obj == null) { return null; }//from w w w. j a v a 2 s . c om switch (inspector.getPrimitiveCategory()) { case VOID: return null; case BOOLEAN: return new BooleanWritable( ((BooleanObjectInspector) inspector).get(new BooleanWritable((boolean) obj))); case BYTE: return new ByteWritable(((ByteObjectInspector) inspector).get(new ByteWritable((byte) obj))); case DOUBLE: return new DoubleWritable(((DoubleObjectInspector) inspector).get(new DoubleWritable((double) obj))); case FLOAT: return new FloatWritable(((FloatObjectInspector) inspector).get(new FloatWritable((float) obj))); case INT: return new IntWritable(((IntObjectInspector) inspector).get(new IntWritable((int) obj))); case LONG: return new LongWritable(((LongObjectInspector) inspector).get(new LongWritable((long) obj))); case SHORT: return new ShortWritable(((ShortObjectInspector) inspector).get(new ShortWritable((short) obj))); case STRING: String v; if (obj instanceof Long) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date((long) obj); v = df.format(date); } else if (obj instanceof BigDecimal) { BigDecimal bigDecimalObj = (BigDecimal) obj; v = bigDecimalObj.toString(); } else { v = ((StringObjectInspector) inspector).getPrimitiveJavaObject(obj); } try { return new BytesWritable(v.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new SerDeException("Failed to encode string in UTF-8", e); } case DECIMAL: HiveDecimal hd; if (obj instanceof Double) { hd = HiveDecimal.create(new BigDecimal((Double) obj)); } else if (obj instanceof BigDecimal) { hd = HiveDecimal.create((BigDecimal) obj); } else { // if "obj" is other than Double or BigDecimal and a vaild // number, .toString, will get its correct number representation // and a BigDecimal object will be created hd = HiveDecimal.create(new BigDecimal(obj.toString())); } return new HiveDecimalWritable(hd); case TIMESTAMP: return new TimestampWritable(((TimestampObjectInspector) inspector) .getPrimitiveJavaObject(new TimestampWritable(new Timestamp((long) obj)))); case DATE: return new DateWritable(((DateObjectInspector) inspector) .getPrimitiveJavaObject(new DateWritable(new Date((long) obj)))); case CHAR: String strippedValue = ((HiveCharObjectInspector) inspector).getPrimitiveJavaObject(obj) .getStrippedValue(); return new BytesWritable(Binary.fromString(strippedValue).getBytes()); case VARCHAR: String value = ((HiveVarcharObjectInspector) inspector).getPrimitiveJavaObject(obj).getValue(); return new BytesWritable(Binary.fromString(value).getBytes()); default: throw new SerDeException("Unknown primitive : " + inspector.getPrimitiveCategory()); } }