学习Hadoop第二十五课(单节点HBase建表、插入数据及查询)
来源:互联网 发布:汪峰半壁江山知乎 编辑:程序博客网 时间:2024/06/05 22:42
上节课我们一起学习了HBase的一些理论知识还搭建好了单节点的HBase,那么这节课我们一起来学习一下HBase是如何建表,如何插入数据以及如何查询数据的。大家如果没看过上节课内容的,可以到:http://blog.csdn.net/u012453843/article/details/52970967这篇博客进行学习。
第一部分:建表
我们使用命令行的方式来进行建表,插入数据和查询的。在建表之前先要保证我们的HBase进程已经启动。我们使用jps命令来查看进程,如下所示,发现当前并没有HMaster进程,说明我们的HBase并没有启动。
[root@itcast03 ~]# jps
5408 Jps
[root@itcast03 ~]#
既然HBase没有启动,那么我们就先来启动HBase,启动完之后我们查看进程,如下所示,发现已经启动HBase了。
[root@itcast03 ~]# cd /itcast/hbase-0.98.23-hadoop2/
[root@itcast03 hbase-0.98.23-hadoop2]# ls
bin CHANGES.txt conf docs hbase-webapps LEGAL lib LICENSE.txt logs NOTICE.txt README.txt
[root@itcast03 hbase-0.98.23-hadoop2]# cd bin
[root@itcast03 bin]# ls
get-active-master.rb hbase-cleanup.sh hbase-config.cmd hbase-daemons.sh local-master-backup.sh region_mover.rb replication start-hbase.cmd stop-hbase.sh zookeepers.sh graceful_stop.sh hbase.cmd hbase-config.sh hbase-jruby local-regionservers.sh regionservers.sh rolling-restart.sh start-hbase.sh test
hbase hbase-common.sh hbase-daemon.sh hirb.rb master-backup.sh region_status.rb shutdown_regionserver.rb stop-hbase.cmd thread-pool.rb
[root@itcast03 bin]# ./start-hbase.sh
starting master, logging to /itcast/hbase-0.98.23-hadoop2/bin/../logs/hbase-root-master-itcast03.out
[root@itcast03 bin]# jps
5537 HMaster
5623 Jps
启动了HBase,我们来用shell命令的方式来操作HBase,如下所示,进入到了shell模式。
2016-10-30 16:53:34,888 INFO [main] Configuration.deprecation: hadoop.native.lib is deprecated. Instead, use io.native.lib.available
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 0.98.23-hadoop2, r44c724b56dc1431209f561cb997fce805f9f45f9, Wed Oct 5 01:05:05 UTC 2016
HBase Shell, version 0.98.23-hadoop2, r44c724b56dc1431209f561cb997fce805f9f45f9, Wed Oct 5 01:05:05 UTC 2016
Type 'help "COMMAND"', (e.g. 'help "get"' -- the quotes are necessary) for help on a specific command.
Commands are grouped. Type 'help "COMMAND_GROUP"', (e.g. 'help "general"') for help on a command group.
Group name: general
Commands: processlist, status, table_help, version, whoami
Commands: alter, alter_async, alter_status, create, describe, disable, disable_all, drop, drop_all, enable, enable_all, exists, get_table, is_disabled, is_enabled, list, show_filters
Commands: alter_namespace, create_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tables
Commands: append, count, delete, deleteall, get, get_counter, get_splits, incr, put, scan, truncate, truncate_preserve
Commands: assign, balance_switch, balancer, balancer_enabled, catalogjanitor_enabled, catalogjanitor_run, catalogjanitor_switch, close_region, compact, compact_rs, flush, hlog_roll, major_compact, merge_region, move, split, trace, unassign, zk_dump
Commands: add_peer, disable_peer, disable_table_replication, enable_peer, enable_table_replication, get_peer_config, list_peer_configs, list_peers, list_replicated_tables, remove_peer, set_peer_tableCFs, show_peer_tableCFs, update_peer_config
Commands: clone_snapshot, delete_all_snapshot, delete_snapshot, delete_table_snapshots, list_snapshots, list_table_snapshots, restore_snapshot, snapshot
Commands: grant, list_security_capabilities, revoke, user_permission
Commands: add_labels, clear_auths, get_auths, list_labels, set_auths, set_visibility
Creates a table. Pass a table name, and a set of column family
specifications (at least one), and, optionally, table configuration.
Column specification can be a simple string (name), or a dictionary
(dictionaries are described below in main help output), necessarily
including NAME attribute.
Examples:
hbase> create 'ns1:t1', {NAME => 'f1', VERSIONS => 5}
hbase> create 't1', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'}
hbase> # The above in shorthand would be the following:
hbase> create 't1', 'f1', 'f2', 'f3'
hbase> create 't1', {NAME => 'f1', VERSIONS => 1, TTL => 2592000, BLOCKCACHE => true}
hbase> create 't1', {NAME => 'f1', CONFIGURATION => {'hbase.hstore.blockingStoreFiles' => '10'}}
Table configuration options can be put at the end.
Examples:
hbase> create 't1', 'f1', SPLITS => ['10', '20', '30', '40']
hbase> create 't1', 'f1', SPLITS_FILE => 'splits.txt', OWNER => 'johndoe'
hbase> create 't1', {NAME => 'f1', VERSIONS => 5}, METADATA => { 'mykey' => 'myvalue' }
hbase> # Optionally pre-split the table into NUMREGIONS, using
hbase> # SPLITALGO ("HexStringSplit", "UniformSplit" or classname)
hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit'}
hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit', CONFIGURATION => {'hbase.hregion.scan.loadColumnFamiliesOnDemand' => 'true'}}
hbase> create 't1', {NAME => 'f1', DFS_REPLICATION => 1}
call methods.
hbase(main):002:0>
TABLE
student
1 row(s) in 1.0400 seconds
hbase(main):002:0>
Table student is ENABLED
student
COLUMN FAMILIES DESCRIPTION
{NAME => 'data', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0',VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => true'}
{NAME => 'info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0',VERSIONS => '3', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE =>'true'}
2 row(s) in 0.0980 seconds
Put a cell 'value' at specified table/row/column and optionally
timestamp coordinates. To put a cell value into table 'ns1:t1' or 't1'
at row 'r1' under column 'c1' marked with the time 'ts1', do:
hbase> put 't1', 'r1', 'c1', 'value'
hbase> put 't1', 'r1', 'c1', 'value', ts1
hbase> put 't1', 'r1', 'c1', 'value', {ATTRIBUTES=>{'mykey'=>'myvalue'}}
hbase> put 't1', 'r1', 'c1', 'value', ts1, {ATTRIBUTES=>{'mykey'=>'myvalue'}}
hbase> put 't1', 'r1', 'c1', 'value', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
t to table 't1', the corresponding command would be:
hbase(main):002:0>
0 row(s) in 0.3440 seconds
ROW COLUMN+CELL
rk0001 column=info:name, timestamp=1477832018237,value=tom
1 row(s) in 0.1460 seconds
0 row(s) in 0.3860 seconds
ROW COLUMN+CELL
rk0001 column=info:gender, timestamp=1477832942394,value=male
rk0001 column=info:name, timestamp=1477832018237,value=tom
1 row(s) in 0.0450 seconds
hbase(main):002:0> put 'student', 'rk0001', 'info:age', '20'
0 row(s) in 0.2780 seconds
ROW COLUMN+CELL
rk0001 column=info:age,timestamp=1477833920512, value=20
rk0001 column=info:gender, timestamp=1477832942394, value=male
rk0001 column=info:name, timestamp=1477832018237, value=tom
1 row(s) in 0.0390 seconds
0 row(s) in 0.2980 seconds
ROW COLUMN+CELL
rk0001 column=info:age, timestamp=1477833920512, value=20
rk0001 column=info:gender, timestamp=1477832942394, value=male
rk0001 column=info:name, timestamp=1477832018237, value=tom
rk0002 column=data:score,timestamp=1477834144805, value=99
2 row(s) in 0.0580 seconds
Put a delete cell value at specified table/row/column and optionally
timestamp coordinates. Deletes must match the deleted cell's
coordinates exactly. When scanning, a delete cell suppresses older
versions. To delete a cell from 't1' at row 'r1' under column 'c1'
marked with the time 'ts1', do:
hbase> delete 't1', 'r1', 'c1', ts1
hbase> delete 't1', 'r1', 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
t to table 't1', the corresponding command would be:
hbase> t.delete 'r1', 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
hbase(main):002:0>
0 row(s) in 0.3230 seconds
ROW COLUMN+CELL
rk0001 column=info:age, timestamp=1477833920512, value=20
rk0001 column=info:gender, timestamp=1477832942394, value=male
rk0001 column=info:name, timestamp=1477832018237, value=tom
1 row(s) in 0.0480 seconds
0 row(s) in 0.2790 seconds
0 row(s) in 0.0150 seconds
ROW COLUMN+CELL
rk0001 column=info:age, timestamp=1477833920512, value=20
rk0001 column=info:gender, timestamp=1477832942394, value=male
rk0001 column=info:name, timestamp=1477832018237, value=tom
rk0002 column=info:gender,timestamp=1477836207768, value=male
rk0002 column=info:name, timestamp=1477836194267, value=jerry
2 row(s) in 0.0380 seconds
0 row(s) in 0.2790 seconds
ROW COLUMN+CELL
rk0001 column=info:age, timestamp=1477836580124,value=21
rk0001 column=info:gender, timestamp=1477832942394, value=male
rk0001 column=info:name, timestamp=1477832018237, value=tom
rk0002 column=info:gender, timestamp=1477836207768, value=male
rk0002 column=info:name, timestamp=1477836194267, value=jerry
2 row(s) in 0.0510 seconds
0 row(s) in 0.0090 seconds
ROW COLUMN+CELL
rk0001 column=info:age, timestamp=1477836634700,value=22
rk0001 column=info:gender, timestamp=1477832942394, value=male
rk0001 column=info:name, timestamp=1477832018237, value=tom
rk0002 column=info:gender, timestamp=1477836207768, value=male
rk0002 column=info:name, timestamp=1477836194267, value=jerry
2 row(s) in 0.0300 seconds
ROW COLUMN+CELL
rk0001 column=info:age, timestamp=1477836634700, value=22
rk0001 column=info:age, timestamp=1477836580124, value=21
rk0001 column=info:age, timestamp=1477833920512, value=20
rk0001 column=info:gender, timestamp=1477832942394, value=male
rk0001 column=info:name, timestamp=1477832018237, value=tom
rk0002 column=info:gender, timestamp=1477836207768, value=male
rk0002 column=info:name, timestamp=1477836194267, value=jerry
2 row(s) in 0.2680 seconds
hbase(main):001:0> put 'student', 'rk0001', 'info:age', '23'
0 row(s) in 0.3200 seconds
ROW COLUMN+CELL
rk0001 column=info:age, timestamp=1477837982394, value=23
rk0001 column=info:age, timestamp=1477836634700, value=22
rk0001 column=info:age, timestamp=1477836580124, value=21
rk0001 column=info:gender, timestamp=1477832942394, value=male
rk0001 column=info:name, timestamp=1477832018237, value=tom
rk0002 column=info:gender, timestamp=1477836207768, value=male
rk0002 column=info:name, timestamp=1477836194267, value=jerry
2 row(s) in 0.0300 seconds
ROW COLUMN+CELL
rk0001 column=info:age, timestamp=1477837982394, value=23
rk0001 column=info:age, timestamp=1477836634700, value=22
rk0001 column=info:age, timestamp=1477836580124, value=21
rk0001 column=info:age, timestamp=1477833920512, value=20
rk0001 column=info:gender, timestamp=1477832942394, value=male
rk0001 column=info:name, timestamp=1477832018237, value=tom
rk0002 column=data:score, timestamp=1477834144805, type=DeleteColumn
rk0002 column=info:gender, timestamp=1477836207768, value=male
rk0002 column=info:name, timestamp=1477836194267, value=jerry
2 row(s) in 0.2830 seconds
0 row(s) in 0.0740 seconds
ROW COLUMN+CELL
rk0001 column=data:score, timestamp=1477840556318, value=90
rk0001 column=info:age, timestamp=1477837982394, value=23
rk0001 column=info:gender, timestamp=1477832942394, value=male
rk0001 column=info:name, timestamp=1477832018237, value=tom
rk0002 column=info:gender, timestamp=1477836207768, value=male
rk0002 column=info:name, timestamp=1477836194267, value=jerry
2 row(s) in 0.0360 seconds
- 学习Hadoop第二十五课(单节点HBase建表、插入数据及查询)
- 学习Hadoop第二十四课(HBase 简单入门)
- 学习Hadoop第二十六课(HBase集群搭建)
- 学习Hadoop第二十七课(HBase理论一)
- MYSQL学习笔记(十五)数据插入
- Hadoop学习笔记(十五)---Hbase shell命令的使用
- Hadoop学习笔记(一)Hadoop的单节点安装
- hadoop学习(一)配置单节点hadoop环境
- HBase总结(十五)HBase数据恢复
- 大数据开发利器:Hadoop(5)-HBase第二讲
- hadoop学习笔记-centos安装单节点及多节点集成(完整版)
- Hadoop HBase操作数据学习
- 学习Hadoop第二十八课(java通过调用接口来操作HBase)
- Hadoop,Hbase,Zookeeper在虚拟机单节点中的整合
- hadoop单节点安装及eclipse调用
- 大数据学习-hadoop -第二课
- Hbase创建表插入查询数据案例
- Hadoop学习笔记(二)设置单节点集群
- codeforces - 444c DZY Loves Physics【水】
- Android Studio 运行项目发生instant Run requires启动不了程序
- 机器学习算法与Python实践之(七)逻辑回归(Logistic Regression)
- AJAX基础
- Codeforces550A Two Substrings 暴力
- 学习Hadoop第二十五课(单节点HBase建表、插入数据及查询)
- iOS开发之AFN的基本使用
- php源码之路第三章第七节( 数据类型的转化)
- 约瑟夫环问题
- C# 算法入门
- 一张图轻松搞懂javascript event对象的clientX,offsetX,screenX,pageX区别
- 数据结构实验之二叉树五:层序遍历
- android学习1
- 跟我一起学C++之带默认形参值的函数