Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
面临有关python starbase fetch函数获取字节和字符串数据的问题_Python_Hbase - Fatal编程技术网

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

面临有关python starbase fetch函数获取字节和字符串数据的问题,python,hbase,Python,Hbase,我最近遇到了starbase模块,用于将我的python脚本连接到hbase 我会给你一个简要的什么问题,我正面临着,然后将其分解一步一步给你一个清晰的形象 我的hbase表中有一些数据称为“dummy_table”。此表中先前的键都是由\x00填充分隔的字符串。以下是一个例子:- 00:00:00:00:00:00\x001441767600\x001\x0040.0.2.1\x00 现在,我将解释这些字段实际上是什么:- 00:00:00:00:00:00 - This is the ma

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

我会给你一个简要的什么问题,我正面临着,然后将其分解一步一步给你一个清晰的形象

我的hbase表中有一些数据称为“dummy_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
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
前面这段代码用来给我一个确切的值,它是一个散列

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

现在,hbase中的行/键如下所示:-

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 = "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
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
当我运行这个程序时,结果是“无”

有趣的是,当我直接访问我的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以获取/插入数据

Happybase在这种情况下似乎工作正常


星基扫描功能目前正在开发中。他们的网站上就是这么说的

经过一番努力,我发现了另一个名为happybase的python模块,它将python连接到hbase以获取/插入数据

Happybase在这种情况下似乎工作正常

星基扫描功能目前正在开发中。他们的网站上就是这么说的