CQL binding check on updates wrong
----------------------------------
Key: CASSANDRA-2748
URL: https://issues.apache.org/jira/browse/CASSANDRA-2748
Project: Cassandra
Issue Type: Bug
Components: API
Affects Versions: 0.8.0
Environment: Windows XP, 32 bit, Cassandra 0.8.0 version with CQL
driver
Reporter: Lars Wunderlich
I'm trying to insert byte data into a column with an ascii name in CQL. The
existing unit test for prepared statement didn't help me really. If my
understanding is correct it should be possible to have different types in name
and value elements of a column. However the task fails and I think it's because
of the applyDualBindings() check in
org.apache.cassandra.cql.jdbc.CassandraPreparedStatement.makeUpdate() method.
The method's task is (in my understanding) to check the statement parameters
and convert them into a string representation (an unnecessary overhead by the
way in my mind which just costs performance, however) according to the meta
data received for the current column family.
The check says (in cql 1.0.3-src.jar) that the variable leftComp(arator) and
leftVald(iator?) both get the same Abstract type (those of the comparator). In
the end, column name and column value must be of the same type to be parsable.
Otherwise the parsing will fail:
AbstractType leftComp = connection.decoder.getComparator(keyspace,
columnFamily);
if (leftComp == null)
throw new SQLException("Could not find comparator for " + keyspace + "." +
columnFamily);
AbstractType leftVald = connection.decoder.getComparator(keyspace,
columnFamily); <== ???
if (leftVald == null)
throw new SQLException("Could not find validator for " + keyspace + "." +
columnFamily);
left = applyDualBindings(left, leftComp, leftVald, params);
where the called dualBindings methods tries to distinguish left and right part
of the assignment and their types in contrast to the calling method.
private static String applyDualBindings(String q, AbstractType ltype,
AbstractType rtype, ParameterIterator params) throws SQLException
{
[...]
Object param = params.nextParam();
AbstractType type = left ? ltype : rtype;
String stringParam = makeCqlString(type.toString(param));
if (type.needsQuotes())
stringParam = "'" + stringParam + "'";
sb.append(stringParam);
[...]
but in fact, ltype and rtype will always be equal because of the assignment in
the makeUpdate() method above. Downloading the latest version of
CassandraPreparedStatement from Git also shows the same behaviour, which is in
my understanding wrong. Please carefully check my thoughts.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira