kreynolds / cassandra-cql

DBI-like CQL driver for Cassandra in Ruby
Apache License 2.0
67 stars 43 forks source link

compound primary key not supported #55

Open kylehr opened 11 years ago

kylehr commented 11 years ago

Hi guys,

The traceback at the end of this post shows the datastax example failing to load. This works from cqlsh ...

cqlsh:k1> CREATE TABLE timeline ( user_id varchar, tweet_id uuid, author varchar, body varchar, PRIMARY KEY (user_id, tweet_id)) ; cqlsh:k1>

I was expecting the string to be passed straight through so apologies if I am missing something.

Cheers, Kyle

1.9.2p320 :192 > db.execute('CREATE TABLE timeline ( user_id varchar, tweet_id uuid, author varchar, body varchar, PRIMARY KEY (user_id, tweet_id))') CassandraCQL::Error::InvalidRequestException: line 1:117 extraneous input ')' expecting EOF from /Users/kyle/.rvm/gems/ruby-1.9.2-p320/gems/cassandra-cql-1.2.0/lib/cassandra-cql/database.rb:110:in rescue in execute_cql_query' from /Users/kyle/.rvm/gems/ruby-1.9.2-p320/gems/cassandra-cql-1.2.0/lib/cassandra-cql/database.rb:104:inexecute_cql_query' from /Users/kyle/.rvm/gems/ruby-1.9.2-p320/gems/cassandra-cql-1.2.0/lib/cassandra-cql/statement.rb:47:in execute' from /Users/kyle/.rvm/gems/ruby-1.9.2-p320/gems/cassandra-cql-1.2.0/lib/cassandra-cql/database.rb:93:inexecute' from (irb):192 from /Users/kyle/.rvm/rubies/ruby-1.9.2-p320/bin/irb:16:in <main>' 1.9.2p320 :193 > db.execute('CREATE TABLE timeline ( user_id varchar, tweet_id uuid, author varchar, body varchar, PRIMARY KEY (user_id, tweet_id))') CassandraCQL::Error::InvalidRequestException: line 1:117 extraneous input ')' expecting EOF from /Users/kyle/.rvm/gems/ruby-1.9.2-p320/gems/cassandra-cql-1.2.0/lib/cassandra-cql/database.rb:110:inrescue in execute_cql_query' from /Users/kyle/.rvm/gems/ruby-1.9.2-p320/gems/cassandra-cql-1.2.0/lib/cassandra-cql/database.rb:104:in execute_cql_query' from /Users/kyle/.rvm/gems/ruby-1.9.2-p320/gems/cassandra-cql-1.2.0/lib/cassandra-cql/statement.rb:47:inexecute' from /Users/kyle/.rvm/gems/ruby-1.9.2-p320/gems/cassandra-cql-1.2.0/lib/cassandra-cql/database.rb:93:in execute' from (irb):193 from /Users/kyle/.rvm/rubies/ruby-1.9.2-p320/bin/irb:16:in

'

vicentllongo commented 11 years ago

Hi there,

You are most likely connecting to Cassandra using CQL2, and compound keys are a CQL3 feature. Pass the correct cql_version in the client options and it should work fine.

db = CassandraCQL::Database.new('127.0.0.1:9160', {:cql_version => "3.0.0"'})
vitaliy commented 11 years ago

Same error here. After adding cql_version error changes to

/Users/vitaliy/.rvm/gems/ruby-2.0.0-p195@cloudp/gems/cassandra-cql-1.2.1/lib/cassandra-cql/database.rb:115:in rescue in execute_cql_query': Cannot execute/prepare CQL2 statement since the CQL has been set to CQL3(This might mean your client hasn't been upgraded correctly to use the new CQL3 methods introduced in Cassandra 1.2+). (CassandraCQL::Error::InvalidRequestException) from /Users/vitaliy/.rvm/gems/ruby-2.0.0-p195@cloudp/gems/cassandra-cql-1.2.1/lib/cassandra-cql/database.rb:109:inexecute_cql_query' from /Users/vitaliy/.rvm/gems/ruby-2.0.0-p195@cloudp/gems/cassandra-cql-1.2.1/lib/cassandra-cql/statement.rb:47:in execute' from /Users/vitaliy/.rvm/gems/ruby-2.0.0-p195@cloudp/gems/cassandra-cql-1.2.1/lib/cassandra-cql/database.rb:98:inexecute' from /Users/vitaliy/.rvm/gems/ruby-2.0.0-p195@cloudp/gems/cassandra-cql-1.2.1/lib/cassandra-cql/database.rb:58:in `block in connect!'

cassandra-cql 1.2.1 thrift 0.8.0 thrift-client 0.8.4

vicentllongo commented 11 years ago

What cassandra version are you using?

vitaliy commented 11 years ago

1.2.6

from what I see it's an issue with thrift client. in cassandra-cql:

def use_cql3? (@cql_version.nil? || @cql_version.split('.').first.to_i >= 3) && CassandraCQL::Thrift::Client.method_defined?(:execute_cql3_query) end

for me CassandraCQL::Thrift::Client.method_defined?(:execute_cql3_query) is false.