【问题标题】:How to query HBase data using MapReduce?如何使用 MapReduce 查询 HBase 数据?
【发布时间】:2014-01-27 20:59:41
【问题描述】:

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

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

请帮助或建议。

【问题讨论】:

    标签: mapreduce hbase


    【解决方案1】:

    当然可以,HBase 附带一个TableMapReduceUtil 来帮助您配置 MapReduce 作业以扫描数据。它会自动为每个区域创建一个地图任务。

    请查看此示例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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多