2012-09-03 13 views
5

पर टेक्स्ट फ़ाइल को पढ़ने के लिए मुझे टेक्स्ट फ़ाइल से डेटा को कम करने की आवश्यकता है, मैं कई दिनों से गोगलिंग कर रहा हूं लेकिन मुझे अपने काम के लिए कोई सही समाधान नहीं मिला। क्या कोई विधि या कक्षा है जो किसी सिस्टम से टेक्स्ट/सीएसवी फ़ाइल पढ़ती है और डेटा को एचबीएएसई तालिका में संग्रहीत करती है। यह वास्तव में मेरे लिए बहुत जरूरी है कृपया कोई भी MapReduce F/w को जानने में मेरी सहायता कर सकता है।सिस्टम से Hbase MapReduce

उत्तर

2

टेक्स्ट फ़ाइल से पढ़ने के लिए सभी टेक्स्ट फ़ाइल में से पहले hdfs में होना चाहिए। आप नौकरी के लिए इनपुट प्रारूप और outputformat निर्दिष्ट करने की आवश्यकता

Job job = new Job(conf, "example"); 
FileInputFormat.addInputPath(job, new Path("PATH to text file")); 
job.setInputFormatClass(TextInputFormat.class); 
job.setMapperClass(YourMapper.class); 
job.setMapOutputKeyClass(Text.class); 
job.setMapOutputValueClass(Text.class); 
TableMapReduceUtil.initTableReducerJob("hbase_table_name", YourReducer.class, job); 
job.waitForCompletion(true); 

YourReducer चाहिए फैली org.apache.hadoop.hbase.mapreduce.TableReducer<Text, Text, Text>

नमूना कम करने कोड

public class YourReducer extends TableReducer<Text, Text, Text> {  
private byte[] rawUpdateColumnFamily = Bytes.toBytes("colName"); 
/** 
* Called once at the beginning of the task. 
*/ 
@Override 
protected void setup(Context context) throws IOException, InterruptedException { 
// something that need to be done at start of reducer 
} 

@Override 
public void reduce(Text keyin, Iterable<Text> values, Context context) throws IOException, InterruptedException { 
// aggregate counts 
int valuesCount = 0; 
for (Text val : values) { 
    valuesCount += 1; 
    // put date in table 
    Put put = new Put(keyin.toString().getBytes()); 
    long explicitTimeInMs = new Date().getTime(); 
    put.add(rawUpdateColumnFamily, Bytes.toBytes("colName"), explicitTimeInMs,val.toString().getBytes()); 
    context.write(keyin, put); 


     } 
    } 
} 

नमूना नक्शाकार वर्ग

public static class YourMapper extends Mapper<LongWritable, Text, Text, IntWritable> { 
private final static IntWritable one = new IntWritable(1); 
private Text word = new Text(); 
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { 
    String line = value.toString(); 
    StringTokenizer tokenizer = new StringTokenizer(line); 
    while (tokenizer.hasMoreTokens()) { 
     word.set(tokenizer.nextToken()); 
     context.write(word, one); 
     } 
    } 
}