In the Enumerable convention, values of SQL datatype TIMESTAMP are represented 
using Java values of type java.lang.Long.

Not sure exactly what you’re doing wrong, but your query (or other code) that 
gets the values into Java should be getting them as Long, not as 
java.sql.Timestamp values. This issue has occurred before, and a search of JIRA 
or the dev@ archive might yield results.

Julian




> On Apr 27, 2020, at 6:49 AM, Ayelet Morris <ayelet.mor...@gigaspaces.com> 
> wrote:
> 
> Hi Calcite Developers,
> Hope you are all doing well at this crazy time.
> 
> I have a question regarding Linq4j$EnumeratorIterator
> throwing ClassCastException.
> *Background*: I'm running a Tableau testing framework called TDVT (it's in
> beta) in order to test our product's JDBC connector.  Our product uses
> Calcite 1.21.0 and Avatics 1.15.0.
> 
> I encountered this class cast exception when running timestamp related sql
> functions (I have about 127 different SQLs failing with the same class cast
> exception).
> *My SQL**:* select DAYOFMONTH(datetime0) from Calcs
> datetime0 is a java.sql.Timestamp field in my POJO, the data in the CSV I'm
> using to fill in the POJO is written like this: '2004-07-23 21:13:37'
> *The exception:*
> ClassCastException: java.sql.Timestamp cannot be cast to java.lang.Long
> at Baz$1$1.current(Unknown Source)
> at org.apache.calcite.linq4j.Linq4j$EnumeratorIterator.next(Linq4j.java:683)
> at
> org.apache.calcite.avatica.util.IteratorCursor.next(IteratorCursor.java:46)
> at
> org.apache.calcite.avatica.AvaticaResultSet.next(AvaticaResultSet.java:217)
> at com.gigaspaces.jdbc.TimestampTest.test(TimestampTest.java:64)
> 
> This exception is thrown when trying to perform "next()"
> I cannot debug the generated code... I just see it being thrown there.
> 
> I looked into the generated code for performing this (and similar) sql
> function and couldn't find a specific time format that is required, but in
> the documentation I saw the use of java.sql.Date as the function type, I
> tried to run my test with Date field I have in my POJO and it did return a
> correct result.
> I suspect it might not be compatible with Timestamp data type, though I saw
> in your tests you do test with timestamp '2008-1-23 12:12:12', I didn't try
> to run the test in the DruidAdapter suite but I saw that you are using a
> timestamp based column there.
> 
> Do you know of a reason for this exception at this location? Did you see
> this exception before at this location? Do you have any idea where I should
> look for further information/clues?
> 
> Thanks,
> Ayelet

Reply via email to