问题
I am trying to insert something into cassandra 0.7.6 from Erlang R14B02 (through thrift 0.6.1)
I am doing the following:
Read record definitions
rr(cassandra_types).
Connect to cassandra
{ok, C}=thrift_client_util:new("localhost", 9160, cassandra_thrift,[{strict_read, false}, {strict_write, false}, {framed, true}]).
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