scassandra / scassandra-server

Stubbed Cassandra
http://www.scassandra.org
Other
87 stars 34 forks source link

ColumnMetadata.column does not appear to do anything. #132

Open MicahZoltu opened 8 years ago

MicahZoltu commented 8 years ago
cassandraServer.primingClient().prime(PrimingRequest.preparedStatementBuilder()
    .withQuery(query)
    .withColumnTypes(ColumnMetadata.column("foo", PrimitiveType.BIG_INT))
    .build());

PreparedStatement preparedStatement = session.prepare("INSERT INTO my_table (foo)");
BoundStatement boundStatement = new BoundStatement(preparedStatement).setLong("foo", 50);
session.execute(boundStatement);

This results in an exception when calling setLong on the bound statement foo is not a column defined in this metadata. Looking at the logs, I see the priming include the priming of column foo as BIG_INT but when I call session.prepare(...) I don't get back the primed columns: PreparedResultV2(0,5,keyspace,table,List())

MicahZoltu commented 8 years ago

Just as a wild guess, it is probably this: https://github.com/scassandra/scassandra-server/blob/master/server/src/main/scala/org/scassandra/server/cqlmessages/response/PreparedResult.scala#L74-L77? Is the cassandra protocol documented anywhere?

MicahZoltu commented 8 years ago

Found the spec, and it appears that I was wrong about the lines that are causing the problem:https://github.com/apache/cassandra/blob/cassandra-2.2/doc/native_protocol_v2.spec#L554-L576

MicahZoltu commented 8 years ago

I ran into further trouble trying to actually use this change in my application. It appears that now the prepared execution doesn't match the prepared statement. When I try to execute the prepared statement, after it parses the first part of the message and looks for matching primes it doesn't find one because the stored primes have a variableType.size of 0. I can change that to also check prime.prime.columnTypes.size but then when it tries to parse the variables it can't because there aren't any in the prime.

I think I can get past this one with more terrible conditional hacks, but this is all telling me that I am probably doing something wrong.

chbatey commented 8 years ago

Hi @Zoltu columns and variables are different so comparing against columsn isn't the right way forward here. What you need to do is use withVariableTypes which will mean that the variable size check will match.