Timestamp/Date offset added to already localized date returned from DB
Hi All, I see in TimestampAccessor and in DateAccessor that the timestamp/date received is already localized and the calendar is the same as the one defined in the configuration as localCalendar, then the code only checks if calendar exists and adds it's offset to the date. it creates an error in my timestamp in some scenarios. I thought that maybe it is possible to check if the timestamp/date uses the same calendar as defined in config and then not to use the offset on it, or at least calculate the offset from the timestamp object calendar and not always from 0... for example, to consider it in this code: @Override public Timestamp getTimestamp(Calendar calendar) throws SQLException { Timestamp timestamp = (Timestamp) getObject(); if (timestamp == null) { return null; } if (calendar != null) { long v = timestamp.getTime(); v -= calendar.getTimeZone().getOffset(v); timestamp = new Timestamp(v); } return timestamp; } WDYT? Thanks, Ayelet
Re: Advise on ClassCastException in Linq4j$EnumeratorIterator
+ Calcite support mailing list. Hi again, I didn't receive any response from you guys, but I continued to debug this today and managed to print the generated code and I saw a weird casting that might explain what happens there: public Object current() { final Object[] current = (Object[]) inputEnumerator.current(); return* (java.sql.Timestamp) *current[8] == null ?* (Long)* null : *Long.valueOf*(org.apache.calcite.avatica.util.DateTimeUtils.unixDateExtract(org.apache.calcite.avatica.util.TimeUnitRange.DAY, org.apache.calcite.avatica.util.DateTimeUtils.floorDiv((Long) current[8], 8640L))); } public Class getElementType() { return *java.lang.Long.class*; } I marked in *bold* the interesting casting that happens there that I need your help understanding: it seems that the code casts the value into long and then re-casts it to timestamp only to return as long, as you can see the element type is marked as long... Do you know why the generated code was generated this way? the field is TIMESTAMP and the return value from the SQL function should be long... Hope you are all well. Thanks! Ayelet On Mon, Apr 27, 2020 at 4:49 PM Ayelet Morris 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 > > > > > > > > >
Re: Advise on ClassCastException in Linq4j$EnumeratorIterator
Sorry about the last email, it was a bit early... I found the exact location of the exception, in the current() method you can see the wrong cast: DateTimeUtils.floorDiv(*(Long) current[8]*, 8640L)) As I explained earlier, the type of the field is TIMESTAMP, and it cannot be cast to long this way... please advise On Tue, May 5, 2020 at 7:27 AM Ayelet Morris wrote: > + Calcite support mailing list. > > Hi again, > > I didn't receive any response from you guys, but I continued to debug this > today and managed to print the generated code and I saw a weird casting > that might explain what happens there: > public Object current() { > final Object[] current = (Object[]) > inputEnumerator.current(); > return* (java.sql.Timestamp) *current[8] == null ?* (Long)* > null : > *Long.valueOf*(org.apache.calcite.avatica.util.DateTimeUtils.unixDateExtract(org.apache.calcite.avatica.util.TimeUnitRange.DAY, > org.apache.calcite.avatica.util.DateTimeUtils.floorDiv((Long) current[8], > 8640L))); > } > > public Class getElementType() { >return *java.lang.Long.class*; > } > > > I marked in *bold* the interesting casting that happens there that I need > your help understanding: > it seems that the code casts the value into long and then re-casts it to > timestamp only to return as long, as you can see the element type is marked > as long... > Do you know why the generated code was generated this way? the field is > TIMESTAMP and the return value from the SQL function should be long... > > Hope you are all well. > Thanks! > Ayelet > > On Mon, Apr 27, 2020 at 4:49 PM 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 >> >> >> >> >> >> >> >> >>
Advise on ClassCastException in Linq4j$EnumeratorIterator
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
[jira] [Created] (CALCITE-2795) New Avatica version doesn't support "list" type in query
Ayelet Morris created CALCITE-2795: -- Summary: New Avatica version doesn't support "list" type in query Key: CALCITE-2795 URL: https://issues.apache.org/jira/browse/CALCITE-2795 Project: Calcite Issue Type: Bug Components: avatica Affects Versions: 1.18.0, 1.17.0 Reporter: Ayelet Morris I created a simple POJO that has an id and a list and created a simple select query from it, I received the following exception, it seems that in previous versions (we used avatica 1.9 with calcite 1.11 before this upgrade) the list type was detected as "OTHER" type and the query worked, now it is marked as a Scalar but somehow finds its way to the "array" type of the types switch, then when trying to parse the column TYPE it fails (it doesn't even try to fetch the list itself) java.lang.RuntimeException: exception while executing [SELECT * FROM TypeWithList] at org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1458) at org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1426) at org.apache.calcite.test.CalciteAssert$AssertQuery.returnsUnordered(CalciteAssert.java:1464) at com.gigaspaces.jdbc.TypesTest.testSelectWithList(TypesTest.java:44) 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.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94) 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.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191) 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:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) Caused by: java.lang.RuntimeException: With materializationsEnabled=false, limit=0 at org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:573) at org.apache.calcite.test.CalciteAssert$AssertQuery.returns(CalciteAssert.java:1450) ... 33 more Caused by: java.sql.SQLException: Error while executing SQL "SELECT * FROM TypeWithList": org.apache.calcite.avatica.ColumnMetaData$ScalarType cannot be cast to org.apache.calcite.avatica.ColumnMetaData$ArrayType 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:163) at org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:227) at org.apache.calcite.test.CalciteAssert.assertQuery(CalciteAssert.java:541) ... 34 more Caused by: java.lang.ClassCastException: org.apache.calcite.avatica.