我正在编写一些python代码,这些代码将随着时间的推移收集数据。我要把这个藏在卡桑德拉。我花了一整天时间在这上面,但找不到有用的东西。
CREATE TABLE timearchive
(name_yymmddhh text, name text, ip text, time_current timestamp, data blob,
PRIMARY KEY (name_yymmddhh, time_current));
我可以创建表,但是插入各种数据(time_current时间戳、data )有困难。我不能正确地格式化它。我计划按小时划分行(在我的用例中数据大小应该很好)和列与每个数据输入(2-3/min)。
这是我要插入的代码。如果我将时间戳/blob的格式更改为int/text,它就能工作。
query = """INSERT INTO timearchive
(name_yymmddhh, name, ip, time_current, data)
VALUES (:name_yymmddhh, :name, :ip, :time_current, :data)"""
values = {'name_yymmddhh':rowkey,
'name': dcname,
'ip': ip,
'time_current': timenow,
'data': my_blob}
cursor.execute(query, values)
问题:
1)如何在python: timenow中创建cql时间戳?
这没有帮助(对我的卡桑德拉级来说太复杂了):Cassandra 1.2 inserting/updating a blob column type using Python and the cql library
2)我的数据是个小数据。这将是一个大量的数据集和其他数据。)我发现了各种各样的讨论,但都没有用。似乎6个月前有一些更新,但没有简单的例子:https://github.com/datastax/python-driver/pull/39)
我该怎么说:
my_dict = {'one': 1, 'two': 2, 'three': 3}
...
my_blob = ???
发布于 2014-04-02 22:17:20
解决了。需要为blob使用最新的Datastax驱动程序和上面的INSERT方法(不是字符串转换),以及正确的泡菜和字节数组。
https://stackoverflow.com/questions/22759843
复制相似问题