从HBase读取数据 [英] Read Data from HBase
本文介绍了从HBase读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是HBase的新手,从表格中逐行检索结果的最佳方法是什么?我想读取表格中的全部数据。我的桌子有两列家庭说col1和col2。
解决方案
我正在寻找类似的东西!
$ b Map函数
public void map(ImmutableBytesWritable row,Result value,Context context)throws InterruptedException,IOException { b
$ b String x1 = new String(value.getValue(Bytes.toBytes(ColumnFamily),Bytes.toBytes(X1)));
String x2 = new String(value.getValue(Bytes.toBytes(ColumnFamily),Bytes.toBytes(X2)));
$ b}
驱动程序文件:
$ b
配置config2 = new Configuration();
Job job2 = new Job(config1,kmeans2);
//配置job2
job2.setJarByClass(Converge.class);
job2.setMapperClass(Converge.Map.class);
job2.setReducerClass(Converge.Reduce.class);
job2.setInputFormatClass(TableInputFormat.class);
job2.setOutputFormatClass(NullOutputFormat.class);
job2.setOutputKeyClass(Text.class);
job2.setOutputValueClass(Text.class);
job2.getConfiguration()。set(TableInputFormat.INPUT_TABLE,tablename);
I'm new to HBase, what's the best way to retrieve results from a table, row by row? I would like to read the entire data in the table. My table has two column families say col1 and col2.
解决方案
I was looking for something like this!
Map function
public void map(ImmutableBytesWritable row, Result value, Context context) throws InterruptedException, IOException {
String x1 = new String(value.getValue(Bytes.toBytes("ColumnFamily"), Bytes.toBytes("X1")));
String x2 = new String(value.getValue(Bytes.toBytes("ColumnFamily"), Bytes.toBytes("X2")));
}
Driver file:
Configuration config2 = new Configuration();
Job job2 = new Job(config1, "kmeans2");
//Configuration for job2
job2.setJarByClass(Converge.class);
job2.setMapperClass(Converge.Map.class);
job2.setReducerClass(Converge.Reduce.class);
job2.setInputFormatClass(TableInputFormat.class);
job2.setOutputFormatClass(NullOutputFormat.class);
job2.setOutputKeyClass(Text.class);
job2.setOutputValueClass(Text.class);
job2.getConfiguration().set(TableInputFormat.INPUT_TABLE, "tablename");
这篇关于从HBase读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文