Playing with HBase (part 2)

I used Pig to load data into hbase. # Download and extract pig # Download population data of India's villages from http://www.censusindia.gov.in/2011census/A-3_Vill/A-3%20MDDS_Release.xls # Use Libreoffice to convert the .xls to a .csv # Create a table called villages with a column family called population in HBase hbase> create 'villages', 'population' bash> export PIG_CLASSPATH=$PIG_/home/vagrant/hbase-0.94.18/hbase-0.94.18.jar:/home/vagrant/hbase-0.94.18/lib/*:pig-0.12.0-withouthadoop.jar:/home/hduser/hadoop/lib/*:$PIG_CLASSPATH # Load the csv file in Pig grunt> A = load 'file:///vagrant/village-population.csv' using PigStorage(','); # Compute (Name of village, Level of village in hierarchy) grunt> B = foreach A generate $4, $3; # Clean up data grunt> C = filter B $0 != '' and $1 != ''; # Save to HBase using name of the village as key and the level as value into population:level column grunt> store C into 'hbase://villages' using org.apache.pig.backend.hadoop.hbase.HBaseStorage('population:level'); # Compute (Name of village, Number of persons in village) grunt> B = foreach A generate $4, $6; # Clean up data grunt> C = filter B BY $0 != '' and $1 != ''; # Save to HBase using name of village as key and the number of persons as the value into population:persons column grunt> store C into 'hbase://villages' using org.apache.pig.backend.hadoop.hbase.HBaseStorage('population:persons'); # Get all the data hbase> scan 'villages' ROW COLUMN+CELL 'N' Thingdawl column=population:level, timestamp=1396879365983, value=SUB-DISTRICT 'N' Thingdawl column=population:persons, timestamp=139687960225 8, value=12108 ... Zunheboto Sadar column=population:level, timestamp=1396879365963, value=SUB-DISTRICT Zunheboto Sadar column=population:persons, timestamp=139687960225 6, value=13344 # Get all states, districts, sub-districts which # have a rural population of 10000 exactly :) hbase> import org.apache.hadoop.hbase.filter.CompareFilter hbase> import org.apache.hadoop.hbase.filter.SingleColumnValueFilter hbase> import org.apache.hadoop.hbase.filter.SubstringComparator hbase> import org.apache.hadoop.hbase.util.Bytes # EQUAL works. But any other kind of numeric # compare does not work. hbase> scan 'villages', {LIMIT => 10, FILTER => SingleColumnValueFilter.new(Bytes.toBytes('population'), Bytes.toBytes('persons'), CompareFilter::CompareOp.valueOf('EQUAL'), Bytes.toBytes('10000')), COLUMNS => 'population:persons' } I tried a simple numeric comparison and fought long and hard to get it right but it seems nigh impossible for today. My brain is also shutting down. Documentation seems really sparse. This link was the one ray of hope in the dark expanse of the internet. In terms of filters hbase is probably really immature and documentation is worse. Getting a few values can’t be this hard. A SQL layer on top of hbase seems necessary. The hbase shell syntax is too much of a pain and is too idiosyncratic.

April 7, 2014 · 2 min · Bharath

Playing with HBase

Below are the steps I followed to get HBase up and running. # Download and extract hbase-0.94.18 into /home/vagrant/hbase-0.94.18 # Edit hbase-0.94.18/conf/hbase-site.xml to save data in /home/vagrant/hbase <configuration> <property> <name>hbase.rootdir</name> <value>/home/vagrant/hbase/hbase</value> </property> <property> <name>hbase.zookeeper.property.dataDir</name> <value>/home/vagrant/hbase/zookeeper</value> </property> </configuration> # Edit hadoop-metrics.properties for monitoring with ganglia dfs.class=org.apache.hadoop.metrics.ganglia.GangliaContext31 dfs.period=10 dfs.servers=239.2.11.71:8649 mapred.class=org.apache.hadoop.metrics.ganglia.GangliaContext31 mapred.period=10 mapred.servers=239.2.11.71:8649 jvm.class=org.apache.hadoop.metrics.ganglia.GangliaContext31 jvm.period=10 jvm.servers=239.2.11.71:8649 rpc.class=org.apache.hadoop.metrics.ganglia.GangliaContext31 rpc.period=10 rpc.servers=239.2.11.71:8649 # Add a column and some data hbase> create 'test', 'columnfamily' hbase> put 'test', 'rowkey1', 'columnfamily:column1', 'value1' hbase> put 'test', 'rowkey1', 'columnfamily:column2', 'value2' hbase> put 'test', 'rowkey2', 'columnfamily:column1', 'value3' hbase> put 'test', 'rowkey2', 'columnfamily:column2', 'value4' hbase> scan 'test' # Try out HBase-on-HDFS. HDFS is running locally listening on IP 10.0.2.15 <configuration> <property> <name>hbase.rootdir</name> <value>hdfs://10.0.2.15/user/hduser/hbase/hbase</value> </property> <property> <name>hbase.zookeeper.property.dataDir</name> <value>hdfs://10.0.2.15/user/hduser/hbase/zookeeper</value> </property> </configuration>

April 7, 2014 · 1 min · Bharath