{"id":2976,"date":"2013-05-31T09:45:53","date_gmt":"2013-05-31T14:45:53","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=2976"},"modified":"2013-05-31T09:45:53","modified_gmt":"2013-05-31T14:45:53","slug":"querying-hive-from-tomcat","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2013\/05\/31\/querying-hive-from-tomcat\/","title":{"rendered":"Querying Hive from Tomcat"},"content":{"rendered":"<p>Below is a very simple example to get started on how Hive can be queried from a web front end.<\/p>\n<p>The idea behind this would be to present the user with a csv file mime type that would be opened in Excel.<\/p>\n<p>Given the long start up time on Hive queries (they are Map Reduce jobs &#8220;under the hood&#8221;), it may be a better idea to run the Hive query (map reduce job &#8220;under the hood&#8221;) and store the intermediate results in a database such as MySQL and query that.<\/p>\n<p>Conversely, use the newest <a href=\"http:\/\/cloudera.com\/content\/cloudera\/en\/campaign\/introducing-impala.html\" target=\"_blank\">Impala release from Cloudera.<\/a><\/p>\n<p>As such, to a large extent, this is simply a learning exercise.<\/p>\n<p>Be sure to copy all *.jar files from your HIVE_INSTALLATION\/lib to the common\/lib directory under tomcat before running this.<\/p>\n<pre lang=\"java\" line=\"1\">\r\n<%@page import=\"java.sql.*;\"%>\r\n\r\n<%\r\ntry {\r\n  Class.forName(\"org.apache.hadoop.hive.jdbc.HiveDriver\");\r\n  Connection con = DriverManager.getConnection(\"jdbc:hive:\/\/192.168.3.50:10000\/default\", \"\", \"\");\r\n  Statement stmt = con.createStatement();\r\n  ResultSet res = stmt.executeQuery(\"select count(*) from requests\");\r\n  while (res.next()) {\r\n    out.println(res.getInt(1) + \"<br>\");\r\n  }\r\n  stmt.close();\r\n  con.close();\r\n}\r\ncatch (Exception e) {\r\n  e.printStackTrace();\r\n  out.println(e.getMessage());\r\n}\r\n%>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Below is a very simple example to get started on how Hive can be queried from a web front end. The idea behind this would be to present the user with a csv file mime type that would be opened&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2013\/05\/31\/querying-hive-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,24,43,25],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/2976"}],"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=2976"}],"version-history":[{"count":16,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/2976\/revisions"}],"predecessor-version":[{"id":3012,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/2976\/revisions\/3012"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=2976"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=2976"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=2976"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}