Metadata
Metadata

Reputation: 2085

How to retrieve the records based on a condition from a Hbase table?

I have a Hbase table: employeedetails with column families:cols-personaldetails: firstname, lastname, professionaldetails: cols-company, empid and it has the following data in it.

 1    column=personaldetails:firstname, timestamp=1490959927100, value=Steven
 1    column=personaldetails:lastname, timestamp=1490959947478, value=Gerrard
 1    column=professionaldetails:company, timestamp=1490959968846, value=ABC
 1    column=professionaldetails:empid, timestamp=1490959978542, value=02429O
 2    column=personaldetails:firstname, timestamp=1490960007427, value=Sidhartha
 2    column=personaldetails:lastname, timestamp=1490960054615, value=Bobby
 2    column=professionaldetails:company, timestamp=1490960074243, value=DEF
 2    column=professionaldetails:empid, timestamp=1490960103882, value=02429N
 3    column=personaldetails:company, timestamp=1490960175772, value=WES
 3    column=personaldetails:empid, timestamp=1490960187863, value=987789
 3    column=personaldetails:firstname, timestamp=1490960128896, value=Sunny
 3    column=personaldetails:lastname, timestamp=1490960142031, value=Smith

Is there a way to write a command to retrieve the records whose first name starts with 'S'.

Upvotes: 2

Views: 1677

Answers (2)

franklinsijo
franklinsijo

Reputation: 18270

Use SingleColumnValueFilter

This filter takes a column family, a qualifier, a compare operator and a comparator as arguments.

  1. If the specified column is not found, all the columns of that row will be emitted.
  2. If the column is found and the comparison with the comparator returns true, all the columns of the row will be emitted.
  3. If the column is found and the comparison with the comparator returns false, the row will not be emitted.

Syntax:

SingleColumnValueFilter (‘<family>’, ‘<qualifier>’, <compare operator>, ‘<comparator>’, <filterIfColumnMissing_boolean>, <latest_version_boolean>)

Try:

scan 'employeedetails' ,{ FILTER => "SingleColumnValueFilter('personaldetails','firstname',=, 'binaryprefix:S', true, false)" }

If the filterIfColumnMissing flag is set to true, the columns of the row will not be emitted if the specified column to check is not found in the row.

Let me know if this retrieves expected results.

Upvotes: 4

Kiran Krishna Innamuri
Kiran Krishna Innamuri

Reputation: 1002

The best thing you can do is that you can create an external table in Hive with the same schema mapping to the HBase table and you can run hive queries on the top of the HBase table.

You can use conditions in the Hive queries which runs on the top of the HBase table data.

You can refer to this blog for integrating hive with HBase and running Hive queries on the top of HBase table.

Upvotes: 0

Related Questions