TsFileSerDe extends AbstractSerDe { @Override public Object deserialize(Writable blob) throws SerDeException { return getDeserializer().deserialize(columnNames, columnTypes, blob, deviceId); }  @Override void initialize(@Nullable Configuration conf, Properties tbl); @Override Class<? extends Writable> getSerializedClass(); @Override Writable serialize(Object obj, ObjectInspector objInspector); @Override SerDeStats getSerDeStats(); @Override Object deserialize(Writable blob); @Override ObjectInspector getObjectInspector(); static final String DEVICE_ID; }
@Test public void testDeserialize() { try { tsFileSerDer.initialize(job, tbl); } catch (SerDeException e) { e.printStackTrace(); fail(); } assertEquals(PrimitiveObjectInspector.PrimitiveCategory.LONG, ((PrimitiveTypeInfo)columnTypes.get(0)).getPrimitiveCategory()); Writable worryWritable1 = new Text(); try { tsFileSerDer.deserialize(worryWritable1); fail("Expect a TsFileSerDeException to be thrown!"); } catch (SerDeException e) { assertEquals("Expecting a MapWritable", e.getMessage()); } MapWritable worryWritable2 = new MapWritable(); worryWritable2.put(new Text("device_id"), new Text("device_2")); worryWritable2.put(new Text("time_stamp"), new LongWritable(1L)); worryWritable2.put(new Text("sensor_1"), new LongWritable(1L)); try { assertNull(tsFileSerDer.deserialize(worryWritable2)); } catch (SerDeException e) { fail("Don't expect a TsFileSerDeException to be Thrown!"); } MapWritable worryWritable3 = new MapWritable(); worryWritable3.put(new Text("device_id"), new Text("device_1")); worryWritable3.put(new Text("time_stamp"), new LongWritable(1L)); worryWritable3.put(new Text("sensor_1"), new IntWritable(1)); try { tsFileSerDer.deserialize(worryWritable3); fail("Expect a TsFileSerDeException to be thrown!"); } catch (SerDeException e) { assertEquals("Unexpected data type: " + worryWritable3.get(new Text("sensor_1")).getClass().getName() + " for Date TypeInfo: " + PrimitiveObjectInspector.PrimitiveCategory.LONG, e.getMessage()); } MapWritable writable = new MapWritable(); writable.put(new Text("device_id"), new Text("device_1")); writable.put(new Text("time_stamp"), new LongWritable(1L)); writable.put(new Text("sensor_1"), new LongWritable(1000000L)); try { Object result = tsFileSerDer.deserialize(writable); assertTrue(result instanceof List); List<Object> row = (List<Object>) result; assertEquals(columnNames.size(), row.size()); assertEquals(1L, row.get(0)); assertEquals(1000000L, row.get(1)); } catch (SerDeException e) { fail("Don't expect a TsFileSerDeException to be Thrown!"); } }