hbase - MapReduce for Loading TSV -
i trying load data cloud bigtable using mapreduce job such values of first column set hbase row key.here code , sample tsv file.
1011 v1 v2 v3 v4 1012 c1 c2 c3 c4 1013 k1 k2 k3 k4 1014 s1 s2 s3 s4 1015 r1 r3 r2 r4 1016 p1 p2 p7 p9
here code sample :-
public static class tokenizermapper extends mapper<text, text, text,text> { @override public void map(text key, text value, context context) throws ioexception, interruptedexception { string fields[] = null; csvparser csvparser = new csvparser('\t'); fields = csvparser.parseline(value.tostring()); log.info(fields[0]); context.write(new text(fields[0]), value); } } public static class mytablereducer extends tablereducer<text, text, text> { @override public void reduce(text key, iterable<text> values, context context) throws ioexception, interruptedexception { string[] fields = null; csvparser csvparser = new csvparser('\t'); try { for(text value: values) { fields = csvparser.parseline(value.tostring()); (int = 1; < fields.length; ++i) { put put = new put(bytes.tobytes(fields[0])); put.addcolumn(column_family, bytes.tobytes(cols[i]), bytes.tobytes(fields[i])); context.write(key, put); } } } catch (exception ex) { context.getcounter("hbasekvmapper", "parse_errors").increment(1); return; } } } public static void main(string[] args) throws exception { configuration conf = hbaseconfiguration.create(); conf.set("mapreduce.input.keyvaluelinerecordreader.key.value.separator", "\t"); job job = job.getinstance(conf, "bigtableloader"); job.setinputformatclass(keyvaluetextinputformat.class); keyvaluetextinputformat.addinputpath(job,new path(args[0])); tablename tablename = tablename.valueof(args[1]); job.setjarbyclass(bigtableloader.class); job.setmapperclass(tokenizermapper.class); job.setmapoutputvalueclass(text.class); job.setmapoutputkeyclass(text.class); tablemapreduceutil.inittablereducerjob(tablename.getnameasstring(), mytablereducer.class, job); system.exit(job.waitforcompletion(true) ? 0 : 1); } }
the problem getting instead of first column, second column has been set key in table, , first column ignored i.e. doesn't exist in table. there missing??
Comments
Post a Comment