java.lang.IllegalArgumentException in Column metadata

952 views
Skip to first unread message

Karthick V

unread,
Jul 5, 2017, 6:18:02 AM7/5/17
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi,

I have been using Datastax Java Driver for a while(v3.0.1).Recently I faced "java.lang.IllegalArgumentException" while accessing one of the column value from the ResultSet by 

Row.getString(ColumnName).

Exception Trace
Caused by: java.lang.IllegalArgumentException: SampleColumn is not a column defined in this metadata at com.datastax.driver.core.ColumnDefinitions.getAllIdx(ColumnDefinitions.java:266) at com.datastax.driver.core.ColumnDefinitions.getFirstIdx(ColumnDefinitions.java:272) at com.datastax.driver.core.ArrayBackedRow.getIndexOf(ArrayBackedRow.java:81) at com.datastax.driver.core.AbstractGettableData.getString(AbstractGettableData.java:159) ... 38 more
 
Later I tried to reproduce this issue but unable to do so. Does it due to connections issues like https://datastax-oss.atlassian.net/browse/JAVA-546 ?

 

 


Andrew Tolbert

unread,
Jul 5, 2017, 11:00:42 AM7/5/17
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi Karthick,

I think the issue might be that your column name is mixed case (has capital letters).  Because of this you may need to quote your column name, i.e.:

cluster.getKeyspace(keyspace).getColumn("\"SampleColumn\"");

The driver (like cqlsh) requires this as it considers identifiers as case insensitive unless quoted so if you provide SampleColumn the driver normalizes it to samplecolumn (reference):

CQL identifiers, including keyspace, table and column ones, are case insensitive by default. Case sensitive identifiers can however be provided by enclosing the identifier in double quotes (see the CQL documentation for details). If you are using case sensitive identifiers, this method can be used to enclose such identifiers in double quotes, making them case sensitive.

You could also use Metadata.quoteIfNecessary if you want to programmatically add quotes where needed.

One interesting thing is the driver logs exactly what you provide, instead of what it tries.  i.e. if you pass in SampleColumn it should return what it tries (samplecolumn) to fetch instead.  I created JAVA-1545 to improve that.

Thanks,
Andy

Andy Tolbert

unread,
Jul 5, 2017, 11:02:34 AM7/5/17
to DataStax Java Driver for Apache Cassandra User Mailing List
Correcting myself, I made a small mistake in my example:

cluster.getKeyspace(keyspace).getColumn("\"SampleColumn\"");

should be:

cluster.getKeyspace(keyspace).getTable(table).getColumn("\"SampleColumn\"");

--
You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.
Reply all
Reply to author
Forward
0 new messages