2012-06-16 10 views
8

से HBase को लिखना मेरे पास एक हैडॉप नौकरी है कि इसका आउटपुट एचबीएस को लिखा जाना चाहिए। मुझे वास्तव में reducer की जरूरत नहीं है, जिस तरह की पंक्ति मैं डालना चाहता हूं वह मैपर में निर्धारित है।हाडोप - सीधे मैपर

मैं इसे प्राप्त करने के लिए TableOutputFormat का उपयोग कैसे कर सकता हूं? सभी उदाहरणों से मैंने देखा है कि धारणा यह है कि रेड्यूसर पुट बनाने वाला है, और वह टेबलमैपर सिर्फ एचबीज़ टेबल से पढ़ने के लिए है।

मेरे मामले में इनपुट एचडीएफएस है, आउटपुट विशिष्ट तालिका में रखा जाता है, मुझे TableMapReduce में कुछ भी नहीं मिल रहा है, जो कि इसके साथ मेरी मदद कर सकता है।

क्या वहां कोई उदाहरण है जो मुझे इसके साथ मदद कर सकता है?

Btw, मैं नई Hadoop एपीआई

+0

आप कितने रिकॉर्ड डालने की कोशिश कर रहे हैं? – Gevorg

उत्तर

1

तुम बस नक्शाकार उत्पादन जोड़ी बनाने की जरूरत का उपयोग कर रहा हूँ। OutputFormat केवल आउटपुट कुंजी-मानों को बनाए रखने के लिए निर्दिष्ट करता है। इसका जरूरी अर्थ यह नहीं है कि प्रमुख मूल्य reducer से आते हैं। आप नक्शाकार में कुछ इस तरह करने की ज़रूरत होगी:

... extends TableMapper<ImmutableBytesWritable, Put>() { 
    ... 
    ... 
    context.write(<some key>, <some Put or Delete object>); 
} 
7

इस फ़ाइल से पढ़ने का उदाहरण है और HBase में सभी लाइनों डाल दिया। यह उदाहरण "हबेस: द निश्चित गाइड" से है और आप इसे भंडार पर पा सकते हैं। इस किताब को आप भी कोड के बारे में सभी स्पष्टीकरण प्राप्त कर सकते में

git clone git://github.com/larsgeorge/hbase-book.git 

: प्राप्त करने के लिए यह सिर्फ आपके कंप्यूटर पर रेपो क्लोन। लेकिन अगर आपके लिए कुछ समझ में नहीं आता है, तो पूछने के लिए स्वतंत्र महसूस करें।

` public class ImportFromFile { 
    public static final String NAME = "ImportFromFile"; 
    public enum Counters { LINES } 

    static class ImportMapper 
    extends Mapper<LongWritable, Text, ImmutableBytesWritable, Writable> { 
     private byte[] family = null; 
     private byte[] qualifier = null; 

     @Override 
     protected void setup(Context context) 
     throws IOException, InterruptedException { 
     String column = context.getConfiguration().get("conf.column"); 
     byte[][] colkey = KeyValue.parseColumn(Bytes.toBytes(column)); 
     family = colkey[0]; 
     if (colkey.length > 1) { 
      qualifier = colkey[1]; 
     } 
     } 

     @Override 
     public void map(LongWritable offset, Text line, Context context) 
     throws IOException { 
      try { 
      String lineString = line.toString(); 
      byte[] rowkey = DigestUtils.md5(lineString); 
      Put put = new Put(rowkey); 
      put.add(family, qualifier, Bytes.toBytes(lineString)); 
      context.write(new ImmutableBytesWritable(rowkey), put); 
      context.getCounter(Counters.LINES).increment(1); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     } 
    } 

    private static CommandLine parseArgs(String[] args) throws ParseException { 
     Options options = new Options(); 
     Option o = new Option("t", "table", true, 
     "table to import into (must exist)"); 
     o.setArgName("table-name"); 
     o.setRequired(true); 
     options.addOption(o); 
     o = new Option("c", "column", true, 
     "column to store row data into (must exist)"); 
     o.setArgName("family:qualifier"); 
     o.setRequired(true); 
     options.addOption(o); 
     o = new Option("i", "input", true, 
     "the directory or file to read from"); 
     o.setArgName("path-in-HDFS"); 
     o.setRequired(true); 
     options.addOption(o); 
     options.addOption("d", "debug", false, "switch on DEBUG log level"); 
     CommandLineParser parser = new PosixParser(); 
     CommandLine cmd = null; 
     try { 
     cmd = parser.parse(options, args); 
     } catch (Exception e) { 
     System.err.println("ERROR: " + e.getMessage() + "\n"); 
     HelpFormatter formatter = new HelpFormatter(); 
     formatter.printHelp(NAME + " ", options, true); 
     System.exit(-1); 
     } 
     return cmd; 
    } 

    public static void main(String[] args) throws Exception { 
     Configuration conf = HBaseConfiguration.create(); 
     String[] otherArgs = 
     new GenericOptionsParser(conf, args).getRemainingArgs(); 
     CommandLine cmd = parseArgs(otherArgs); 
     String table = cmd.getOptionValue("t"); 
     String input = cmd.getOptionValue("i"); 
     String column = cmd.getOptionValue("c"); 
     conf.set("conf.column", column); 
     Job job = new Job(conf, "Import from file " + input + " into table " + table); 

      job.setJarByClass(ImportFromFile.class); 
     job.setMapperClass(ImportMapper.class); 
     job.setOutputFormatClass(TableOutputFormat.class); 
     job.getConfiguration().set(TableOutputFormat.OUTPUT_TABLE, table); 
     job.setOutputKeyClass(ImmutableBytesWritable.class); 
     job.setOutputValueClass(Writable.class); 
     job.setNumReduceTasks(0); 
     FileInputFormat.addInputPath(job, new Path(input)); 
     System.exit(job.waitForCompletion(true) ? 0 : 1); 
    } 
    }` 
+1

मुझे निम्नलिखित मिल रहा है: 'कंटेनर-लॉन्च से अपवाद: org.apache.hadoop.util.Shell $ ExitCodeException' क्या आप उपरोक्त कोड के साथ-साथ इस समस्या में भी भाग गए थे? मैं Hadoop2.4 और Hbase0.94.18 का उपयोग कर रहा हूँ – Gevorg

संबंधित मुद्दे