Skip to content

Instantly share code, notes, and snippets.

@groundwater
Created April 12, 2012 08:12
Show Gist options
  • Save groundwater/2365569 to your computer and use it in GitHub Desktop.
Save groundwater/2365569 to your computer and use it in GitHub Desktop.
Play with HBase
package controllers
import play.api._
import play.api.mvc._
import com.googlecode.protobuf.format._
import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.client.{ HTable, Put, Scan, Get }
import org.apache.hadoop.hbase.util.Bytes
import models.Auth.User
import play.api.templates.Html
object Application extends Controller {
// HBase Constants
val d = Bytes.toBytes("d")
val buf = Bytes.toBytes("buf")
val rid = Bytes.toBytes("row1")
val conf = HBaseConfiguration.create()
val table = new HTable(conf, "demo")
def index = Action {
val put = new Put(rid)
val protobuf = User.newBuilder().
setUid("bob").
setEmail("bob@example.com").
setPwdhash("0293fj09ajdfasdf").
build()
put.add(
d,
buf,
protobuf.toByteArray())
table.put(put)
val row = table.get(new Get(rid))
val user = models.Auth.User.parseFrom(row.getValue(
d,
buf))
Ok(Html(HtmlFormat.printToString(user)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment