开发者

inserting from erlang into cassandra

I am trying to insert something into cassandra 0.7.6 from Erlang R14B02 (through thrift 0.6.1)

I am doing the following:

  1. Read record definitions

    rr(cassandra_types).

  2. Connect to cassandra

    {ok, C}=thrift_client_util:new("localhost", 9160, cassandra_thrift,[{strict_read, false}, {strict_write, false}, {framed, true}]).

  3. Try to insert a value (timestamp=1, 2=Quorum)

    Reply1 = thrift_client:call(C, 'insert', ["existing_keyspace", "new_key",#columnPath{column_family = "existing_column_family", column = "existing_column"}, "new_value",1,2]).

But nr3 gives me a bad_args error (1开发者_运维问答 and 2 work perfectly). What would be the right arguments?


What API information there is for unsupported languages is largely in their Cassandra Thrift API documentation.

In Cassandra 0.7, you don't supply the keyspace for most operations, so insert just takes [Key, ColumnPath, Column, ConsistencyLevel]. You need to call set_keyspace before attempting the insert. The insert in erlang would be

Reply1 = thrift_client:call(C, 'insert',
                            [SomeKey,
                             #columnPath{column_family = "existing_column_family",
                                         column = "existing_column"},
                             #column{name="existing_column",
                                     value="new_value",timestamp=1},
                             ?cassandra_ConsistencyLevel_QUORUM]).

Your example is missing the row key for the insert I think too.

As an aside, make sure you always update the value of C - it changes after every thrift_client call.

?cassandra_ConsistencyLevel_QUORUM is 2 from memory.


This might help, although there is no erlang-specific code: http://wiki.apache.org/cassandra/ThriftExamples

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜