ExcelSpreadSheetCellDAOSerde extends AbstractSerDe { @Override public Writable serialize(Object arg0, ObjectInspector arg1) throws SerDeException { if (!(arg1 instanceof StructObjectInspector)) { throw new SerDeException("Expect a row of Strings for serialization"); } final StructObjectInspector outputOI = (StructObjectInspector) arg1; final List<? extends StructField> outputFields = outputOI.getAllStructFieldRefs(); if (outputFields.size()!=ExcelSpreadSheetCellDAOSerde.columnNames.length) { throw new SerDeException("Expected "+ExcelSpreadSheetCellDAOSerde.columnNames.length+" fields characterizing a cell: \"formattedValue\",\"comment\",\"formula\",\"address\",\"sheetName\", but found "+outputFields.size()+" fields"); } if (arg0==null) { return null; } int columnNum=0; final Object foFormattedValue = outputOI.getStructFieldData(arg0, outputFields.get(columnNum)); final ObjectInspector oiFormattedValue = outputFields.get(columnNum).getFieldObjectInspector(); String formattedValue = String.valueOf(((PrimitiveObjectInspector) oiFormattedValue).getPrimitiveJavaObject(foFormattedValue)); columnNum=1; final Object foComment= outputOI.getStructFieldData(arg0, outputFields.get(columnNum)); final ObjectInspector oiComment = outputFields.get(columnNum).getFieldObjectInspector(); String comment = String.valueOf(((PrimitiveObjectInspector) oiComment).getPrimitiveJavaObject(foComment)); columnNum=2; final Object foFormula= outputOI.getStructFieldData(arg0, outputFields.get(columnNum)); final ObjectInspector oiFormula = outputFields.get(columnNum).getFieldObjectInspector(); String formula = String.valueOf(((PrimitiveObjectInspector) oiFormula).getPrimitiveJavaObject(foFormula)); columnNum=3; final Object foAddress= outputOI.getStructFieldData(arg0, outputFields.get(columnNum)); final ObjectInspector oiAddress = outputFields.get(columnNum).getFieldObjectInspector(); String address = String.valueOf(((PrimitiveObjectInspector) oiAddress).getPrimitiveJavaObject(foAddress)); columnNum=4; final Object foSheetName= outputOI.getStructFieldData(arg0, outputFields.get(columnNum)); final ObjectInspector oiSheetName = outputFields.get(columnNum).getFieldObjectInspector(); String sheetName = String.valueOf(((PrimitiveObjectInspector) oiSheetName).getPrimitiveJavaObject(foSheetName)); return new SpreadSheetCellDAO(formattedValue,comment,formula,address,sheetName); }  @Override void initialize(Configuration conf, Properties tbl); @Override void initialize(Configuration conf, Properties prop, Properties partitionProperties); @Override Class<? extends Writable> getSerializedClass(); @Override Writable serialize(Object arg0, ObjectInspector arg1); @Override SerDeStats getSerDeStats(); @Override Object deserialize(Writable arg0); @Override ObjectInspector getObjectInspector();  }
@Test public void serialize() throws SerDeException { ExcelSpreadSheetCellDAOSerde testSerde = new ExcelSpreadSheetCellDAOSerde(); Configuration hadoopConf = new Configuration(); Properties tblProperties = new Properties(); tblProperties.setProperty("hadoopoffice.write.locale.bcp47", "de"); testSerde.initialize(hadoopConf, tblProperties); ObjectInspector oi = testSerde.getObjectInspector(); String[] testHiveStructure = new String[5]; testHiveStructure[0] = "test1"; testHiveStructure[1] = "no comment"; testHiveStructure[2] = "A1*A2"; testHiveStructure[3] = "A3"; testHiveStructure[4] = "Sheet1"; SpreadSheetCellDAO resultDAO = (SpreadSheetCellDAO) testSerde.serialize(testHiveStructure, oi); assertEquals(testHiveStructure[0],resultDAO.getFormattedValue(),"formatted value correct"); assertEquals(testHiveStructure[1],resultDAO.getComment(),"comment correct"); assertEquals(testHiveStructure[2],resultDAO.getFormula(), "formula correct"); assertEquals(testHiveStructure[3],resultDAO.getAddress(), "address correct"); assertEquals(testHiveStructure[4],resultDAO.getSheetName(),"sheetname correct"); }