i have a problem with an insert query in ruby with cassandra,
This is my table :
CREATE TABLE testkeyspace.ticket (
id int,
uid text,
annule boolean,
avoir decimal,
caisse int,
clotureid int,
couverts decimal,
creation_iso timestamp,
modif_iso timestamp,
montantencaisse decimal,
montantttc decimal,
nb_articles int,
numero int,
remise decimal,
remise_montant decimal,
remise_type text,
remise_valeur decimal,
rendu decimal,
stats_iso timestamp,
PRIMARY KEY (id, uid)
)
In ruby i made a prepare statement :
insert_table_ticket = session.prepare("INSERT INTO ticket(id, uid, annule, avoir, caisse, clotureid, couverts,creation_iso, modif_iso, montantencaisse, montantttc, nb_articles, numero, remise,remise_montant, remise_type, remise_valeur, rendu,stats_iso) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
And i put these value for testing :
session.execute(insert_table_ticket,
1,
"test",
true,
1.1,
1,
1,
1.0,
1415350203,
1415350203,
1.1,
1.1,
1,
1,
1.1,
1.1,
"tests",
1.1,
1.1,
1415350203
)
I got this error:
/home/florian/.rvm/gems/ruby-2.1.4/gems/cassandra-driver-1.0.0.rc.1/lib/cassandra/protocol/cql_byte_buffer.rb:275:in
to_s': wrong number of arguments (1 for 0) (ArgumentError) from /home/florian/.rvm/gems/ruby-2.1.4/gems/cassandra-driver-1.0.0.rc.1/lib/cassandra/protocol/cql_byte_buffer.rb:275:in
append_decimal' from /home/florian/.rvm/gems/ruby-2.1.4/gems/cassandra-driver-1.0.0.rc.1/lib/cassandra/protocol/type_converter.rb:287:indecimal_to_bytes' from /home/florian/.rvm/gems/ruby-2.1.4/gems/cassandra-driver-1.0.0.rc.1/lib/cassandra/protocol/type_converter.rb:85:in
call' from /home/florian/.rvm/gems/ruby-2.1.4/gems/cassandra-driver-1.0.0.rc.1/lib/cassandra/protocol/type_converter.rb:85:into_bytes' from /home/florian/.rvm/gems/ruby-2.1.4/gems/cassandra-driver-1.0.0.rc.1/lib/cassandra/protocol/requests/execute_request.rb:93:in
block in encode_values' from /home/florian/.rvm/gems/ruby-2.1.4/gems/cassandra-driver-1.0.0.rc.1/lib/cassandra/protocol/requests/execute_request.rb:92:ineach' from /home/florian/.rvm/gems/ruby-2.1.4/gems/cassandra-driver-1.0.0.rc.1/lib/cassandra/protocol/requests/execute_request.rb:92:in
each_with_index' from /home/florian/.rvm/gems/ruby-2.1.4/gems/cassandra-driver-1.0.0.rc.1/lib/cassandra/protocol/requests/execute_request.rb:92:inencode_values' from /home/florian/.rvm/gems/ruby-2.1.4/gems/cassandra-driver-1.0.0.rc.1/lib/cassandra/protocol/requests/execute_request.rb:39:in
initialize' from /home/florian/.rvm/gems/ruby-2.1.4/gems/cassandra-driver-1.0.0.rc.1/lib/cassandra/cluster/client.rb:190:innew' from /home/florian/.rvm/gems/ruby-2.1.4/gems/cassandra-driver-1.0.0.rc.1/lib/cassandra/cluster/client.rb:190:in
execute' from /home/florian/.rvm/gems/ruby-2.1.4/gems/cassandra-driver-1.0.0.rc.1/lib/cassandra/session.rb:81:inexecute_async' from /home/florian/.rvm/gems/ruby-2.1.4/gems/cassandra-driver-1.0.0.rc.1/lib/cassandra/session.rb:103:in
execute' from /home/florian/Projects/hadoop-ticket-server/import_cassandra.rb:60:inblock (3 levels) in <top (required)>' from /home/florian/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/benchmark.rb:279:in
measure' from /home/florian/Projects/hadoop-ticket-server/import_cassandra.rb:35:inblock (2 levels) in <top (required)>' from /home/florian/Projects/hadoop-ticket-server/import_cassandra.rb:34:in
each' from /home/florian/Projects/hadoop-ticket-server/import_cassandra.rb:34:inblock in <top (required)>' from /home/florian/Projects/hadoop-ticket-server/import_cassandra.rb:33:in
execute' from /home/florian/Projects/hadoop-ticket-server/import_cassandra.rb:33:in<top (required)>' from -e:1:in
load' from -e:1:in `'
Did you have an idea about my problem ? Thanks you
The problem was with the float number.
Ruby in float is interpreted as double or float in cassandra. To put decimal in cassandra we have to put BigDecimal in Ruby.
source : "http://datastax.github.io/ruby-driver/features/basics/"
solution :
session.execute(insert_table_ticket,
1,
"test",
true,
BigDecimal.new('1.1'),
1,
1,
BigDecimal.new('1.0'),
1415350203,
1415350203,
BigDecimal.new('1.1'),
BigDecimal.new('1.1'),
1,
1,
BigDecimal.new('1.1'),
BigDecimal.new('1.1'),
"tests",
BigDecimal.new('1.1'),
BigDecimal.new('1.1'),
1415350203
)