cassandra - not able to insert decimal numbers using ruby client in a composite column

419 Views Asked by At

I have a composite column family with the following schema

CREATE TABLE employees ( 
                          name varchar,
                          month int,
                          date int,
                          salary decimal,
                          PRIMARY KEY(name,month,date)
                       );

This works fine when executed from CQL.

#INSERT INTO employees (name,month,date,salary) VALUES ('joe',1,1,1000);

However this is failing when tried to insert using Ruby Clinet.

client = Cassandra.new('keyspace_name', '127.0.0.1:9160')
colkey = Cassandra::Composite.new([4].pack('N'), [5].pack('N'), 'salary')
client.insert(:employees, 'nick', {colkey=> [2000].pack("D")}) - This is failing
client.insert(:employees, 'nick', {colkey=> "2000"}) - This works fine

Here is the error:

CassandraThrift::InvalidRequestException: CassandraThrift::InvalidRequestException
        from /usr/local/lib/ruby/gems/1.9.1/gems/cassandra-0.16.0/vendor/0.8/gen-rb/cassandra.rb:252:in `recv_batch_mutate'
        from /usr/local/lib/ruby/gems/1.9.1/gems/cassandra-0.16.0/vendor/0.8/gen-rb/cassandra.rb:243:in `batch_mutate'
        from /usr/local/lib/ruby/gems/1.9.1/gems/thrift_client-0.8.2/lib/thrift_client/abstract_thrift_client.rb:148:in `handled_proxy'
        from /usr/local/lib/ruby/gems/1.9.1/gems/thrift_client-0.8.2/lib/thrift_client/abstract_thrift_client.rb:51:in `batch_mutate'
        from /usr/local/lib/ruby/gems/1.9.1/gems/cassandra-0.16.0/lib/cassandra/protocol.rb:7:in `_mutate'
        from /usr/local/lib/ruby/gems/1.9.1/gems/cassandra-0.16.0/lib/cassandra/cassandra.rb:463:in `insert'
        from (irb):41
        from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in `start'
        from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start'
        from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:41:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'

What is it that I am doing wrong ? or is it a bug ?

regards, madhu

0

There are 0 best solutions below