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를 처음 접했을 때 나는 그것을 잡을 수 없다. 도와주세요.
감사
안녕 타리크 덕분에 나를 위해하고 유용한 링크에 대한 것을 지적. 내가 본 모든 사례는 HBase를 소스 및 싱크로 사용하며 혼란스러워졌습니다. 그것을 당신의 방식대로 해 드리겠습니다. 결과를 올바른 코드로 게시 할 것입니다. –
안녕하십니까? @ Shashank.Kr. 확실한. – Tariq