数据清洗5

依然是mapper
20200101,beijing>2020-01-01,beijing

package test5;

import org.apache.hadoop.io.IntWritable;
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 org.codehaus.jettison.json.JSONObject;


import javax.lang.model.element.AnnotationValue;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class mapppppp extends Mapper<LongWritable, Text,Text, NullWritable> {
    Text k=new Text();
    IntWritable v=new IntWritable();
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        Text  k=new Text();

       // Calendar c1=Calendar.getInstance();
        //为日期设置毫秒数
      //  c1.setTimeInMillis(System.currentTimeMillis());
        //得到当前日期
      //  Date date=c1.getTime();
        //对日期进行格式转换--转换格式
      //  SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //格式转换
    //    String str=sdf.format(date);



        String line=value.toString();
       // String   line=new String(value.getBytes(),0,value.getLength(),"GBK");
        String[] word=line.split("");

        JSONObject obj=new JSONObject();

       // net.sf.json.JSONObject j = net.sf.json.JSONObject.fromObject(line);
       // String[] d = new String[10];

        word[4]= "-"+word[4];
        word[6]= "-"+word[6];
       // word[6]=word[6].replace("","-");
        String end = "";
        for (String item: word){
            end = end + item + "";
        }
//格式转换

      // j.put("-",d[1]);
      //  j.put("-",d[0]);
        k.set(String.valueOf(end));

        context.write(k,NullWritable.get());

    }
}

©️2020 CSDN 皮肤主题: 1024 设计师:上身试试 返回首页