List of usage examples for org.apache.hadoop.io VIntWritable VIntWritable
public VIntWritable(int value)
From source file:com.ikanow.aleph2.search_service.elasticsearch.utils.TestJsonNodeWritableUtils.java
License:Apache License
@Test public void test_transform() { final ObjectMapper mapper = BeanTemplateUtils.configureMapper(Optional.empty()); new JsonNodeWritableUtils(); //coverage! assertEquals(NullNode.instance, JsonNodeWritableUtils.transform("banana", JsonNodeFactory.instance)); assertEquals(null, JsonNodeWritableUtils.transform(null, JsonNodeFactory.instance)); assertEquals(NullNode.instance,/*from w w w. j a v a2s. co m*/ JsonNodeWritableUtils.transform(NullWritable.get(), JsonNodeFactory.instance)); assertEquals(mapper.convertValue(true, JsonNode.class), JsonNodeWritableUtils.transform(new BooleanWritable(true), JsonNodeFactory.instance)); assertEquals(mapper.convertValue("test", JsonNode.class), JsonNodeWritableUtils.transform(new Text("test"), JsonNodeFactory.instance)); assertEquals(mapper.convertValue(new byte[] { (byte) 0xFF }, JsonNode.class), JsonNodeWritableUtils.transform(new ByteWritable((byte) 0xFF), JsonNodeFactory.instance)); assertEquals(mapper.convertValue(4, JsonNode.class), JsonNodeWritableUtils.transform(new IntWritable(4), JsonNodeFactory.instance)); assertEquals(mapper.convertValue(4, JsonNode.class), JsonNodeWritableUtils.transform(new VIntWritable(4), JsonNodeFactory.instance)); assertEquals(mapper.convertValue(4L, JsonNode.class), JsonNodeWritableUtils.transform(new LongWritable(4), JsonNodeFactory.instance)); assertEquals(mapper.convertValue(4L, JsonNode.class), JsonNodeWritableUtils.transform(new VLongWritable(4), JsonNodeFactory.instance)); assertEquals(mapper.convertValue(new byte[] { (byte) 0xFF, (byte) 0xFE }, JsonNode.class), JsonNodeWritableUtils.transform(new BytesWritable(new byte[] { (byte) 0xFF, (byte) 0xFE }), JsonNodeFactory.instance)); assertEquals(mapper.convertValue(4.0, JsonNode.class), JsonNodeWritableUtils.transform(new DoubleWritable(4), JsonNodeFactory.instance)); //(had real trouble creating a float node!) assertEquals(JsonNodeFactory.instance.numberNode(Float.valueOf((float) 4.0)), JsonNodeWritableUtils.transform(new FloatWritable(4), JsonNodeFactory.instance)); // will test object writable and array writable below }
From source file:com.toshiba.mwcloud.gs.hadoop.io.GSRowWritable.java
License:Apache License
private void writeColumn(DataOutput out, int i) throws IOException { switch (types_[i]) { case BLOB:/*from w w w .j a va2s . co m*/ out.writeByte(BLOB); writeBlob(out, (Blob) values_[i]); break; case BOOL: out.writeByte(BOOL); out.writeBoolean((Boolean) values_[i]); break; case BYTE: out.writeByte(BYTE); out.writeByte((Byte) values_[i]); break; case DOUBLE: out.writeByte(DOUBLE); out.writeDouble((Double) values_[i]); break; case FLOAT: out.writeByte(FLOAT); out.writeFloat((Float) values_[i]); break; case INTEGER: out.writeByte(INTEGER); new VIntWritable((Integer) values_[i]).write(out); break; case LONG: out.writeByte(LONG); new VLongWritable((Long) values_[i]).write(out); break; case SHORT: out.writeByte(SHORT); out.writeShort((Short) values_[i]); break; case STRING: out.writeByte(STRING); writeString(out, (String) values_[i]); break; case TIMESTAMP: out.writeByte(TIMESTAMP); out.writeLong(((Date) values_[i]).getTime()); break; case BOOL_ARRAY: out.writeByte(BOOL_ARRAY); writeBoolArray(out, (boolean[]) values_[i]); break; case BYTE_ARRAY: out.writeByte(BYTE_ARRAY); writeByteArray(out, (byte[]) values_[i]); break; case DOUBLE_ARRAY: out.writeByte(DOUBLE_ARRAY); writeDoubleArray(out, (double[]) values_[i]); break; case FLOAT_ARRAY: out.writeByte(FLOAT_ARRAY); writeFloatArray(out, (float[]) values_[i]); break; case INTEGER_ARRAY: out.writeByte(INTEGER_ARRAY); writeIntegerArray(out, (int[]) values_[i]); break; case LONG_ARRAY: out.writeByte(LONG_ARRAY); writeLongArray(out, (long[]) values_[i]); break; case SHORT_ARRAY: out.writeByte(SHORT_ARRAY); writeShortArray(out, (short[]) values_[i]); break; case STRING_ARRAY: out.writeByte(STRING_ARRAY); writeStringArray(out, (String[]) values_[i]); break; case TIMESTAMP_ARRAY: out.writeByte(TIMESTAMP_ARRAY); writeTimestampArray(out, (Date[]) values_[i]); break; default: throw new IOException(); } }
From source file:crunch.MaxTemperature.java
License:Apache License
@Test public void mapWritable() throws IOException { // vv MapWritableTest MapWritable src = new MapWritable(); src.put(new IntWritable(1), new Text("cat")); src.put(new VIntWritable(2), new LongWritable(163)); MapWritable dest = new MapWritable(); WritableUtils.cloneInto(dest, src); assertThat((Text) dest.get(new IntWritable(1)), is(new Text("cat"))); assertThat((LongWritable) dest.get(new VIntWritable(2)), is(new LongWritable(163))); // ^^ MapWritableTest }//from w w w . ja v a 2 s . c o m
From source file:crunch.MaxTemperature.java
License:Apache License
@Test public void test() throws IOException { // vv VIntWritableTest byte[] data = serialize(new VIntWritable(163)); assertThat(StringUtils.byteToHexString(data), is("8fa3")); // ^^ VIntWritableTest }// w ww .ja v a 2 s . c o m
From source file:crunch.MaxTemperature.java
License:Apache License
@Test public void testSizes() throws IOException { assertThat(serializeToString(new VIntWritable(1)), is("01")); // 1 byte assertThat(serializeToString(new VIntWritable(-112)), is("90")); // 1 byte assertThat(serializeToString(new VIntWritable(127)), is("7f")); // 1 byte assertThat(serializeToString(new VIntWritable(128)), is("8f80")); // 2 byte assertThat(serializeToString(new VIntWritable(163)), is("8fa3")); // 2 byte assertThat(serializeToString(new VIntWritable(Integer.MAX_VALUE)), is("8c7fffffff")); // 5 byte assertThat(serializeToString(new VIntWritable(Integer.MIN_VALUE)), is("847fffffff")); // 5 byte }/* ww w . ja v a 2 s . co m*/
From source file:hivemall.utils.hadoop.WritableUtils.java
License:Open Source License
public static Writable toWritable(Object object) { if (object == null) { return null; //return NullWritable.get(); }/*from w w w . ja va2 s .c om*/ if (object instanceof Writable) { return (Writable) object; } 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 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); } return new BytesWritable(object.toString().getBytes()); }
From source file:io.aos.hdfs.MapWritableTest.java
License:Apache License
@Test public void mapWritable() throws IOException { // vv MapWritableTest MapWritable src = new MapWritable(); src.put(new IntWritable(1), new Text("cat")); src.put(new VIntWritable(2), new LongWritable(163)); MapWritable dest = new MapWritable(); WritableUtils.cloneInto(dest, src);//from www . j a va 2 s . c om assertThat((Text) dest.get(new IntWritable(1)), is(new Text("cat"))); assertThat((LongWritable) dest.get(new VIntWritable(2)), is(new LongWritable(163))); // ^^ MapWritableTest }
From source file:io.aos.hdfs.VIntWritableTest.java
License:Apache License
@Test public void test() throws IOException { // vv VIntWritableTest byte[] data = serialize(new VIntWritable(163)); assertThat(StringUtils.byteToHexString(data), is("8fa3")); // ^^ VIntWritableTest }
From source file:io.aos.hdfs.VIntWritableTest.java
License:Apache License
@Test public void testSizes() throws IOException { assertThat(serializeToString(new VIntWritable(1)), is("01")); // 1 byte assertThat(serializeToString(new VIntWritable(-112)), is("90")); // 1 byte assertThat(serializeToString(new VIntWritable(127)), is("7f")); // 1 byte assertThat(serializeToString(new VIntWritable(128)), is("8f80")); // 2 byte assertThat(serializeToString(new VIntWritable(163)), is("8fa3")); // 2 byte assertThat(serializeToString(new VIntWritable(Integer.MAX_VALUE)), is("8c7fffffff")); // 5 byte assertThat(serializeToString(new VIntWritable(Integer.MIN_VALUE)), is("847fffffff")); // 5 byte }
From source file:org.apache.hcatalog.data.ReaderWriter.java
License:Apache License
public static void writeDatum(DataOutput out, Object val) throws IOException { // write the data type byte type = DataType.findType(val); switch (type) { case DataType.LIST: out.writeByte(DataType.LIST);/*w w w .j a v a 2 s. c o m*/ List<?> list = (List<?>) val; int sz = list.size(); out.writeInt(sz); for (int i = 0; i < sz; i++) { writeDatum(out, list.get(i)); } return; case DataType.MAP: out.writeByte(DataType.MAP); Map<?, ?> m = (Map<?, ?>) val; out.writeInt(m.size()); Iterator<?> i = m.entrySet().iterator(); while (i.hasNext()) { Entry<?, ?> entry = (Entry<?, ?>) i.next(); writeDatum(out, entry.getKey()); writeDatum(out, entry.getValue()); } return; case DataType.INTEGER: out.writeByte(DataType.INTEGER); new VIntWritable((Integer) val).write(out); return; case DataType.LONG: out.writeByte(DataType.LONG); new VLongWritable((Long) val).write(out); return; case DataType.FLOAT: out.writeByte(DataType.FLOAT); out.writeFloat((Float) val); return; case DataType.DOUBLE: out.writeByte(DataType.DOUBLE); out.writeDouble((Double) val); return; case DataType.BOOLEAN: out.writeByte(DataType.BOOLEAN); out.writeBoolean((Boolean) val); return; case DataType.BYTE: out.writeByte(DataType.BYTE); out.writeByte((Byte) val); return; case DataType.SHORT: out.writeByte(DataType.SHORT); out.writeShort((Short) val); return; case DataType.STRING: String s = (String) val; byte[] utfBytes = s.getBytes(ReaderWriter.UTF8); out.writeByte(DataType.STRING); out.writeInt(utfBytes.length); out.write(utfBytes); return; case DataType.BINARY: byte[] ba = (byte[]) val; out.writeByte(DataType.BINARY); out.writeInt(ba.length); out.write(ba); return; case DataType.NULL: out.writeByte(DataType.NULL); return; default: throw new IOException("Unexpected data type " + type + " found in stream."); } }