[ 
https://issues.apache.org/jira/browse/CALCITE-1703?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Kevin Risden updated CALCITE-1703:
----------------------------------
    Labels: pull-request-available  (was: )

> Query with BETWEEN or AGGREGATE functions on TIMESTAMP column throws 
> ClassCastException
> ---------------------------------------------------------------------------------------
>
>                 Key: CALCITE-1703
>                 URL: https://issues.apache.org/jira/browse/CALCITE-1703
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.11.0
>         Environment: Any
>            Reporter: Gangadhar Kairi
>            Priority: Major
>              Labels: pull-request-available
>
> Getting below error while executing the query on timestamp columns with 
> BETWEEN or AGGREGATE function operator.
> {noformat}
> java.sql.SQLException: Error while executing SQL "select * from "DATE" where 
> "JOINTIMES" < '2017-03-16 18:04:07.034'": java.sql.Timestamp cannot be cast 
> to java.lang.Long
>       at org.apache.calcite.avatica.Helper.createException(Helper.java:56)
>       at org.apache.calcite.avatica.Helper.createException(Helper.java:41)
>       at 
> org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
>       at 
> org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218)
>       at 
> org.apache.calcite.test.CsvTest.testTimestampGTCheck(CsvTest.java:617)
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>       at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>       at java.lang.reflect.Method.invoke(Method.java:498)
>       at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
>       at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>       at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
>       at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>       at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
>       at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
>       at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
>       at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
>       at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
>       at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
>       at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
>       at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
>       at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
>       at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
>       at 
> com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
>       at 
> com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
>       at 
> com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
>       at 
> com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>       at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>       at java.lang.reflect.Method.invoke(Method.java:498)
>       at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
> Caused by: java.lang.ClassCastException: java.sql.Timestamp cannot be cast to 
> java.lang.Long
>       at Baz$1$1.moveNext(Unknown Source)
>       at 
> org.apache.calcite.linq4j.Linq4j$EnumeratorIterator.<init>(Linq4j.java:664)
>       at org.apache.calcite.linq4j.Linq4j.enumeratorIterator(Linq4j.java:98)
>       at 
> org.apache.calcite.linq4j.AbstractEnumerable.iterator(AbstractEnumerable.java:33)
>       at org.apache.calcite.avatica.MetaImpl.createCursor(MetaImpl.java:89)
>       at 
> org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:196)
>       at 
> org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:67)
> {noformat}
> I could able to reproduce this issues in CsvTests.
>  
> Fire a test with query "select * from \"DATE\" where \"JOINTIMES\" BETWEEN '" 
> + from + "' and '" + to + "'" you will see test failing with exception.
> Root cause and fix:
> Timestamp datatype needs to be handled in the same way as the Date datatype. 
> In {{RexToLixTranslator.convert()}} method and in 
> {{PhysTypeImpl.fieldReference()}} method.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to