2013-07-26 2 views
1

HBase 테이블에 4 억 개의 행을 삽입해야합니다.MapReduce를 사용하여 HBase에 대량 데이터 삽입

스키마 보이는

내 매퍼이

public class DatasetMapper extends Tablemapper <Text,LongWritable> { 


    private static Configuration conf = HBaseConfiguration.create(); 


public void map (Text key, LongWritable values, Context context) throws exception { 

    // instantiate HTable object that connects to table name 
    HTable htable = new HTable(conf,"temp") // already created temp table 
    htable.setAutoFlush(flase); 
    htable.setWriteBufferSize(1024*1024*12); 

    // construct key 
    int i = 0, j = 0; 
    for(i=0; i<400000000,i++) { 
     String rowkey = Integer.toString(i).concat(Integer.toString(j)); 
     Long value = Math.abs(System.nanoTime()); 
     Put put = new Put(Bytes.toBytes(rowkey)); 
      put.add(Bytes.toBytes("location"),Bytes.toBytes("longlat"),Bytes.toBytes(value); 
     htable.put(put) 
     j++; 
     htable.flushCommits(); 
} 
} 

과 같이 보입니다 단순히 INT 연결하여 키를 생성하고 System.nanoTime()로 int 형과 값하고이

같은 내 직업은 이렇게 보입니다.

Configuration config = HBaseConfiguration.create(); 
Job job = new Job(config,"initdb"); 
job.setJarByClass(DatasetMapper.class); // class that contains mapper 

TableMapReduceUtil.initTableMapperJob(
null,  // input table 
null,    
DatabaseMapper.class, // mapper class 
null,    // mapper output key 
null,    // mapper output value 
job); 
TableMapReduceUtil.initTableReducerJob(
temp,  // output table 
null,    // reducer class 
job); 
job.setNumReduceTasks(0); 

boolean b = job.waitForCompletion(true); 
if (!b) { 
throw new IOException("error with job!"); 
} 

작업은 실행되지만 nserts 0 레코드. 내가 실수를하고 있다는 것을 알고 있지만 HBase를 처음 접했을 때 나는 그것을 잡을 수 없다. 도와주세요.

감사

답변

3

것부터 먼저, 당신의 매퍼의 이름은 는 DatasetMapper하지만 당신의 작업 설정에서 당신은 DatabaseMapper을 지정했습니다. 어떤 오류없이 작동하는지 궁금합니다.

다음으로 TableMapper와 Mapper 사용법을 혼합 한 것 같습니다. Hbase TableMapper는 Hadoop Mapper를 확장하고 HBase에서 편리하게 읽을 수있게 해주는 추상 클래스이며 TableReducer는 HBase에 다시 쓰는 데 도움이됩니다. Mapper에서 데이터를 가져 오려고하고 있으며 동시에 TableReducer를 사용하고 있습니다. 당신 매퍼는 실제로 절대로 불리지 않을 것입니다.

TableReducer를 사용하여 데이터를 저장하거나 매퍼 만 사용하십시오. Mapper에서 실제로 수행하려는 경우 TableOutputFormat 클래스를 사용할 수 있습니다. HBase Definitive Guide의 301 페이지에있는 예를보십시오. 이것은 Google Books link

HTH

P.S.입니다 : 당신은 제대로 HBase를 + MR 통합 학습에이 링크가 도움이 될 수 :

Link 1.

Link 2.

+0

안녕 타리크 덕분에 나를 위해하고 유용한 링크에 대한 것을 지적. 내가 본 모든 사례는 HBase를 소스 및 싱크로 사용하며 혼란스러워졌습니다. 그것을 당신의 방식대로 해 드리겠습니다. 결과를 올바른 코드로 게시 할 것입니다. –

+0

안녕하십니까? @ Shashank.Kr. 확실한. – Tariq