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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章