我目前正试图让我的头脑围绕 Cassandra/thrift 与 Erlang ......
我有一个名为“mq”的列族(如在消息队列中)...
我希望每个用户都有一行(带有 user_id),每条消息都是一个新列,名称为时间戳,消息为值。
这是我在 Cassandra-cli 中所做的:
create keyspace my_keyspace;
use my_keyspace;
create column family mq with comparator=UTF8Type and key_validation_class=UTF8Type;
%% Adding to user_id (00000001) the message "Hello World!"
set mq['00000001']['1336499385041308'] = 'Hello Wold';
使用 Cassandra-cli 一切正常
但是,当我尝试从 Erlang 插入时,遇到了一些问题:
1>rr(cassandra_types).
2>{ok, C}=thrift_client_util:new("localhost", 9160, cassandra_thrift,[{framed, true}]).
3>thrift_client:call(C, 'set_keyspace', ["peeem"]).
4>thrift_client:call(C,'insert',["00000001",
#columnPath{column_family="mq"},
#column{name="1336499385041308", value="Hello World!"},
1
]
).
这是错误:
{error,{bad_args,insert,
["00000001",
#columnPath{column_family = "mq",super_column = undefined,
column = undefined},
#column{name = "1336499385041308",value = "Hello World!",
timestamp = undefined,ttl = undefined},1]}}}
任何帮助,将不胜感激...
编辑 1:
我发现它应该是(因为它适用于其他人):
thrift_client:call(C,'insert', ["00000001", #columnParent{column_family="mq"}, #column{name="123456",value="Hello World!"}, 2]).
这是相关的错误消息:
** exception error: no match of right hand side value {{protocol,thrift_binary_protocol,
{binary_protocol,{transport,thrift_framed_transport,
{framed_transport,{transport,thrift_socket_transport,
{data,#Port<0.730>,infinity}},
[],[]}},
true,true}},
{error,closed}}
in function thrift_client:send_function_call/3 (src/thrift_client.erl, line 83)
in call from thrift_client:call/3 (src/thrift_client.erl, line 40)
最佳答案
好的,我已经找到了问题所在,或者问题是正确的......
这是我的代码,用于连接和插入...
rr(cassandra_types).
{ok, C}=thrift_client_util:new("localhost", 9160, cassandra_thrift,[{framed, true}]).
{C1, _} = thrift_client:call(C, 'set_keyspace', ["my_keyspace"]).
thrift_client:call(C1,'insert', ["00000001", #columnParent{column_family="mq"}, #column{name="1234567",value="Hello World !", timestamp=0}, 2]).
事实上,我们应该插入到“set_keyspace”返回的新 thrift_client 中……显然对于通过 thrift 完成的每次调用,都会生成一个新的 thrift_client 并应该使用它。
此外,我们应该使用 columnParent 而不是 columnPath (不知道为什么,它只是有效)。 #column 中的时间戳是强制性的...
我希望这对其他人有帮助。
关于erlang - Cassandra thrift Erlang 插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10503907/