Я в змозі проаналізувати дані Json за допомогою mapreduce в hadoop, і я хотів відобразити 2 струнні змінні, як це в функції зменшення, нижче - код, який я намагався
public static class Map extends Mapper<LongWritable, Text, Text, Text>{
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException{
Double overall;
String reviewtime;
String line = value.toString();
//line = line.replaceAll("\s+","");
String[] tuple = line.split("\n");
try{
for(int i=0;i<tuple.length; i++){
JSONObject obj = new JSONObject(tuple[i]);
overall = obj.getDouble("overall");
reviewtime = obj.getString("reviewTime");
context.write(new Text(String.valueOf(overall)), new Text(reviewtime));
}
}catch(JSONException e){
e.printStackTrace();
}
}
}
Що писати у функцію "Зменшити", щоб я міг відображати над двома рядковими змінними у функції зменшення ... Я новачок у зменшенні та перетворенні, будь ласка, допоможіть мені, нижче - функція зменшення функції
public static class Reduce extends Reducer<Text,Text,NullWritable,Text>{
public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException{
try{
}catch(JSONException e){
e.printStackTrace();
}
}
}
Відповіді:
0 для відповіді № 1Я зрозумів, це правильний,
public static class Reduce extends Reducer<Text,Text,NullWritable,Text>{
public void reduce(NullWritable key, Iterable<Text> values, Context context) throws IOException, InterruptedException{
try{
for(Text val : values){
context.write(key, new Text(val.toString()));
}
}catch(JSONException e){
e.printStackTrace();
}
}
}