@@ -0,0 +1,1851 @@
+/*%0A * To change this license header, choose License Headers in Project Properties.%0A * To change this template file, choose Tools %7C Templates%0A * and open the template in the editor.%0A */%0Apackage com.telefonica.iot.bigdata.hadoop.mr.mappers;%0A%0Aimport com.telefonica.iot.bigdata.utils.Utils;%0Aimport java.io.IOException;%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.Iterator;%0Aimport org.apache.hadoop.io.Text;%0Aimport org.apache.hadoop.mapreduce.Mapper;%0Aimport org.json.simple.JSONObject;%0Aimport org.json.simple.parser.JSONParser;%0Aimport org.json.simple.parser.ParseException;%0A%0A/**%0A *%0A * @author frb%0A */%0Apublic class KeyGenerator extends Mapper%3CObject, Text, Text, Text%3E %7B%0A    %0A    private ArrayList%3CString%3E keyFields;%0A        %0A    @Override%0A    public void setup(Mapper.Context context) throws IOException, InterruptedException %7B%0A        String keyFieldsStr = context.getConfiguration().get(%22KEY_FIELDS%22, %22%22);%0A        keyFields = new ArrayList%3C%3E(Arrays.asList(keyFieldsStr.split(%22&%22)));%0A    %7D // setup%0A%0A    @Override%0A    public void map(Object key, Text value, Mapper.Context context) throws IOException, InterruptedException %7B%0A        JSONParser parser = new JSONParser();%0A        JSONObject jsonObject;%0A%0A        try %7B%0A            jsonObject = (JSONObject) parser.parse(value.toString());%0A        %7D catch (ParseException e) %7B%0A            throw new InterruptedException(e.getMessage());%0A        %7D // try catch%0A%0A        String k = %22%22;%0A        Iterator it = jsonObject.keySet().iterator();%0A%0A        while (it.hasNext()) %7B%0A            String field = (String) it.next();%0A            Object val = jsonObject.get(field);%0A%0A            if (keyFields.contains(field)) %7B%0A                k += Utils.serializeJsonValue(val);%0A            %7D // if%0A        %7D // while%0A%0A        context.write(new Text(k), value);%0A    %7D // map%0A    %0A%7D // KeyGenerator%0A

Add KeyGenerator.java