Daniel Klöck
Daniel Klöck

Reputation: 21147

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?

Upvotes: 2

Views: 515

Answers (2)

archaelus
archaelus

Reputation: 7129

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.

Upvotes: 3

jbellis
jbellis

Reputation: 19377

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

Upvotes: 0

Related Questions