2016-04-21 5 views
0

In Karte lesen I HDFS Datei Update Hbase,hdfs Klartext schreiben zu hbase, Ausgabeverzeichnis nicht gesetzt

Version: hadoop 2.5.1 hbase 1.0.0

Ausnahme wie folgt:

Exception in thread "main" org.apache.hadoop.mapred.InvalidJobConfException: Output directory not set. 

vielleicht ist es etwas falsch mit

job.setOutputFormatClass(TableOutputFormat.class); 

diese Aufforderung:

The method setOutputFormatClass(Class<? extends OutputFormat>) in the type Job is not applicable for the arguments (Class<TableOutputFormat>) 

Codes wie folgt:

public class HdfsAppend2HbaseUtil extends Configured implements Tool{ 

    public static class HdfsAdd2HbaseMapper extends Mapper<Text, Text, ImmutableBytesWritable, Put>{ 

     public void map(Text ikey, Text ivalue, Context context) 
       throws IOException, InterruptedException { 

      String oldIdList = HBaseHelper.getValueByKey(ikey.toString()); 

      StringBuffer sb = new StringBuffer(oldIdList); 
      String newIdList = ivalue.toString(); 
      sb.append("\t" + newIdList); 

      Put p = new Put(ikey.toString().getBytes()); 
      p.addColumn("idFam".getBytes(), "idsList".getBytes(), sb.toString().getBytes()); 
      context.write(new ImmutableBytesWritable(), p); 

     } 

    } 

    public int run(String[] paths) throws Exception { 

     Configuration conf = HBaseConfiguration.create(); 
     conf.set("hbase.zookeeper.quorum", "master,salve1"); 
     conf.set("hbase.zookeeper.property.clientPort", "2181"); 

     Job job = Job.getInstance(conf,"AppendToHbase"); 
     job.setJarByClass(cn.edu.hadoop.util.HdfsAppend2HbaseUtil.class); 

     job.setInputFormatClass(KeyValueTextInputFormat.class); 

     job.setMapperClass(HdfsAdd2HbaseMapper.class); 
     job.setNumReduceTasks(0); 

     job.setOutputFormatClass(TableOutputFormat.class); 

     job.getConfiguration().set(TableOutputFormat.OUTPUT_TABLE, "reachableTable"); 

     FileInputFormat.setInputPaths(job, new Path(paths[0])); 


     job.setOutputKeyClass(ImmutableBytesWritable.class); 
     job.setOutputValueClass(Put.class); 


     return job.waitForCompletion(true) ? 0 : 1; 
    } 

    public static void main(String[] args) throws Exception { 

     System.out.println("Append Start: "); 

     long time1 = System.currentTimeMillis(); 
     long time2; 
     String[] pathsStr = {Const.TwoDegreeReachableOutputPathDetail}; 

     int exitCode = ToolRunner.run(new HdfsAppend2HbaseUtil(), pathsStr); 
     time2 = System.currentTimeMillis(); 
     System.out.println("Append Cost " + "\t" + (time2-time1)/1000 +" s"); 

     System.exit(exitCode); 
    } 
} 

Antwort

0

Sie haben nicht das Ausgabeverzeichnis erwähnen, wo es um die Ausgabe zu schreiben, wie Sie für Eingangsweg gab.
Erwähnen Sie es so.

FileOutputFormat.setOutputPath(job, new Path(<output path>)); 
+0

In der Tat, ich brauche kein Ausgabeverzeichnis, ich möchte die Daten in Hbase aktualisieren. Ich bin nicht sehr klar darüber, wie zu aktualisieren, wenn Sie wissen, bitte teilen Sie mir danken U sehr. –

+0

Tank U sehr viel !!! –

0

Endlich, ich weiß, warum, so wie ich es sollte etwas falsch mit:

job.setOutputFormatClass(TableOutputFormat.class); 

diese Aufforderung:

The method setOutputFormatClass(Class<? extends OutputFormat>) in the type Job is not applicable for the arguments (Class<TableOutputFormat>) 

In der Tat hier müssen wir importieren

org.apache.hadoop.hbase.mapreduce.TableOutputFormat 

nicht zu importieren

org.apache.hadoop.hbase.mapred.TableOutputFormat 

der ehemalige erstreckt sich von org.apache.hadoop.mapred.FileOutputFormat

siehe: https://hbase.apache.org/apidocs/org/apache/hadoop/hbase/mapred/TableOutputFormat.html

und die später erstreckt sich von org.apache.hadoop.mapreduce.OutputFormat

siehe:

https://hbase.apache.org/apidocs/org/apache/hadoop/hbase/mapreduce/TableOutputFormat.html

Endlich vielen Dank !!!

Verwandte Themen