繁体   English   中英

从 HBase 读取数据

[英]Read Data from HBase

我是 HBase 的新手,从表中逐行检索结果的最佳方法是什么? 我想读取表中的全部数据。 我的表有两个列族,比如 col1 和 col2。

在 Hbase shell 中,您可以使用scan命令列出表中的数据,或获取检索记录。 参考这里

我认为这是您需要的:通过 HBase shell 和 Java API: http : //cook.coredump.me/post/19672191046/hbase-client-example

但是你应该明白 hbase shell 'scan' 非常慢(它没有被缓存)。 但它仅用于调试目的。

另一个对您有用的信息部分在这里: http : //hbase.apache.org/book/perf.reading.html本章关于从 HBase 阅读是正确的,但有点难以理解,因为它假定了一定程度的熟悉和包含更高级的建议。 我会从头开始向您推荐本指南。

使用Hbase的Scan api,可以指定开始行和结束行,并可以从表中检索数据。

下面是一个例子:

http://eternaltechnology.blogspot.in/2013/05/hbase-scanner-example-scanning.html

我正在寻找这样的东西!

地图功能

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")));


}

驱动文件:

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");                   

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM