用于加载TSV的MapReduce

用于加载TSV的MapReduce,mapreduce,hbase,google-cloud-bigtable,Mapreduce,Hbase,Google Cloud Bigtable,我正在尝试使用mapreduce作业将数据加载到Cloud Bigtable中,以便将第一列的值设置为hbase行键 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 以下是我的代码示例:- public static class TokenizerMapper

我正在尝试使用mapreduce作业将数据加载到Cloud Bigtable中,以便将第一列的值设置为hbase行键

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
以下是我的代码示例:-

    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());
                    for (int i = 1; i < 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);
    }
}
公共静态类TokenizerMapper扩展
制图员{
@凌驾
公共void映射(文本键、文本值、上下文上下文)引发IOException,
中断异常{
字符串字段[]=null;
CSVParser CSVParser=新的CSVParser('\t');
fields=csvParser.parseLine(value.toString());
日志信息(字段[0]);
write(新文本(字段[0]),值);
}
}
公共静态类MyTableReducer扩展
压片机{
@凌驾
公共void reduce(文本键、Iterable值、上下文)
抛出IOException、InterruptedException{
字符串[]字段=null;
CSVParser CSVParser=新的CSVParser('\t');
试一试{
用于(文本值:值){
fields=csvParser.parseLine(value.toString());
对于(int i=1;i
我遇到的问题是,不是第一列,而是第二列被设置为表中的键,并且第一列被完全忽略,即它在表中不存在。
是否有我遗漏的内容???

映射器中字段[0]的值是多少?即使在记录之后也没有打印任何内容,因此我不知道您导入的数据文件有多大?如果它不是一个大文件,那么在单个进程中导入它可能会更快更容易,而不使用MapReduce,因为它不需要调试CSV记录在MR中的序列化/传递方式。您的col数组是什么样子的?col[0]中是否有空值?@solomonduski col数组是一个字符串数组,类似于以下字符串col={“Atg_id”、“173”、“174”、“175”、“176”},这些是我正在使用的列限定符的名称映射器中字段[0]的值是什么?即使在日志记录之后也不会打印任何内容,所以我不知道你导入的数据文件有多大?如果它不是一个大文件,那么在单个进程中导入它可能会更快更容易,而不使用MapReduce,因为它不需要调试CSV记录在MR中的序列化/传递方式。您的col数组是什么样子的?col[0]中是否有空值?@solomonduski col数组是一个字符串数组,类似于以下字符串col={“Atg_id”、“173”、“174”、“175”、“176”},这些是我正在使用的列限定符的名称