| 25 | import com.winvector.util.SerialUtils; |
| 26 | |
| 27 | public final class MapRedScan { |
| 28 | public static final String BURSTERSERFIELD = "MapRedScan.BursterScan"; |
| 29 | private static final String FORMULAFIELD = "MapRedScan.Formula"; |
| 30 | private static final String DEFFIELD = "MapRedScan.DefFieldName"; |
| 31 | |
| 32 | public static final class DefMapper extends Mapper<LongWritable,Text,LongWritable,WritableVariableList> { |
| 33 | // config |
| 34 | private LineBurster burster = null; |
| 35 | // derived |
| 36 | private Log log = null; |
| 37 | private String hostDescr = null; |
| 38 | // result |
| 39 | private WritableVariableList accum = null; |
| 40 | |
| 41 | @Override |
| 42 | public void setup(final Context context) throws IOException { |
| 43 | log = LogFactory.getLog(DefMapper.class); |
| 44 | hostDescr = WritableUtils.hostDescr(); |
| 45 | log.info(".setup() " + hostDescr); |
| 46 | // read side-channel configuration |
| 47 | accum = null; |
| 48 | try { |
| 49 | burster = SerialUtils.readSerialiazlabeFromString(context.getConfiguration().get(MapRedScan.BURSTERSERFIELD)); |
| 50 | final String formulaStr = context.getConfiguration().get(FORMULAFIELD); |
| 51 | final Formula f = new Formula(formulaStr); |
| 52 | accum = new WritableVariableList(); |
| 53 | accum.readyForDefTracking(f); |
| 54 | } catch (Exception e) { |
| 55 | throw new IOException(e.toString()); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public void map(final LongWritable key, final Text value, final Context context) { |
| 61 | final BurstMap parsed = burster.parse(value.toString()); |
| 62 | if(!parsed.isEmpty()) { |
| 63 | accum.trackVariableDefsFromRow(parsed); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public void cleanup(final Context context) throws IOException, InterruptedException { |
| 69 | context.write(new LongWritable(0),accum); |
| 70 | log.info(".cleanup() " + hostDescr); |
| 71 | burster = null; |
| 72 | accum = null; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | public static final class DefReducer extends Reducer<LongWritable,WritableVariableList,LongWritable,WritableVariableList> { |
| 77 | @Override |
| 78 | public void reduce(final LongWritable key, final Iterable<WritableVariableList> values, final Context context) throws IOException, InterruptedException { |
| 79 | WritableVariableList r = null; |
| 80 | for(final WritableVariableList vi: values) { |
| 81 | if(r==null) { |
| 82 | r = WritableVariableList.copy(vi); |
| 83 | } else { |
| 84 | r.mergeVariableDefs(vi); |
nothing calls this directly
no outgoing calls
no test coverage detected