HBase 1.1.2 REST API 初体验

环境版本: ·HDP 2.5.3  ·HBase 1.1.2

HBase提供了REST API,为开发者增加了更多选择。我们可以使用HBase REST API对表进行增删改查,但本篇博客主要使用查询功能。
请注意HBase版本! 请注意HBase版本! 请注意HBase版本!

1 启动HBase REST Server

# 前台运行
[root@hqc-test-hdp3 ~]# hbase rest start -p8888
2020-05-12 16:26:02,062 INFO  [main] util.VersionInfo: HBase 1.1.2.2.5.3.0-37
2020-05-12 16:26:02,064 INFO  [main] util.VersionInfo: Source code repository git://c66-slave-20176e25-10/grid/0/jenkins/workspace/HDP-parallel-centos6/SOURCES/hbase revision=cb8c969d1089f1a34e9df11b6eeb96e69bcf878d
2020-05-12 16:26:02,064 INFO  [main] util.VersionInfo: Compiled by jenkins on Tue Nov 29 18:48:22 UTC 2016

# 后台运行
[root@hqc-test-hdp3 ~]# cd /usr/hdp/2.5.3.0-37/hbase/
[root@hqc-test-hdp3 hbase]# ls
bin  conf  doc  etc  hbase-webapps  include  lib  logs  man  pids
[root@hqc-test-hdp3 hbase]# cd bin/
[root@hqc-test-hdp3 bin]# ls
draining_servers.rb   hbase             hbase.cmd        hbase-config.cmd  hbase-daemon.sh  hbase-jruby  region_mover.rb   replication               start-hbase.cmd  test
get-active-master.rb  hbase-cleanup.sh  hbase-common.sh  hbase-config.sh   hbase.distro     hirb.rb      region_status.rb  shutdown_regionserver.rb  stop-hbase.cmd   thread-pool.rb
[root@hqc-test-hdp3 bin]# ./hbase-daemon.sh start rest -p8888
starting rest, logging to /var/log/hbase/hbase-root-rest-hqc-test-hdp3.out```

更多内容请访问官网:
http://hbase.apache.org/book.html#_rest

101.1. Starting and Stopping the REST Server
The included REST server can run as a daemon which starts an embedded Jetty servlet container and deploys the servlet into it. Use one of the following commands to start the REST server in the foreground or background. The port is optional, and defaults to 8080.

 Foreground
$ bin/hbase rest start -p <port>

 Background, logging to a file in $HBASE_LOGS_DIR
$ bin/hbase-daemon.sh start rest -p <port>
To stop the REST server, use Ctrl-C if you were running it in the foreground, or the following command if you were running it in the background.

$ bin/hbase-daemon.sh stop rest

2 使用rowkey进行查询

http://hqc-test-hdp3:8888/表名/rowkey 
# 值为Base-64编码,需解码
{
    "Row": [
        {
            "key": "MDAxMDcyOTg1MQ==",
            "Cell": [
                {
                    "column": "dmFsdWU6UkVW",
                    "timestamp": 1589268991882,
                    "$": "MzMzLjA="
                },
                ...
                {
                    "column": "dmFsdWU6VlQ4MDA4QQ==",
                    "timestamp": 1589268991882,
                    "$": "ODYuODMx"
                }
            ]
        }
    ]
}

2.1 查询单列指定时间段内的数据

# 注意此时的rowkey写为*,查询所有
http://hqc-test-hdp3:8888/表名/*/列簇名:列名/开始时间戳,结束时间戳
# 例子:http://hqc-test-hdp3:8888/TBxxx/*/cf:xx1/1589268991881,1589268991883
# 值为Base-64编码,需解码
{
    "Row": [
        {
            "key": "MDExMDcyOTg1MQ==",
            "Cell": [
                {
                    "column": "dmFsdWU6VkkxOTAyWA==",
                    "timestamp": 1589269001868,
                    "$": "NC40OTY="
                }
            ]
        },
        {
            "key": "NTAxMDcyOTg1MQ==",
            "Cell": [
                {
                    "column": "dmFsdWU6VkkxOTAyWA==",
                    "timestamp": 1589268996879,
                    "$": "NC44NDU="
                }
            ]
        }
    ]
}

2.2 查询多列指定时间段内的数据

# 注意此时的rowkey写为*,查询所有
http://hqc-test-hdp3:8888/表名/*/列簇名:列名,列簇名:列名/开始时间戳,结束时间戳
# 例子:http://hqc-test-hdp3:8888/TBxxx/*/cf:xx1,cf:xx2/1589268991881,1589268991883
# 值为Base-64编码,需解码
{
    "Row": [
        {
            "key": "MDExMDcyOTg1MQ==",
            "Cell": [
                {
                    "column": "dmFsdWU6VkkxOTAyWA==",
                    "timestamp": 1589269001868,
                    "$": "NC40OTY="
                },
                {
                    "column": "dmFsdWU6VkkxOTAyWQ==",
                    "timestamp": 1589269001868,
                    "$": "My45MzQ="
                }
            ]
        },
        {
            "key": "NTAxMDcyOTg1MQ==",
            "Cell": [
                {
                    "column": "dmFsdWU6VkkxOTAyWA==",
                    "timestamp": 1589268996879,
                    "$": "NC44NDU="
                },
                {
                    "column": "dmFsdWU6VkkxOTAyWQ==",
                    "timestamp": 1589268996879,
                    "$": "NC4zMjE="
                }
            ]
        }
    ]
}

参考链接:
https://www.iteye.com/blog/kane-xie-2226813
http://hbase.apache.org/book.html#_rest

你可能感兴趣的:(大数据动物园)