简体   繁体   English

HBase Shell:如何根据特定的多列值扫描行

[英]Hbase shell: how to scan rows based on specific multiple column values

New to Hbase, don't have hive or impala configured. Hbase的新功能,没有配置蜂巢或黑斑羚。 :-( Now wanted to scan rows of a table based on multiple column values let say having Table A with 4 columns aa, ab, ac, ad. I wanted all rows of the table which satisfied the values condition of column ab & ad. :-(现在想基于多个列值扫描表的行,比如说让表A具有4列aa,ab,ac,ad。我想要表中所有满足ab和ad列的值条件的行。

And other query is how to query on multiple tables assuming have external key are presents in the tables. 其他查询是假设表中存在外部键的情况下如何查询多个表。

Just to reiterate your scenarios: One HBase table named A , One Column Family CF1 and within it there are four column qualifiers ie aa, ab, ac, ad 重申一下您的情况:一个名为A的 HBase表,一个列系列CF1 ,其中有四个列限定符,即aa,ab,ac,ad

Your requirement is to get rows which meet the two column qualifiers ab & ad conditions 您的要求是获取符合两个列限定符ab和ad条件的行

The way for this implementation is to go with SingleColumnValueFilter. 此实现的方法是使用SingleColumnValueFilter。 Create filter list, as many as you want (two filter list in your case) And add filters in the dependent order 创建所需数量的过滤器列表(您的情况下有两个过滤器列表),并按从属顺序添加过滤器

If you have two different column families (A & B), then Scan 'A' , {COLUMNS => ['A:aa' , 'B:ab']} 如果您有两个不同的列族(A和B),则扫描'A',{COLUMNS => ['A:aa','B:ab']}

In your second question, what do you mean by external key? 在第二个问题中,外键是什么意思? If you are referring to a unique composite key identifier then explore secondary Index. 如果您指的是唯一的组合键标识符,请浏览二级索引。

For scanning rows on multiple columns in single hbase table you can use Hbase Api and the following java code might solve your problem. 要在单个hbase表中扫描多列上的行,可以使用Hbase Api,以下Java代码可能会解决您的问题。

 SingleColumnValueFilter f1 = new SingleColumnValueFilter(Bytes.toBytes("0"), Bytes.toBytes("EMP_KEY"), CompareFilter.CompareOp.LESS_OR_EQUAL, Bytes.toBytes(500));
  SingleColumnValueFilter f2 = new SingleColumnValueFilter(Bytes.toBytes("0"), Bytes.toBytes("DEPT_KEY"), CompareFilter.CompareOp.EQUAL, Bytes.toBytes(204));

  FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL); //could be FilterList.Operator.MUST_PASS_ALL instead
  filterList.addFilter(f1);
  filterList.addFilter(f2);

  Scan scan = new Scan();
  scan.setFilter(filterList);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM