get command and get() method of HTable class are used to read data from a table in HBase. Using get command, you can get a single row of data at a time. Below is the syntax:
Below example shows how to use the get command. Let’s scan the first row of the emp table.
Below is the syntax to read a specific column using the get method.
Below is the example to read a specific column in HBase table.
get() method of the HTable class can be used to read data from an HBase table. This method requires an instance of the Get class. Follow the steps given below to retrieve data from the HBase table.
Configuration class adds HBase configuration files to its object. Configuration object can be created using create() method of HbaseConfiguration class as shown below.
There is a class called HTable, an implementation of Table in HBase. This class is used for comunicating with a single HBase table. While instantiating this class, it accepts the configuration object and the table name as parameters. HTable class can be instantiates as shown below.
get() method of the HTable class can be used to retrieve data from the HBase table. This method extracts a cell from a given row. It requires a Get class object as parameter. Create it as shown below.
While retrieving data, you can get a single row by id, or get a set of rows by a set of row ids, or scan an entire table or a subset of rows.
HBase table data can be retrieved using add method variants in Get class.
To get a specific column from a specific column family, use below method.
To get all the columns from a specific column family, use below method.
Get the result by passing your Get class instance to the get method of HTable class. This method returns the Result class object, which holds the requested result. Below is the usage of get() method.
Result class provides the getValue() method for reading the values from its instance. Use it as shown below to read the values from the Result instance.
Below is the complete program to read values from an HBase table.
Compile and execute the above program as shown below.
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.