Skip to content

cluXiss/hbase-clj

Repository files navigation

hbase-clj

Talk to hbase in clojure

Usage

With Leiningen

Add [org.cluxis.hbase-clj "0.1.0-SNAPSHOT"] into your :dependencies of project.clj

A tiny tutorial

First, require the required namespaces

(require 
 '(hbase-clj
	 [core :refer :all]
	 [manage :refer :all])))

We could define an hbase handler via hbase-clj.core/defhbase The code below defines a handler which connects to the localhost HBase

(defhbase test-hbase 
  "hbase.zookeeper.quorum" "localhost")

We could create a table via hbase-clj.manage/create-table! The code below creates a table named test_stu using the hbase handler defined above.

(def table-name "test_stu")

(create-table! 
  test-hbase table-name
  "info" "score")

Before we perform any CRUDs on the table, we must create a "schema" on it. The Schema describes how the data from an HBaseTable could be transformed into clojure data-structures. We define a schema via hbase-clj.core/def-hbtable

(def-hbtable test-table
  {:id-type :string 
   :table-name table-name
   :hbase test-hbase}
  :info  {:--ktype :keyword  :--vtype :long :name :string}
  :score {:--ktype :keyword  :--vtype :long})

Then we could perform CRUDs inside a table using hbase-clj.core/with-table

(with-table test-table
  (put! 
    ["101" {:info {:age 17 :name "Alice"}
            :score {:math 99 :physics 78}}]

    ["102" {:info {:age 19 :name "Bob"}
            :score {:math 63 :physics 52}}]))

The hbase-clj.core/get function gets data according to row-keys and other constraints. and returns it as a vector of vec: [row-key data]

(get "102") 
;; => [["102"
        {:info {:age 19 :name "Bob"}
         :score {:math 63 :physics 52}}]]

We can specify the families and cols either

(get "102" {:info :*}) 
;; => [["102" {:info {:age 19 :name "Bob"}}]]

(get "102" {:info :age}) 
;; => [["102" {:info {:age 19}}]]

(get "102" {:info [:age :name]}) 
;; => [["102" {:info {:age 19 :name "Bob"}}]]

If specified with-versions as the first argument, get acts a little different

(get :with-versions "102" {:info :age})
;; => [["102" {:info {:age [ {:val 19 :timestamp xxxxxxx} 
   	                         ...]}}]]

And we've got other tasty functions like

Check the complete doc!

TODOs:

  • More docs
  • Filter Support
  • Co-processor Support
  • More Table Management Tools
  • Support & Tests on various versions of Hadoop
  • More Integretion with the Hadoop Platform (e.g: MapReduce Support, etc.)

License

Copyright © 2016 cluXis

Distributed under the Eclipse Public License either version 1.0 any later version.

About

Talk to hbase in clojure

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published