hb.init("115.28.167.22",9090)
hbase thrift端口是9090
rhbase的相关函数:
hb.compact.table hb.describe.table hb.insert hb.regions.table
hb.defaults hb.get hb.insert.data.frame hb.scan
hb.delete hb.get.data.frame hb.list.tables hb.scan.ex
hb.delete.table hb.init hb.new.table hb.set.table.mode
hbase和rhbase的基本操作对比:
建表
HBASE: create 'student_shell','info'
RHBASE: hb.new.table("student_rhbase","info")
列出所有表
HBASE: list
RHBASE: hb.list.tables()
显示表结构
HBASE: describe 'student_shell'
RHBASE: hb.describe.table("student_rhbase")
插入一条数据
HBASE: put 'student_shell','mary','info:age','19'
RHBASE: hb.insert("student_rhbase",list(list("mary","info:age", "24")))
读取数据
HBASE: get 'student_shell','mary'
RHBASE: hb.get('student_rhbase','mary')
删除表(HBASE需要两条命令,rhbase仅是一个操作)
HBASE: disable 'student_shell'
HBASE: drop 'student_shell'
RHBASE: hb.delete.table('student_rhbase')
代码部分:
Hbase Shell
> create 'student_shell','info'
> list
TABLE
student_shell
> describe 'student_shell'
DESCRIPTION ENABLED
{NAME => 'student_shell', FAMILIES => [{NAME => 'info', DATA_BLOCK_ true
ENCODING => 'NONE', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0'
, VERSIONS => '3', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL
=> '2147483647', KEEP_DELETED_CELLS => 'false', BLOCKSIZE => '65536
', IN_MEMORY => 'false', ENCODE_ON_DISK => 'true', BLOCKCACHE => 't
rue'}]}
> put 'student_shell','mary','info:age','19'
> get 'student_shell','mary'
COLUMN CELL
info:age timestamp=1365414964962, value=19
> disable 'student_shell'
> drop 'student_shell'
rhbase script
~ R
> library(rhbase)
> hb.init()
<pointer: 0x16494a0>
attr(,"class")
[1] "hb.client.connection"
>hb.new.table("student_rhbase","info",opts=list(maxversions=5,x=list(maxversions=1L,compression='GZ',inmemory=TRUE)))
[1] TRUE
> hb.list.tables()
$student_rhbase
maxversions compression inmemory bloomfiltertype bloomfiltervecsize
info: 5 NONE FALSE NONE 0
bloomfilternbhashes blockcache timetolive
info: 0 FALSE -1
> hb.describe.table("student_rhbase")
maxversions compression inmemory bloomfiltertype bloomfiltervecsize
info: 5 NONE FALSE NONE 0
bloomfilternbhashes blockcache timetolive
info: 0 FALSE -1
> hb.insert("student_rhbase",list(list("mary","info:age", "24")))
[1] TRUE
> hb.get('student_rhbase','mary')
[[1]]
[[1]][[1]]
[1] "mary"
[[1]][[2]]
[1] "info:age"
[[1]][[3]]
[[1]][[3]][[1]]
[1] "24"
> hb.delete.table('student_rhbase')
[1] TRUE