{"id":3567,"date":"2014-03-11T15:57:19","date_gmt":"2014-03-11T20:57:19","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=3567"},"modified":"2014-03-11T15:57:19","modified_gmt":"2014-03-11T20:57:19","slug":"query-hbase-from-tomcat","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2014\/03\/11\/query-hbase-from-tomcat\/","title":{"rendered":"Query HBase from Tomcat"},"content":{"rendered":"<p>We installed Tomcat 6.0.39 (we weren&#8217;t running JDK 1.7), as well as hbase.  To get this to work, we copied the following jar&#8217;s from the hadoop and hbase installation directories to the tomcat lib directory.<\/p>\n<pre>\r\n-rw-r--r-- 1 serengeti serengeti 5212641 Mar 11 19:28 hbase-0.94.10.jar\r\n-rw-r--r-- 1 serengeti serengeti 2536366 Mar 11 19:28 hbase-0.94.10-tests.jar\r\n-rw-rw-r-- 1 serengeti serengeti 4203147 Mar 11 19:37 hadoop-core-1.2.1.jar\r\n-rw-r--r-- 1 serengeti serengeti    1521 Mar 11 19:41 hbase-site.xml\r\n-rw-rw-r-- 1 serengeti serengeti   60686 Mar 11 19:48 commons-logging-1.1.1.jar\r\n-rw-rw-r-- 1 serengeti serengeti  261809 Mar 11 19:49 commons-lang-2.4.jar\r\n-rw-rw-r-- 1 serengeti serengeti  298829 Mar 11 19:50 commons-configuration-1.6.jar\r\n-rw-r--r-- 1 serengeti serengeti  779974 Mar 11 19:52 zookeeper-3.4.5.jar\r\n-rw-r--r-- 1 serengeti serengeti   15345 Mar 11 19:53 slf4j-api-1.4.3.jar\r\n-rw-r--r-- 1 serengeti serengeti    8601 Mar 11 19:54 slf4j-log4j12-1.4.3.jar\r\n-rw-r--r-- 1 serengeti serengeti  481535 Mar 11 19:54 log4j-1.2.16.jar\r\n-rw-r--r-- 1 serengeti serengeti  449818 Mar 11 19:55 protobuf-java-2.4.0a.jar\r\n<\/pre>\n<p>We also copied the hbase-site.xml file from the hbase installation into the tomcat lib directory.<\/p>\n<p>We then create our table in HBase&#8230;<\/p>\n<pre lang=\"text\">\r\nhbase(main):006:0> create 'stores', 'f'\r\n0 row(s) in 1.4600 seconds\r\n\r\nhbase(main):008:0> put 'stores', '12345', 'f:lat', '10.0'\r\n0 row(s) in 0.2490 seconds\r\n\r\nhbase(main):018:0> put 'stores', '12345', 'f:lon', '20.0'\r\n0 row(s) in 0.0060 seconds\r\n\r\nhbase(main):019:0> scan 'stores'\r\nROW                                         COLUMN+CELL\r\n 12345                                      column=f:lat, timestamp=1394570512251, value=10.0\r\n 12345                                      column=f:lon, timestamp=1394570720417, value=20.0\r\n1 row(s) in 0.0280 seconds\r\n<\/pre>\n<p>&#8230;and finally, create the following JSP&#8230;<\/p>\n<pre lang=\"java\">\r\n<%@page import=\"java.util.*\"%>\r\n<%@page import=\"org.apache.hadoop.hbase.client.*\"%>\r\n<%@page import=\"org.apache.hadoop.hbase.util.*\"%>\r\n<%@page import=\"org.apache.hadoop.hbase.*\"%>\r\n<%@page import=\"org.apache.hadoop.conf.*;\"%>\r\n\r\n<%\r\n  Configuration conf = HBaseConfiguration.create();\r\n  HTable hTable = new HTable(conf, \"stores\");  \/\/this is your table name\r\n\r\n  byte[] rowId = null;\r\n  byte[] famA = Bytes.toBytes(\"f\");  \/\/this is your column family\r\n  byte[] col1 = Bytes.toBytes(\"lat\"); \/\/this is your on the fly column name in the table\r\n  byte[] col2 = Bytes.toBytes(\"lon\"); \/\/this is your on the fly column name in the table\r\n\r\n  for (int j = 9; j < 10; j++) {  \/\/each thread loops 1000 times\r\n    rowId = Bytes.toBytes(Integer.toString(12345));\r\n    Get get = new Get(rowId);\r\n    Result result = hTable.get(get);\r\n    byte[] value = result.getValue(famA, col1);\r\n    out.println(j);\r\n    out.println(Bytes.toString(value));\r\n    value = result.getValue(famA, col2);\r\n    out.println(j);\r\n    out.println(Bytes.toString(value));\r\n  }\r\n\r\n%>\r\n<\/pre>\n<p>This should &#8220;just work&#8221;, so please reply in the comments section if you have issues.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We installed Tomcat 6.0.39 (we weren&#8217;t running JDK 1.7), as well as hbase. To get this to work, we copied the following jar&#8217;s from the hadoop and hbase installation directories to the tomcat lib directory. -rw-r&#8211;r&#8211; 1 serengeti serengeti 5212641&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2014\/03\/11\/query-hbase-from-tomcat\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[19,31],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/3567"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=3567"}],"version-history":[{"count":7,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/3567\/revisions"}],"predecessor-version":[{"id":3574,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/3567\/revisions\/3574"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=3567"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=3567"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=3567"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}