简体   繁体   中英

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

New to Hbase, don't have hive or impala configured. :-( 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.

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

Your requirement is to get rows which meet the two column qualifiers ab & ad conditions

The way for this implementation is to go with 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']}

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.

 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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