The*_*uad 5 erlang thrift cassandra
我正在尝试用Erlang让我的头围绕Cassandra/thrift ...
我有一个名为"mq"的列族(如在消息队列中)...
我希望每个用户有一行(带有user_id),每条消息都是一个新列,其中包含name的时间戳和作为值的消息.
这是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';
Run Code Online (Sandbox Code Playgroud)
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
]
).
Run Code Online (Sandbox Code Playgroud)
这是错误:
{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]}}}
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激...
编辑1:
我发现它应该是(因为它适用于其他人):
thrift_client:call(C,'insert', ["00000001", #columnParent{column_family="mq"}, #column{name="123456",value="Hello World!"}, 2]).
Run Code Online (Sandbox Code Playgroud)
这是相关的错误消息:
** 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)
Run Code Online (Sandbox Code Playgroud)
好吧,我已经找到了问题所在,或者需要纠正的问题......
这是我的代码,用于连接和插入......
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]).
Run Code Online (Sandbox Code Playgroud)
事实上,我们应该将“set_keyspace”返回的新 thrift_client 插入...显然,对于通过 thrift 完成的每个调用,都会生成一个新的 thrift_client 并应该使用它。
此外,我们应该使用columnParent而不是columnPath(还不知道为什么,它只是有效)。#column 中的时间戳是强制性的...
我希望这对其他人有帮助。
| 归档时间: |
|
| 查看次数: |
782 次 |
| 最近记录: |