首页 > 解决方案 > HBase 多个 PrefixFilters + setLimit

问题描述

我有一个行前缀列表。我想为每个前缀查询 N 行。

我不能使用 MultiRowRangeFilter 因为我不知道该范围的结尾行键前缀是什么。我也不能使用 scan.setLimit(N) 因为我认为它会将查询的总行数限制为 N (我想要的是每个前缀都有 N 行)。

我目前的设置:

val hbaseConf = HBaseConfiguration.create()
// set zookeeper quorum properties in hbaseConf

val hbaseContext = new HBaseContext(sc, hbaseConf)

val rowPrefixes = Array("a", "b", "c")
val filterList = new FilterList()

rowPrefixes.foreach { x => filterList.addFilter(new PrefixFilter(Bytes.toBytes(x))) }

var scan = new Scan()  

scan.setFilter(filterList)
scan.addFamily(Bytes.toBytes("myCF"));

val rdd = hbaseContext.hbaseRDD(TableName.valueOf("tableName"), scan)
rdd.mapPartitions(populateCaseClass)

我不确定我应该使用哪个过滤器来实现这个多个行键前缀 + 每个行键的 setLimit ...

标签: scalaapache-sparkhadoophbasecloudera-cdh

解决方案


推荐阅读