sh 使用HBase REST API进行的实验
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 使用HBase REST API进行的实验相关的知识,希望对你有一定的参考价值。
#!/usr/bin/env bash
#
# ===================================
# Experiments with the HBase REST API
# ===================================
#
# <http://hbase.apache.org/docs/r0.20.4/api/org/apache/hadoop/hbase/rest/package-summary.html>
#
# Usage:
#
# $ brew install hbase
# $ hbase master start
# $ hbase rest start
# $ ./hbase-rest-examples.sh
#
#
function step {
/usr/bin/env ruby -e "puts '', %Q|\e[1m$1\e[0m|, %Q|\e[37m\e[42m|+('-'*80)+%Q|\e[0m|;"
}
function encode {
echo $1 | tr -d "\n" | base64
}
function decode {
echo $1 | base64 -D
}
TABLE='test'
FAMILY='data'
KEY=$(encode 'row1')
COLUMN=$(encode 'data:test')
DATA=$(encode 'Some data...')
# echo $KEY
# echo $COLUMN
# echo $DATA
step "Delete table '$TABLE'"
# -----------------------------------------------------------------------------
curl -v -X DELETE \
'http://localhost:8080/test/schema' \
-H "Accept: application/json"
step "Create table '$TABLE' with column family '$FAMILY'"
# -----------------------------------------------------------------------------
curl -v -X PUT \
'http://localhost:8080/test/schema' \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '{"@name":"test","ColumnSchema":[{"name":"data"}]}'
step "Store value '$(decode $DATA)' in column '$(decode $COLUMN)' as row '$(decode $KEY)'"
# -----------------------------------------------------------------------------
curl -v -X PUT \
'http://localhost:8080/test/row1/data:test' \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{\"Row\":{\"@key\":\"$KEY\",\"Cell\":{\"@column\":\"$COLUMN\", \"$\":\"$DATA\"}}}"
step "Store multiple value '$(decode $DATA)' in column '$(decode $COLUMN)' as row '$(decode $KEY)'"
# -----------------------------------------------------------------------------
curl -v -X PUT \
'http://localhost:8080/test/false-row-key' \
-H "Content-Type: application/json" \
--data "{\"Row\":[{\"@key\":\"$KEY1\",\"Cell\":{\"@column\":\"$COLUMN\", \"$\":\"$DATA1\"}},{\"@key\":\"$KEY2\",\"Cell\":{\"@column\":\"$COLUMN\", \"$\":\"$DATA2\"}}]}"
step "Get row '$(decode $KEY)' from table '$TABLE'"
# -----------------------------------------------------------------------------
curl -v -X GET \
'http://localhost:8080/test/row1' \
-H "Accept: application/json"
step "Get value from returned JSON"
# -----------------------------------------------------------------------------
VALUE=$( curl -s -X GET -H "Accept: application/json" 'http://localhost:8080/test/row1' | ruby -ne 'puts $_[/"\$"\:"(.+)"/, 1]' | decode )
echo "The returned value is: $VALUE"
以上是关于sh 使用HBase REST API进行的实验的主要内容,如果未能解决你的问题,请参考以下文章
HBASE Rest API (Stargate) 发布多个单元格/行
它是 Hbase REST API `get version/cluster` 中的错误吗?
markdown HBase Stargate REST API扫描程序筛选器示例
markdown HBase Stargate REST API扫描程序筛选器示例
Hbase集群搭建及所有配置调优参数整理及API代码运行
HBase:Thrift vs Rest 性能