Databases Reference
In-Depth Information
The table itself is named historical_daily_stock_price . To get the row data for NYSE, AA,
2008-02-27, you can query as follows:
get 'historical_daily_stock_price', 'NYSEAA20080227'
You can get the open price as follows:
get 'historical_daily_stock_price', 'NYSEAA20080227', 'price:open'
You could also use a programming language to query for the data. A sample Java program to get the
open and high price data could be as follows:
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.io.RowResult;
import java.util.HashMap;
import java.util.Map;
import java.io.IOException;
public class HBaseConnector {
public static Map retrievePriceData(String rowKey) throws IOException {
HTable table = new HTable(new HBaseConfiguration(),
“historical_daily_stock_price”);
Map stockData = new HashMap();
RowResult result = table.getRow(rowKey);
for (byte[] column : result.keySet()) {
stockData.put(new String(column), new
String(result.get(column).getValue()));
}
return stockData;
}
public static void main(String[] args) throws IOException {
Map stock_data = HBaseConnector.retrievePriceData(“NYSEAA20080227”);
System.out.println(stock_data.get(“price:open”));
System.out.println(stock_data.get(“price:high”));
}
}
HBaseConnector.java
HBase includes very few advanced querying techniques beyond what is illustrated, but its capability
to index and query can be extended with the help of Lucene and Hive. Details of using Hive with
HBase is illustrated in Chapter 12.
Search WWH ::




Custom Search