1、查看hbase數(shù)據(jù),可以使用hbase shell。
- 也可以使用python。
- python包使用:happybase:https://happybase.readthedocs.io/en/latest/?spm=a2c6h.12873639.article-detail.7.58057c6cvWQ5wt
2、登錄阿里云服務(wù)器:xxxxxxxxxx
- 進(jìn)入目錄:/mnt/hbase
- 創(chuàng)建文件:test.py
3、腳本內(nèi)容:vim test.py
import happybase #導(dǎo)入包
import datetime #導(dǎo)入包
# 連接HBase集群
connection = happybase.Connection('hb-xxxxxxxxxx.hbase.rds.aliyuncs.com', port=xxxx, timeout=120000 )
table = connection.table('xxxxxxxx')
# 讀取前10條數(shù)據(jù)
limit = 10 #一定要提前設(shè)置變量,如果這里不配置,在for循壞里直接寫數(shù)值不生效。
# 格式化時間
start_date = datetime.datetime(2024, 6, 20)
end_date = datetime.datetime(2024, 6, 30)
start_date_str = start_date.strftime('%Y-%m-%d %H:%M:%S')
end_date_str = end_date.strftime('%Y-%m-%d %H:%M:%S')
# for循壞
for key, data in table.scan(
filter=f"SingleColumnValueFilter('xxxx', 'creationTime', >=, 'binary:{start_date_str}') AND SingleColumnValueFilter('xxxx', 'creationTime', <=, 'binary:{end_date_str}')",
limit=limit #這里一定要注意,必須是引用變量
):
print(key, data) #打印
# 關(guān)閉連接
connection.close()
4、執(zhí)行腳本:python test.py
-
可以看到對應(yīng)時間的數(shù)據(jù)
image.png
5、如、重新編寫時間,寫一個沒有數(shù)據(jù)的時間,提示如下:
-
這里其實是沒有數(shù)據(jù)引起的。
image.png

