[ 
https://issues.apache.org/jira/browse/CASSANDRA-8779?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14316704#comment-14316704
 ] 

Kishan Karunaratne commented on CASSANDRA-8779:
-----------------------------------------------

Simple statements won't work in the python-driver as it uses string 
interpolation to create the raw CQL, as you have done. You need to serialize 
the arguments using the native protocol (which is true for simple statements in 
Java/Ruby). Try a prepared statement instead? I get the following output:
{noformat}
cassandra.cluster: DEBUG: Error querying host 127.0.0.1
Traceback (most recent call last):
  File "/home/kishan/git/cstar/python-driver/cassandra/cluster.py", line 2630, 
in _query
    connection.send_msg(message, request_id, cb=cb)
  File "/home/kishan/git/cstar/python-driver/cassandra/connection.py", line 
300, in send_msg
    self.push(msg.to_binary(request_id, self.protocol_version, 
compression=self.compressor))
  File "/home/kishan/git/cstar/python-driver/cassandra/protocol.py", line 75, 
in to_binary
    self.send_body(body, protocol_version)
  File "/home/kishan/git/cstar/python-driver/cassandra/protocol.py", line 715, 
in send_body
    write_value(f, param)
  File "/home/kishan/git/cstar/python-driver/cassandra/protocol.py", line 970, 
in write_value
    f.write(v)
TypeError: 'tuple' does not have the buffer interface
{noformat}

> Able to unintentionally nest tuples during insert
> -------------------------------------------------
>
>                 Key: CASSANDRA-8779
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-8779
>             Project: Cassandra
>          Issue Type: Bug
>         Environment: Linux Mint 64-bit | ruby-driver 2.1 | java-driver 2.1 | 
> C* 2.1.2
>            Reporter: Kishan Karunaratne
>            Assignee: Tyler Hobbs
>
> If I insert a tuple using an extra pair of ()'s, C* will let me do the 
> insert, but (incorrectly) creates a nested tuple as the first tuple value. 
> Upon doing a select statement, the result is jumbled and has weird binary in 
> it (which I wasn't able to copy into here).
> Example using ruby-driver:
> {noformat}
> session.execute("CREATE TABLE mytable (a int PRIMARY KEY, b 
> frozen<tuple<ascii, bigint, boolean>>)")
> complete = Cassandra::Tuple.new('foo', 123, true)
> session.execute("INSERT INTO mytable (a, b) VALUES (0, (?))", arguments: 
> [complete])            # extra ()'s here
> result = session.execute("SELECT b FROM mytable WHERE a=0").first
> p result['b']
> {noformat}
> Output:
> {noformat}
> #<Cassandra::Tuple:0x97b328 (fo{, , )>
> {noformat}
> Bug also confirmed using java-driver. 
> Example using java-driver:
> {noformat}
> session.execute("CREATE TABLE mytable (a int PRIMARY KEY, b 
> frozen<tuple<ascii, int, boolean>>)");
> TupleType t = TupleType.of(DataType.ascii(), DataType.cint(), 
> DataType.cboolean());
> TupleValue complete = t.newValue("foo", 123, true);
> session.execute("INSERT INTO mytable (a, b) VALUES (0, (?))", complete); // 
> extra ()'s here
> TupleValue r = session.execute("SELECT b FROM mytable WHERE 
> a=0").one().getTupleValue("b");
> System.out.println(r);
> {noformat}
> Output:
> {noformat}
> ('foo{', null, null)
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to