senseiRequest.setSelectList(senseiProtoRequest.getSelectListList());
}
if (senseiProtoRequest.hasMapReduce()) {
SenseiMapReduce mapReduceFunction = convertMapReduce(senseiProtoRequest.getMapReduce());
if (mapReduceFunction != null) {
senseiRequest.setMapReduceFunction(mapReduceFunction);
List<String> columns = senseiProtoRequest.getMapReduceColumnsList();
JSONUtil.FastJSONObject jsonObject = new JSONUtil.FastJSONObject();
try {
jsonObject.put("column", columns.get(0));
jsonObject.put("columns", columns.toArray(new String[]{}));
} catch (JSONException e) {
throw new IllegalStateException(e);
}
senseiRequest.getMapReduceFunction().init(jsonObject);
} else {
ByteString mapReduceBytes = senseiProtoRequest.getMapReduceBytes();
Object object = null;
try {
ObjectInputStream ois = new ObjectInputStream(mapReduceBytes.newInput());
object = ois.readObject();
} catch (IOException ioException) {
// Shouldn't happen.
logger.error("IO Exception deserializing map reduce, ignoring mapreduce", ioException);
} catch (ClassNotFoundException cnfe) {
logger.error("Could not find class to deserialize to, ignoring mapreduce", cnfe);
}
if (object != null) {
SenseiMapReduce mapReduce = (SenseiMapReduce) object;
senseiRequest.setMapReduceFunction(mapReduce);
}
}
}