adejanovski / cassandra-jdbc-wrapper

A JDBC wrapper for the Datastax Java Driver for Cassandra
Apache License 2.0
53 stars 36 forks source link

CHAR_OCTET_LENGTH null as default value results in exception #7

Closed enekofb closed 8 years ago

enekofb commented 8 years ago

Hi Alexander, I am on the branch 3.0.3-spanshot which fixes the previous bug. However, I have found that that in MetadataResultSets: 170 there is the definition for charol as follows

//CHAR_OCTET_LENGTH
Integer charol = null;
if (jtype instanceof JdbcAscii || jtype instanceof JdbcUTF8) charol = Integer.MAX_VALUE;

and for those datatype that are not defined (i.e. JdbcDate), when trying to create column based on retrieved metadata, results in the following exception

Caused by: java.lang.NumberFormatException: For input string: "null" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_91] at java.lang.Integer.parseInt(Integer.java:580) ~[na:1.8.0_91] at java.lang.Integer.valueOf(Integer.java:766) ~[na:1.8.0_91] at liquibase.snapshot.CachedRow.getInt(CachedRow.java:38) ~[liquibase-core-3.4.1.jar:na] at liquibase.snapshot.jvm.ColumnSnapshotGenerator.readDataType(ColumnSnapshotGenerator.java:315) ~[liquibase-core-3.4.1.jar:na] at liquibase.snapshot.jvm.ColumnSnapshotGenerator.readColumn(ColumnSnapshotGenerator.java:216) ~[liquibase-core-3.4.1.jar:na] at liquibase.snapshot.jvm.ColumnSnapshotGenerator.addTo(ColumnSnapshotGenerator.java:111) ~[liquibase-core-3.4.1.jar:na]

My workaround was just to set it up by default to max_value (is that wrong?) and it worked

Integer charol = Integer.MAX_VALUE;

Cheers,

adejanovski commented 8 years ago

Merged your PR to fix your issue, although the JDBC interface states that CHAR_OCTET_LENGTH should return null for non char fields. We can revert if we see that it eventually breaks something else. Did the issue arise on a Date/Timestamp field only ?

enekofb commented 8 years ago

Hi, Not only in Date, but it was primarily on the one that I have noticed it. With merge it is fixed (liquibase).