Hbase错误:java.lang.ClassCastException:org.apache.hadoop.io.Text无法强制转换为org.apache.hadoop.hbase.client.Mutation

时间:2016-03-27 12:35:02

标签: hadoop hbase hadoop2 mapper reducers

将值从一个Hbase表传输到其他Hbase表时,我遇到以下错误。从Hbase表转移到文件输出时,代码工作正常。

Error: java.lang.ClassCastException: org.apache.hadoop.io.Text cannot be cast to org.apache.hadoop.hbase.client.Mutation
    at org.apache.hadoop.hbase.mapreduce.TableOutputFormat$TableRecordWriter.write(TableOutputFormat.java:94)
    at org.apache.hadoop.mapred.ReduceTask$NewTrackingRecordWriter.write(ReduceTask.java:558)
    at org.apache.hadoop.mapreduce.task.TaskInputOutputContextImpl.write(TaskInputOutputContextImpl.java:89)
    at org.apache.hadoop.mapreduce.lib.reduce.WrappedReducer$Context.write(WrappedReducer.java:105)
    at org.apache.hadoop.mapreduce.Reducer.reduce(Reducer.java:150)
    at org.apache.hadoop.mapreduce.Reducer.run(Reducer.java:171)
    at org.apache.hadoop.mapred.ReduceTask.runNewReducer(ReduceTask.java:627)
    at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:389)
    at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:164)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:422)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1657)
    at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)

驱动程序类:

        // Mapper
        TableMapReduceUtil.initTableMapperJob(
                mailsTable,
                scan,
                SimHashMapper.class,
                Text.class, Text.class,
                job);
        //reducer
        String targetTable="old_64bit";
       TableMapReduceUtil.initTableReducerJob(
                targetTable,        // output table
                SimHashReducer.class,    // reducer class
                job);
return job;

Mapper类是:

 public static class SimHashMapper extends
            TableMapper<Text, Text> {

        public void map(ImmutableBytesWritable row, Result value,
                Context context) throws InterruptedException, IOException {
                         .......
           context.write(new Text(s),new Text(t));

Reducer类是:

public static class SimHashReducer extends
            TableReducer<Text, Text,ImmutableBytesWritable> {

        public void reduce(Text key, Text values, //values is a single Text value
                Context context) throws IOException, InterruptedException {


            Put put = new Put(Bytes.toBytes(values.toString()));
            put.add(Bytes.toBytes("64_bit_fingerprint"),Bytes.toBytes(""),Bytes.toBytes(values.toString()));
            //context.write(new ImmutableBytesWritable(Bytes.toBytes("old_64bit")),put);

           context.write(null, put);

提前致谢!!!

1 个答案:

答案 0 :(得分:0)

您的功能代码:

public void reduce(Text key, Text values, //values is a single Text value
            Context context) throws IOException, InterruptedException {


public void reduce(Text key, Iterable<Text> values, //values is a single Text value
            Context context) throws IOException, InterruptedException {