@Override // The evaluate() method. The input is passed in as an array of DeferredObjects, so that // computation is not wasted on deserializing them if they're not actually used public Object evaluate(DeferredObject[] arguments) throws HiveException { Object obj = arguments[0].get(); return serde.serializeField(obj, inOi); }
/** * Serializes a Union */ private Object serializeUnion(Object obj, UnionObjectInspector oi) { if(obj == null) return null; return serializeField(obj, oi.getObjectInspectors().get(oi.getTag(obj))); }
/** * Serializes a Hive map<> using a JSONObject. * * @param obj the object to serialize * @param moi the object's inspector * @return */ private JSONObject serializeMap(Object obj, MapObjectInspector moi) { if (obj==null) { return null; } JSONObject jo = new JSONObject(); Map m = moi.getMap(obj); for(Object k : m.keySet()) { try { jo.put( serializeField(k, moi.getMapKeyObjectInspector()).toString(), serializeField(m.get(k), moi.getMapValueObjectInspector()) ); } catch (JSONException ex) { LOG.warn("Problem serializing map"); } } return jo; }
/** * Serializes a Hive List using a JSONArray * * @param obj the object to serialize * @param loi the object's inspector * @return */ private JSONArray serializeList(Object obj, ListObjectInspector loi) { // could be an array of whatever! // we do it in reverse order since the JSONArray is grown on demand, // as higher indexes are added. if(obj==null) { return null; } JSONArray ar = new JSONArray(); for(int i=loi.getListLength(obj)-1; i>=0; i--) { Object element = loi.getListElement(obj, i); try { ar.put(i, serializeField(element, loi.getListElementObjectInspector() ) ); } catch (JSONException ex) { LOG.warn("Problem serializing array", ex); throw new RuntimeException(ex); } } return ar; }
serializeField( data, sf.getFieldObjectInspector()));