--- title: How to create example tables in HBase author: admin type: post date: 2013-08-13T21:40:00+00:00 url: /hadoop-tutorial-how-to-create-example-tables-in-hbase/ tumblr_gethue_permalink: - http://gethue.tumblr.com/post/58181985680/hadoop-tutorial-how-to-create-example-tables-in-hbase tumblr_gethue_id: - 58181985680 sf_thumbnail_type: - none sf_thumbnail_link_type: - link_to_post sf_detail_type: - none sf_page_title: - 1 sf_page_title_style: - standard sf_no_breadcrumbs: - 1 sf_page_title_bg: - none sf_page_title_text_style: - light sf_background_image_size: - cover sf_social_sharing: - 1 sf_sidebar_config: - left-sidebar sf_left_sidebar: - Sidebar-2 sf_right_sidebar: - Sidebar-1 sf_caption_position: - caption-right slide_template: - default ampforwp-amp-on-off: - default categories: ---
Hue brings another new app for making Apache Hadoop easier to use: HBase Browser. Apache HBase is the main keyvalue datastore for Hadoop. This post is the first episode describing the new user experience brought by the app. We will start by describing how to create some sample tables with various HBase schemas.
To help getting started with HBase, Hue now comes directly with theses examples! Just got to Hue on the [/about/][1] page and on Step 2 click on HBase and Hue will install them for you: If you want to see the HBase Browser demo, jump [episode 2][2]! {{< youtube eGcj-o90rvI >}} # Tutorial When building the new HBase Browser, we wanted to test the app against various HBase tables. It happened to be difficult to find some ready to play with schema and data to load. Hence, base on the most common uses cases, we created our own HBase schemas and decided to share them in order to help anybody wanting to start with HBase. This how-to describes how to create a very simple table that counts the daily number of votes for certain candidates and get you warmed-up. Then part 2 focuses on creating a HBase table with lot of columns and part 3 about inserting and visualizing binary data. # Setup The HBase Browser application is tailored for quickly browsing huge tables and accessing any content. You can also create new tables, add data, modify existing cells and filter data with the autocompleting search bar. The first step is to install HBase in your Hadoop cluster. We recommend to use the CDH [packages][3]. HBase Browser requires the [Thrift 1 service][4] to be started. Then, grab the app from a special tarball [release][5]{.trackLink} of Hue or get the latest and slickest version from the [nightly ‘hue’ package][6]. CDH 4.4 (target date early September) will bring a stable v1. After the installation, if HBase master is not running on the same host as Hue, have the app pointing to it by updating the [hue.ini][7] and restarting Hue. Then go tocd /tmp git clone https://github.com/romainr/hadoop-tutorials-examples.git cd hbase-tables# Analytics table The goals of this data is to show the search and smart layout of HBase Browser. This table contains more than 1000 columns of text. The idea is to have counters for 3 Web domains of 3 countries for each hour of the day. The data is then aggregated by day and for all the countries.
from hbase.api import HbaseApi
HbaseApi().putRow('Cluster', 'events', 'hue-20130801', {'doc:txt': 'Hue is awesome!'})
HbaseApi().putRow('Cluster', 'events', 'hue-20130801', {'doc:json': '{"user": "hue", "coolness": "extra"}'})
HbaseApi().putRow('Cluster', 'events', 'hue-20130802', {'doc:version': 'I like HBase'})
HbaseApi().putRow('Cluster', 'events', 'hue-20130802', {'doc:version': 'I LOVE HBase'})
Then insert a picture, and HTML page and a PDF:
root='/tmp/hadoop-tutorials-examples'
HbaseApi().putRow('Cluster', 'events', 'hue-20130801', {'doc:img': open(root + '/hbase-tables/data/hue-logo.png', "rb").read()})
HbaseApi().putRow('Cluster', 'events', 'hue-20130801', {'doc:html': open(root + '/hbase-tables/data/gethue.com.html', "rb").read()})
HbaseApi().putRow('Cluster', 'events', 'hue-20130801', {'doc:pdf': open(root + '/hbase-tables/data/gethue.pdf', "rb").read()})
Notice that the column names do not matter for the type detection. The go look at the [events][15] table and play around!
# Conclusion
These two schemas and data enable the user to easily get started with HBase. This first version of HBase Browser brings a new way to quickly explore and search for some rows and columns. New versions will support bulk loads and upload in order to completely free the user from the command line.
The new HBase Browser app will be demo-ed on these two tables in the upcoming blog posts, so stay tuned!
[1]: http://127.0.0.1:8888/about/
[2]: https://gethue.com/the-web-ui-for-hbase-hbase-browser/
[3]: http://www.cloudera.com/content/cloudera-content/cloudera-docs/CDH4/latest/CDH4-Installation-Guide/cdh4ig_topic_20_2.html
[4]: http://www.cloudera.com/content/cloudera-content/cloudera-docs/CDH4/latest/CDH4-Installation-Guide/cdh4ig_topic_20_5.html#topic_20_5_4_unique_1
[5]: https://cdn.gethue.com/downloads/releases/hbase/hue-hbase-2.5.0.tgz
[6]: http://nightly.cloudera.com/cdh4/
[7]: https://github.com/cloudera/hue/blob/master/desktop/conf.dist/hue.ini#L505
[8]: https://github.com/romainr/hadoop-tutorials-examples/tree/master/hbase-tables
[9]: http://git-scm.com/
[10]: https://raw.github.com/romainr/hadoop-tutorials-examples/master/hbase-tables/create_schemas.py
[11]: https://raw.github.com/romainr/hadoop-tutorials-examples/master/hbase-tables/load_data.sh
[12]: https://github.com/romainr/hadoop-tutorials-examples/blob/master/hbase-tables/load_data.log
[13]: http://127.0.0.1:8888/hbase/#Cluster/analytics
[14]: https://github.com/romainr/hadoop-tutorials-examples/blob/master/hbase-tables/load_binary.py
[15]: http://127.0.0.1:8888/hbase/#Cluster/events