hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Hadoop Wiki] Update of "Hbase/Scala" by tuxracer69
Date Thu, 17 Dec 2009 08:31:09 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Hadoop Wiki" for change notification.

The "Hbase/Scala" page has been changed by tuxracer69.
The comment on this change is: starting a scala page (there was already a jython and groovy


New page:
== Accessing HBase from Scala ==
Scala can call Hbase classes very easily as other JVM based languages (Jython, Jruby, Groovy).
Scala may be a better choice than say Jython as Jython 2.5.1 does not ship any more with a
jythonc compiler command, and if you want to do Hbase mapreduce integration, you will need
compiled classes.

== Setting Your Classpath ==

Set your classpath as described in 
for instance getting it from:
ps auwx|grep java|grep org.apache.hadoop.hbase.master.HMaster|perl -pi -e "s/.*classpath //"

== The Code ==
Please look at the Java API. Adaptation to scala should be relatively easy. The example below
shows part of the smple Java code adapted to scala:


import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.client.HBaseAdmin
import org.apache.hadoop.hbase.client.HTable
import org.apache.hadoop.hbase.client.Put
import org.apache.hadoop.hbase.client.Get
import org.apache.hadoop.hbase.util.Bytes

val conf = new HBaseConfiguration()
val admin = new HBaseAdmin(conf)

// list the tables
val listtables=admin.listTables() 

// let's insert some data in 'mytable' and get the row

val table = new HTable(conf, "mytable")

val theput= new Put(Bytes.toBytes("rowkey1"))


val theget= new Get(Bytes.toBytes("rowkey1"))
val result=table.get(theget)
val value=result.value()


View raw message