找不到 hbase.mapreduce.TableOutputFormat
Posted
技术标签:
【中文标题】找不到 hbase.mapreduce.TableOutputFormat【英文标题】:hbase.mapreduce.TableOutputFormat not found 【发布时间】:2019-01-14 12:54:03 【问题描述】:我正在使用 hdp 2.6 和 hbase1.1.2。
当我从不在 hdp 集群中的服务器提交 map-reduce 作业时, 我得到了以下异常:
Class org.apache.hadoop.hbase.mapreduce.TableOutputFormat not found.
我的映射器在本地作业模式下正确完成,我非常确定这个类在我的类路径中,并且集群中的 lib 也有这个 jar。
我用谷歌搜索了其他人所做的几个步骤: 1. 使用-libjars 2.将hbase_classpath添加到hadoop.env并重启集群 3. 将 hbase-master/lib 添加到 yarn-site.xml 并重启集群 但这些都行不通。请帮助我,因为我只能使用 mr 来完成这项任务。
这是我的代码:
package com.test.service;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.mapreduce.ImportTsv;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.util.ToolRunner;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@Service
public class Tsv2HBaseService
private org.apache.hadoop.conf.Configuration config;
private String principle;
private String keytab;
Tsv2HBaseService(@Value("$hbase.kerberos.REALM") String principle,
@Value("$hbase.kerberos.keytab") String keytab)
this.config = HBaseConfiguration.create();
this.principle = principle;
this.keytab = keytab;
public int importMultiKeyWithTableTSV(String table, String tsvfile, String className) throws Exception
String args[] =
"-Dimporttsv.mapper.class=" + className,
"-DtableStructure.file=" + tsvfile.replace(".csv", ".xml"),
table,
tsvfile,
"-libjars ./hbase-client-1.1.2.jar,./hbase-server-1.1.2.jar,./hbase-protocol-1.1.2.jar,./hbase-common-1.1.2.jar"
;
config.set("hadoop.security.authentication" , "Kerberos");
UserGroupInformation.setConfiguration(this.config);
UserGroupInformation.loginUserFromKeytab(this.principle, this.keytab);
return ToolRunner.run(config, new ImportTsv(), args);
package com.test.web;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.CellCreator;
import org.apache.hadoop.hbase.util.Base64;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
public class GRZHXXTsvImporterMapper extends Mapper<LongWritable, Text, ImmutableBytesWritable, Put>
private static final Logger logger = LoggerFactory.getLogger(Tsv2HbaseController.class);
@Override
public void map(LongWritable offset, Text value, Mapper<LongWritable, Text, ImmutableBytesWritable, Put>.Context context)
throws IOException
try
String[] row = value.toString().split(",");
ImmutableBytesWritable rowKey = new ImmutableBytesWritable((row[0]+row[1]+row[2]).getBytes());
Put put = new Put(rowKey.copyBytes());
KeyValue kv3 = new KeyValue(rowKey.copyBytes(), "PUBLIC".getBytes(),"GRJCJS".getBytes(), row[3].getBytes());
put.add(kv3);
// Write user table put
context.write(rowKey, put);
catch (Exception e)
e.printStackTrace();
hadoop-env.sh:
...lots of settings...
HADOOP_CLASSPATH=$HADOOP_CLASSPATHJAVA_JDBC_LIBS$HBASE_CLASSPATH
...lots of settings...
yarn-site.xml:
...lots of settings...
yarn.application.classpath=.......,/usr/hdp/current/hbase-master/lib/*
...lots of settings...
【问题讨论】:
【参考方案1】:我终于找到了解决办法。
将 hbase-master 添加到下面的类路径中: 纱线站点.xml mapred-site.xml
xml都应该在集群和自己的jar资源中修改。
【讨论】:
以上是关于找不到 hbase.mapreduce.TableOutputFormat的主要内容,如果未能解决你的问题,请参考以下文章