Starting to work on the hbase storage backend for maps

This commit is contained in:
David Greco 2010-09-17 14:10:32 +02:00
parent a737ef60b5
commit bd4106e7ea
2 changed files with 22 additions and 6 deletions

View file

@ -17,6 +17,7 @@ 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.client.Delete
import org.apache.hadoop.hbase.util.Bytes
/**
@ -196,7 +197,15 @@ private[akka] object HbaseStorageBackend extends MapStorageBackend[Array[Byte],
}
def getMapStorageFor(name: String): List[Tuple2[Array[Byte], Array[Byte]]] = {
Nil
val row = new Get(Bytes.toBytes(name))
val result = MAP_TABLE.get(row)
val raw = result.getFamilyMap(Bytes.toBytes(MAP_ELEMENT_COLUMN_FAMILY_NAME)).entrySet.toArray
val listBuffer = new ListBuffer[Tuple2[Array[Byte], Array[Byte]]]
for(i <- Range(raw.size-1, -1, -1)) {
listBuffer += Tuple2(raw.apply(i).asInstanceOf[java.util.Map.Entry[Array[Byte], Array[Byte]]].getKey, raw.apply(i).asInstanceOf[java.util.Map.Entry[Array[Byte],Array[Byte]]].getValue)
}
listBuffer.toList
}
def getMapStorageSizeFor(name: String): Int = {
@ -209,9 +218,16 @@ private[akka] object HbaseStorageBackend extends MapStorageBackend[Array[Byte],
}
}
def removeMapStorageFor(name: String): Unit = removeMapStorageFor(name, null)
def removeMapStorageFor(name: String): Unit = {
val row = new Delete(Bytes.toBytes(name))
MAP_TABLE.delete(row)
}
def removeMapStorageFor(name: String, key: Array[Byte]): Unit = {}
def removeMapStorageFor(name: String, key: Array[Byte]): Unit = {
val row = new Delete(Bytes.toBytes(name))
row.deleteColumns(Bytes.toBytes(MAP_ELEMENT_COLUMN_FAMILY_NAME), key)
MAP_TABLE.delete(row)
}
def getMapStorageRangeFor(name: String, start: Option[Array[Byte]], finish: Option[Array[Byte]], count: Int): List[Tuple2[Array[Byte], Array[Byte]]] = {
Nil

View file

@ -44,9 +44,9 @@ BeforeAndAfterEach {
new String(getMapStorageEntryFor("t1", "stroustrup".getBytes).get) should equal("c++")
getMapStorageEntryFor("t1", "torvalds".getBytes) should equal(None)
}
/*
it("should insert with multiple keys and values") {
import MongoStorageBackend._
import HbaseStorageBackend._
val l = List(("stroustrup", "c++"), ("odersky", "scala"), ("gosling", "java"))
insertMapStorageEntriesFor("t1", l.map { case (k, v) => (k.getBytes, v.getBytes) })
@ -66,7 +66,7 @@ BeforeAndAfterEach {
removeMapStorageFor("t1")
getMapStorageSizeFor("t1") should equal(0)
}
/*
it("should do proper range queries") {
import MongoStorageBackend._
val l = List(