inserting from erlang into cassandra

丶灬走出姿态 提交于 2019-12-12 17:14:52

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/6372654/inserting-from-erlang-into-cassandra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!