初试Hadoop, HBase

之前项目组曾经尝试过 Hadoop来进行 DFS 存储,但是因为当时Hadoop版本不稳定,或者是我们使用的不深入,感觉Hadoop不是太稳定,有些文件扫描时会出错,因此就放弃了Hadoop的方案。最近在寻找大容量样本数据库的方案,又想起Hadoop来了,而且最近新出的 HBase 构建在Hadoop之上,实现了一个类似Bigtable的存储结构,恰好能满足要求。拿来尝试下。
安装很简单,下载 HBase的文件,解压,修改下 conf/hbase-site.xml ,测试时简单的用本机:

hbase.rootdir
file:///tmp/hbase-${user.home}/hbase

修改 conf/hbase-env.sh ,把 JAVA_HOME路径写进去。ok了

执行 hbase/bin/start-hbase.sh 启动一个 hbase 服务器。
运行 hbase/bin/hbase shell 进入 HQL 的 shell 。

进入 HQL shell 有种熟悉的感觉,如同mysql或者 sqlite的shell,试着创建了一个表:

create table user (name, age);

~ 运行ok, 很简单。

插入条数据:

hql > insert into user (name, age) values ("Albert Lee", 26);
Syntax error : Type 'help;' for usage.
Message : Encountered ";" at line 1, column 56.
hql >

oh, 出错了, 看help,原来需要一个 row 的key, 之前看过Google的 Bigtable 的论文,大概知道这个row key 是定位一行数据的

hql > insert into user (name, age) values ("Albert Lee", 26) where row='al';
1 row inserted successfully. (0.12 sec)

ok, 查询:
hql > select * from user;
+-------------------------+-------------------------+-------------------------+
| Row | Column | Cell |
+-------------------------+-------------------------+-------------------------+
| al | age: | 26 |
+-------------------------+-------------------------+-------------------------+
| al | name: | Albert Lee |
+-------------------------+-------------------------+-------------------------+

恩, 看到 Row al 这个行,有两个 Column , 一个 age,一个name。

没有发现 Update 语句啊?原来直接用 Insert,改下数据覆盖掉就可以了,应该会记录不同的版本的数据的,具体再试验。

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

你好,我现在在测试hb

你好,我现在在测试hbase-0.2.0,
单独安装在Linux下,
设置JAVA_HOME后,使用脚本hbase/bin/start-hbase.sh,
然后hbase/bin/hbase shell 进入 HBASE 的 shell,
create后(命令: create 't1','f1')
但是在使用put(命令:put 't1',"row1",'f1:foo',"testtest")的命令时候无法插入数据,总是返回“0 row(s) in 0.0040 seconds”之类的提示,不知道怎么回事
能不能给个例子让我知道怎么create,然后put,然后update ,delete的命令操作

急,望回复,我email,msn:thebluesoul@hotmail.com

hehe,奇怪,这次一次就

hehe,奇怪,这次一次就通过了,还是谢谢你的文章