HBase를 처음 사용했습니다. HBase의 셀에 여러 버전을 저장하려고하지만 마지막으로 저장된 값만 가져옵니다.HBase 셀에 여러 버전 저장하기
: 0.0150 초 입력 파일은 다음과 같다에서ROW COLUMN+CELL
abc column=backward:first, timestamp=1422722312845, value=rrb
1 행을 다음과 같이 두 가지 출력을 반환 get 'Dummy1','abc', {COLUMN=>'backward:first', VERSIONS=>12}
및 scan 'Dummy1', {VERSIONS=>12}
: 여러 개의 저장 버전을 검색하려면 다음 두 명령을 시도
abc xyz kkk
abc qwe asd
abc anf rrb
는 는 HBase를 표 생성을위한 코드는 다음과 같이된다
:
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HBaseAdmin;
public class HBaseTableCreator {
public static void main(String[] args) throws Exception {
HBaseConfiguration conf = new HBaseConfiguration();
conf.set("hbase.master","localhost:60000");
HBaseAdmin hbase = new HBaseAdmin(conf);
HTableDescriptor desc = new HTableDescriptor("Dummy");
HColumnDescriptor meta = new HColumnDescriptor("backward".getBytes());
meta.setMaxVersions(Integer.MAX_VALUE);
HColumnDescriptor prefix = new HColumnDescriptor("forward".getBytes());
prefix.setMaxVersions(Integer.MAX_VALUE);
desc.addFamily(meta);
desc.addFamily(prefix);
hbase.createTable(desc);
}
}
,
HBase에서 데이터를 덤프하는 코드는 다음과 같습니다. 주 클래스 : import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;
public class TestMain {
public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException
{
// TODO Auto-generated method stub
Configuration conf=new Configuration();
//HTable hTable = new HTable(conf, args[3]);
String[] otherArgs=new GenericOptionsParser(conf,args).getRemainingArgs();
if(otherArgs.length!=2)
{
System.err.println("Usage: wordcount <in> <out>");
System.exit(2);
}
Job job=new Job(conf,"HBase dummy dump");
job.setJarByClass(TestMain.class);
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
job.setMapperClass(TestMapper.class);
TableMapReduceUtil.initTableReducerJob("Dummy", null, job);
//job.setOutputKeyClass(NullWritable.class);
//job.setOutputValueClass(Text.class);
job.setNumReduceTasks(0);
//job.setOutputKeyClass(Text.class);
//job.setOutputValueClass(Text.class);
FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
//HFileOutputFormat.configureIncrementalLoad(job, hTable);
System.exit(job.waitForCompletion(true)?0:1);
}
}
매퍼 클래스 :
import java.io.IOException;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.Mapper;
public class TestMapper extends Mapper <LongWritable, Text, Text, Put>{
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String line=value.toString();
String[] l=line.split("\\s+");
for(int i=1;i<l.length;i++)
{
Put HPut = new Put(l[0].getBytes());
HPut.add("backward".getBytes(),"first".getBytes(),l[i].getBytes());
context.write(new Text(l[0]),HPut);
}
}
}
내가 잘못거야 곳 알려주세요.
테이블에 데이터를 넣으려면 HBase 셸을 사용하고 있습니다. 하지만 버전을 구할 수는 없습니다. 나는 최신 가치만을 얻는다. 버전 저장을 "켜기"로 전환 할 수있는 HBase 시스템 구성이나 테이블/열 특정 설정이 있습니까? –