mapreduce - 如何使用MapReduce查询HBase数据?

标签 mapreduce hbase

您好,我是 MapReduce 和 HBase 的新手。请指导。我正在使用 MapReduce 将表格数据移动到 HBase。现在数据已到达 HBase 中(HDFS 中也是如此)。我创建了 mapreduce 作业,它将从文件中读取表格数据并使用 HBase API 将其放入 Hbase 中。

现在我的疑问是我可以使用MapReduce查询HBase数据吗?我不想执行 HBase 命令来查询数据。是否可以使用MapReduce查询HBase的数据?

请提供帮助或建议。

最佳答案

当然可以,HBase 附带 TableMapReduceUtil帮助您配置用于扫描数据的 MapReduce 作业。它会自动为每个区域创建一个 map task 。

请检查此示例 extracted from the HBase book :

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

Scan scan = new Scan();
scan.setCaching(500);        // 1 is the default in Scan, which will be bad for MapReduce jobs
scan.setCacheBlocks(false);  // don't set to true for MR jobs
// set other scan attrs
...

TableMapReduceUtil.initTableMapperJob(
  tableName,        // input HBase table name
  scan,             // Scan instance to control CF and attribute selection
  MyMapper.class,   // mapper
  null,             // mapper output key
  null,             // mapper output value
  job);
job.setOutputFormatClass(NullOutputFormat.class);   // because we aren't emitting anything from mapper

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

<强> MORE EXAMPLES HERE

关于mapreduce - 如何使用MapReduce查询HBase数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21379465/

相关文章:

javascript - 在 Mongo 中重新加入拆分 MapReduce 数组

hadoop - "INFO : Tez session hasn' t 尚未创建。开场“挂

hadoop - Phoenix-> csv->封装的 token 和定界符之间的无效字符

java - 将base64编码的字符串存储在HBase中

mongodb - 组结果 mongoDB

hadoop - Hdfs 文件行数

java - HBase Java Client批处理/放入CDH 4.6的速度很慢

hadoop - 在 HDP 集群上安装 Snappy

javascript - MongoDB 计算对象内的对象

java - 如何更新 HBase 中的现有列值