{"id":11725,"date":"2013-12-08T21:08:00","date_gmt":"2013-12-08T20:08:00","guid":{"rendered":"http:\/\/zygm0nt.github.com\/blog\/2013\/12\/08\/simple-hbase-orm"},"modified":"2013-12-09T08:24:20","modified_gmt":"2013-12-09T07:24:20","slug":"simple-hbase-orm","status":"publish","type":"post","link":"https:\/\/touk.pl\/blog\/2013\/12\/08\/simple-hbase-orm\/","title":{"rendered":"Simple HBase ORM"},"content":{"rendered":"<p>When dealing with data stored in HBase, you are quick to come to a<br \/>\nconclusion, that it is extremaly inconvenient to reach to it<br \/>\nvia HBase native API. It is very verbose and you always need to convert<br \/>\nbetween bytes and simple types &#8211; a pain.<\/p>\n<p>While I was working on a project of mine, I thought, why not to easy<br \/>\nthose pains and fetch real objects from HBase.<\/p>\n<p>And that&#8217;s how this simplistic, hackish ORM came to life. It is no match<br \/>\nfor projects like <a href=\"https:\/\/github.com\/impetus-opensource\/Kundera\">Kundera<\/a><br \/>\n(a JPA compliant solution), or <a href=\"https:\/\/code.google.com\/p\/n-orm\/\">n-orm<\/a>. Nevertheless, it just suits my needs :)<\/p>\n<p><!-- more --><\/p>\n<p>Project sources are hosted on GitHub: <a href=\"https:\/\/github.com\/zygm0nt\/hbase-annotations\">https:\/\/github.com\/zygm0nt\/hbase-annotations<\/a><\/p>\n<p>To make use of this, you need to have an entity class with annotations:<\/p>\n<ul>\n<li>@Column &#8211; with argument specifying column family and column name, ie.<br \/>\n@Column(&#8220;cf:column-name&#8221;)<\/li>\n<li>@Id &#8211; will store row key in this property,<\/li>\n<li>and optionaly @Value &#8211; for Spring Expression Language, in case you<br \/>\nneed to perform some extraction on the value.<\/li>\n<\/ul>\n<p><em>Annotations should be on setter methods.<\/em><\/p>\n<p>Now you have your model annotated and ready to be fetched from HBase.<\/p>\n<p>The actual work is done with a service class, that should extend class<br \/>\n<a href=\"https:\/\/github.com\/zygm0nt\/hbase-annotations\/blob\/master\/src\/main\/java\/pl\/touk\/hadoop\/hbase\/BaseHadoopInteraction.java\">BaseHadoopInteraction<\/a> just as class<br \/>\n<a href=\"https:\/\/github.com\/zygm0nt\/hbase-annotations\/blob\/master\/src\/test\/java\/pl\/touk\/hadoop\/hbase\/SampleHBaseClient.java\">SimpleHBaseClient<\/a> does.<\/p>\n<p>Then it is possible to just call:<\/p>\n<p>Note that there are more methods you can use on BaseHadoopInteraction.<br \/>\nYou can also do:<\/p>\n<ul>\n<li>scan<\/li>\n<li>scan with key ranges<\/li>\n<li>delete<\/li>\n<\/ul>\n<p>What you won&#8217;t get from this simple ORM is:<\/p>\n<ul>\n<li>automatic object updating,<\/li>\n<li>nested objects,<\/li>\n<li>saving to HBase &#8211; &#8217;cause I didn&#8217;t have a need for that,<\/li>\n<\/ul>\n<p>Hope you&#8217;ll find this piece of code useful. If you see room for<br \/>\nimprovements while staying in project&#8217;s scope &#8211; please drop me a<br \/>\nmessage.<\/p>\n<p>And if you are searching for a full-fledged ORM solution for interacting with HBase, just head<br \/>\nstraight to Kundera project website :)<\/p>\n","protected":false},"excerpt":{"rendered":"When dealing with data stored in HBase, you are quick to come to a\nconclusion, that it is extremaly inconvenient to reach to it\nvia HBase native API. It is very verbose and you always need to convert\nbetween bytes and simple types &#8211; a pain.\nWhile I wa&#8230;When dealing with data stored in HBase, you are quick to come to a\nconclusion, that it is extremaly inconvenient to reach to it\nvia HBase native API. It is very verbose and you always need to convert\nbetween bytes and simple types &#8211; a pain.\nWhile I wa&#8230;\n","protected":false},"author":11,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":{"0":"post-11725","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-development-design"},"_links":{"self":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/11725","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/comments?post=11725"}],"version-history":[{"count":3,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/11725\/revisions"}],"predecessor-version":[{"id":11728,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/11725\/revisions\/11728"}],"wp:attachment":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/media?parent=11725"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/categories?post=11725"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/tags?post=11725"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}