1 / 7

Homework 3 ( 上交时间: 12 月 12 号 )

Homework 3 ( 上交时间: 12 月 12 号 ). 使用 MapReduce 构建 Hbase 索引. 背景介绍. Hbase 中的表根据行健被分成了多个 Regions ,通常一个 Region 的一行会包含较多的数据,如果以列值作为查询条件,就只能从第一行开始往下查找。这显然很低效。相反,如果将经常被查询的列作为行健,行健作为列重新构造一张表,既可以实现根据列值快速的定位相关数据所在的行。因为 Hbase 的表中,行健是以 B-Tree 的形式组织的,所以即使列值较多的时候,也能较快的查询到相关的行健。这就是索引。 下 图给出了索引表的示例.

odina
Download Presentation

Homework 3 ( 上交时间: 12 月 12 号 )

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Homework 3(上交时间:12月12号) 使用MapReduce构建Hbase索引

  2. 背景介绍 • Hbase中的表根据行健被分成了多个Regions,通常一个Region的一行会包含较多的数据,如果以列值作为查询条件,就只能从第一行开始往下查找。这显然很低效。相反,如果将经常被查询的列作为行健,行健作为列重新构造一张表,既可以实现根据列值快速的定位相关数据所在的行。因为Hbase的表中,行健是以B-Tree的形式组织的,所以即使列值较多的时候,也能较快的查询到相关的行健。这就是索引。 • 下图给出了索引表的示例

  3. 索引表示例 (原始表)

  4. 索引表示例(索引表)

  5. 实现过程 • InpuFormat类。Hbase实现了TableInputFormatBase类,该类提供了对表数据大部分操作,其子类TableInputFormat则提供了完整的实现。TableInputFormat类将数据按照Region分割成split,即有多少个Regions就有多少个splits。然后将Region按行键分成<key, value>形式,key对应行键,value为改行所包含的数据。 • Mapper类。Hbase实现了TableMapper类和TableReducer类,其中TableMapper类并没有实现具体的功能只是将输入的<key, value>对的类型限定为ImmutableBytesWritable和Result。 • OutPutFormat类。Hbase实现的TableOutputFormat将输出的<key, value>对写到指定的Hbase表中。

  6. 实现过程 • 利用TableInputFormat类从Hbase表中提取数据。 • 在Map中,对每一行的数据提取出需要建立索引的列的值,加入到索引表中输出。 • 本实验不用Reduce函数

  7. 实现过程 • 程序Map大致框架 map(ImutableBytesWritablerowKey, Result result, Context contex) { for (对于每个需要建立索引的列) //列用 列簇:标示符 表示 { byte[] value = result.getValue(family, qualifier); //插入索引表中,这里value作为行键 Put put = new Put(value);//加入一行 //然后在索引表的指定列中插入rowKey put.add(index_col, index_qualifer, rowKey.get()) //最后输出, tableName为索引表名 context.write(tableName, put); } }

More Related