Skip to content

Instantly share code, notes, and snippets.

@jonathanmv
Created April 5, 2016 22:35
Show Gist options
  • Save jonathanmv/c6cf31f0dd44a59e06ca4d1ae8a6ef67 to your computer and use it in GitHub Desktop.
Save jonathanmv/c6cf31f0dd44a59e06ca4d1ae8a6ef67 to your computer and use it in GitHub Desktop.
Calls a converter giving it the json string and emits the converted thrift object
package jonathanmv.storage;
import java.io.IOException;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.json.simple.parser.ParseException;
public class JsonToThriftMapper extends Mapper<Object, Text, Void, FriendsEdge> {
public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
String jsonString = value.toString();
try {
JsonToThriftConverter converter = new JsonToThriftConverter(jsonString);
FriendsEdge thriftObject = converter.convert();
context.write(null, thriftObject);
} catch (ParseException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment