Database Reference
In-Depth Information
The following is a complete example of how to read data to HBase:
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
public class SingleGetEx {
public static void main(String[] args) throws IOException {
// Get instance of Default Configuration
Configuration conf = HBaseConfiguration.create();
// Get table instance
HTable table = new HTable(conf, "tab1");
// Create Get with rowkey
Get get = new Get(Bytes.toBytes("row-1"));
// Add a column with value "Hello", in "cf1:greet", to the // Put.
get.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("greet"));
Result result = table.get(get);
byte[] val = result.getValue(Bytes.toBytes("cf1"),
Bytes.toBytes("greet"));
System.out.println("Cell Value: " + Bytes.toString(val));
table.close();
}
}
Data reading in HBase can take place for a single row or in the form of a batch
representing multiple rows using the following method of the HTable class:
Results[] get(List<Get> gets)
Here, List can be deined as follows:
List<Get> gets = new ArrayList<Get>();
Get get1 = new Get(Bytes.toBytes("row-1"));
get1.add(Bytes.toBytes("cf1"), Bytes.toBytes("greet"));
gets.add(get1);
 
Search WWH ::




Custom Search