12

I am using

 scan 'table_name', { COLUMNS => 'column_family:column_qualifier', LIMIT => 2 }

to list 2 rows in a hbase table but I would like to know if it is possible to achieve following using hbase shell:

Questions

  1. list all row keys through the hbase shell?
  2. list only those rows, whose row keys have a particular word in it?
slm
  • 15,396
  • 12
  • 109
  • 124
user2360096
  • 133
  • 1
  • 2
  • 6

3 Answers3

39

A1. hbase(main):015:0> count 'table_name', INTERVAL => 1

A2. Use RowKey filter with SubstringComparator.

Usage :

hbase(main):003:0> import org.apache.hadoop.hbase.filter.CompareFilter
hbase(main):005:0> import org.apache.hadoop.hbase.filter.SubstringComparator
hbase(main):006:0> scan 'test', {FILTER => org.apache.hadoop.hbase.filter.RowFilter.new(CompareFilter::CompareOp.valueOf('EQUAL'),SubstringComparator.new("word_by_which_you_want_to_search"))}
Tariq
  • 34,076
  • 8
  • 57
  • 79
  • A1. Works perfect. Thank you! A2. got an error: NameError: uninitialized constant CompareFilter – user2360096 May 31 '13 at 23:07
  • have you imported it?"import org.apache.hadoop.hbase.filter.CompareFilter" – Tariq May 31 '13 at 23:09
  • sorry i didn't import first. This works like a charm. Thank you for your help. Is it possible to list only those rows that have a particular word in a column family and column qualifier? – user2360096 May 31 '13 at 23:38
  • scan 'test', {FILTER => org.apache.hadoop.hbase.filter.QualifierFilter.new(CompareFilter::CompareOp.valueOf('EQUAL'),SubstringComparator.new("substring"))} – Tariq Jun 01 '13 at 00:08
  • 1
    scan 'test', {FILTER => org.apache.hadoop.hbase.filter.FamilyFilter.new(CompareFilter::CompareOp.valueOf('EQUAL'),SubstringComparator.new("substring"))} – Tariq Jun 01 '13 at 00:12
  • If you don't want to import: `scan 'test', {FILTER => org.apache.hadoop.hbase.filter.FamilyFilter.new(org.apache.hadoop.hbase.filter.CompareFilter::CompareOp.valueOf('EQUAL'),org.apache.hadoop.hbase.filter.SubstringComparator.new("substring"))}` – Rag Jan 09 '14 at 00:53
  • @Tariq: I need to further narrow the filter, suppose my column family name is element, qualifier is CountryCode and itz value is "US", so what will be the filter query – Sudip7 Jan 22 '15 at 05:50
  • There's a performance concern for listing all the rowkeys - we can possibly print billions of row keys depending on what's in the table. – neverendingqs Jan 07 '16 at 15:25
4

KeyOnlyFilter - takes no arguments. Returns the key portion of each key-value pair.

Syntax: KeyOnlyFilter ()

Ashwin91
  • 49
  • 1
  • 2
    Just to give an explicit example: scan 'table1', { STARTROW=>"startrow", FILTER => "KeyOnlyFilter()", LIMIT => 10 } – Traveler Apr 12 '17 at 23:38
2

Earlier solution would be:

scan 'test', { 
  COLUMNS => ['col_family_name:col_name'], 
  FILTER => "RowFilter(=, 'substring:the_string_to_be_compared')" 
}
James
  • 4,644
  • 5
  • 37
  • 48
Amit Kumar
  • 21
  • 1
  • 1
    Can you please explain this a bit better? What do you mean by "earlier solution" also? – Will Jul 30 '15 at 22:45
  • I'm going to assume that "easier" was meant (rather than "earlier"). That said, I'm struggling to find documentation on the possibly values given as the 2nd argument to RowFilter besides `substring:`...ah, [here's a bit of help](http://hbase.apache.org/book.html#_comparator). – Tommy Stanton Mar 08 '17 at 01:16
  • does this method retrieve bringing 'rowkey'? – CoolCK Jun 10 '21 at 09:17