Is there any way to limit the number of columns in

2019-09-05 23:07发布

Is there any way to limit the number of columns under a particular row in Hbase? I have seen methods to limit rows. I wonder if there is any ways i can limit column family values

Like,

row      columnfamily(page)      value
1          page:1                         1
1          page:2                         2
1          page:3                         3

I need to retrieve row1 values for column families page:1 and page:2
Is it possible?

2条回答
虎瘦雄心在
2楼-- · 2019-09-05 23:08

It is possible.

When scan-ning use http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/client/Scan.html#addColumn(byte[], byte[])

When get-ting use http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/client/Get.html#addColumn(byte[], byte[])

If the column key is predictable, for example, key is an index, then based on a particular value the keys could be added by iterating. Besides you could use filters as well if the conditioning could be random and complicated for example > 1 and < 3, key in (3, 10, 11) etc. For filter use this. There are host of pre-implemented filters. You would probably be interested in the qualifier filter.

Hope this helps.

查看更多
Fickle 薄情
3楼-- · 2019-09-05 23:17

There are a number of different ways that you can go with this problem. Basically, you want a server-side filter to limit your return data in a Get/Scan. Normally, this would be done with a co-processor, but that is still under development, so you really want to apply a filter to your query.

Example Filters: http://svn.apache.org/repos/asf/hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/filter/

The easiest example would be a prefix filter (although it looks like you want some sort of range filter). Just to give you a rough idea of how this would work, here's how you apply a PrefixFilter to a Get:

HTable myTable; // predefined
Scan scan; // predefined
scan.setFilter(new ColumnPrefixFilter(Bytes.toBytes("myprefix")));
return myTable.getScanner(scan);
查看更多
登录 后发表回答