Giter Site home page Giter Site logo

hbase-clj's Introduction

hbase-clj

Talk to hbase in clojure

Usage

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!

License

Copyright © 2016 cluXis

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

hbase-clj's People

Contributors

clyce avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.