mapper代码
package test3;
import net.sf.json.JSONObject;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.codehaus.jettison.json.JSONException;
import java.io.IOException;
public class MAppear3 extends Mapper<LongWritable, Text,Text, NullWritable> {
Text k=new Text();
@Override
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
Text k=new Text();
/* ```北京, 2020.9.3, 多云, 17-28, 无持续风向 3-4级
处理后的结果: ```
北京, 2020-9-3, 多云, 17-28, 无持续风向 3-4级
*/
String line=value.toString();
net.sf.json.JSONObject j = JSONObject.fromObject(line);
String[] d = new String[2];
d[1]=j.getString("date");
d[0]=j.getString("city");
d[1]=d[1].replace(".","-");
j.put("date",d[1]);
j.put("city",d[0]);
k.set(j.toString());
context.write(k,NullWritable.get());
}
}