面临有关 python starbase 获取字节和字符串数据的问题

Facing issues regarding python starbase fetch function to fetch byte and string data

我最近遇到了 starbase 模块,用于将我的 python 脚本连接到 hbase。

我将向您简要说明我所面临的问题,然后逐步分解,让您对它有一个清晰的了解。

我的 hbase table 中有一些名为 'dummy_table' 的数据。之前 table 中的键都是由 \x00 填充分隔的字符串。这是一个例子:-

00:00:00:00:00:00\x001441767600\x001\x0040.0.2.1\x00

现在我将解释这些字段实际上是什么:-

00:00:00:00:00:00 - This is the mac address
1441767600 - This is the time in epoch (Wed Sep  9 03:00:00 UTC 2015)
1 - this is the customer id
40.0.2.1 - this is store id

由于之前都是字符串,所以很容易获取到这些键对应的值。

这是代码片段:-

from starbase import Connection
import starbase
C = Connection(host='10.10.122.136', port='60010')

get_table = C.table('dummy_table')
mac = "00:00:00:00:00:00"
hours = "1441767600"
cus_id = "1"
store_id = "40.0.2.1"
create_query = '%s\x00%s\x00%s\x00%s\x00' % (mac,hours,cus_id,store_id)
fetch_result = get_table.fetch(create_query)
print fetch_result

早些时候,这段代码用于给我精确的哈希值

{count:100}

现在的问题是时间 1441767600 以 8 字节的形式存储在 hbase 中以提高性能,因为 hbase 中的数据量非常大。

现在 hbase 中的 row/key 看起来像这样:-

00:00:00:00:00:00\x00\x80\x00\x00\x00U\xEF\xA0\xB0\x001\x0040.0.2.1\x00

分解:-

00:00:00:00:00:00 - Mac address
\x80\x00\x00\x00U\xEF\xA0\xB0 - time in bytes (1441767600 if converted into long from bytes)
1 - customer id
40.0.2.1 - store_id

现在,如果我 运行 类似的代码并进行最小的更改,以便 python 将字节作为字符串,则它不起作用。 这是代码片段:-

from starbase import Connection
import starbase
C = Connection(host='10.10.122.136', port='60010')

get_table = C.table('dummy_table')
mac = "00:00:00:00:00:00"
hours = "\x80\x00\x00\x00U\xEF\xA0\xB0"
cus_id = "1"
store_id = "40.0.2.1"
create_query = '%s\x00%s\x00%s\x00%s\x00' % (mac,hours,cus_id,store_id)
fetch_result = get_table.fetch(create_query)
print fetch_result

当我 运行 这个时,结果是 "None"。

有趣的是,当我直接访问我的 hbase 和 运行 相同的 get 查询时,它起作用了。 这是相同的 hbase get 查询:-

get 'dummy_table', "00:00:00:00:00:00\x00\x80\x00\x00\x00U\xEF\xA0\xB0\x001\x0040.0.2.1\x00", COLUMN => ['cf1:count:toLong']

这给出了输出:-

100

这是正确的。 我已经搜索了很多,但我还没有遇到任何可以解决我的问题的东西。

有什么帮助吗?谢谢

经过相当多的努力,我发现了另一个名为 happybase 的 python 模块,它将 python 连接到 hbase 到 fetch/insert 数据。

在这种情况下,Happybase 似乎可以正常工作。 https://happybase.readthedocs.org/en/latest/installation.html#installing-the-happybase-package

Starbase 扫描功能正在开发中。这就是他们网站上所说的。 http://starbase.readthedocs.org/en/0.1/