Description
The generated code for sql queries that filter on DATE, TIME or TIMESTAMP fields is incorrect.
The problem can easily be reproduced with the csv example using a statement such as (patch with unit test in attachment).
select EMPNO from "DATE" where JOINEDAT is not null;
or (similar but not exactly the same problem)
select EMPNO from "DATE" where JOINEDAT > {d '1990-01-01'};
In case of the not-null filter, the generated code contains
if (org.apache.calcite.runtime.SqlFunctions.internalToDate(((Object[]) inputEnumerator.current())[1]) != null) {...}
This seems to be generated in the assumption that the internal representation is a long, rather than a java.sql.Date, java.sql.Time or java.sql.Timestamp.
So first question: is the enumerator supposed to return java.sql.Date, java.sql.Time and java.sql.Timestamp values or simply longs (epoch millis). Currently it returns java.sql.* types and that is definitely how it used to work in older calcite versions.
In that case the generated code should probably not contain the internalToDate function?
However the mere existence of that function makes me think that maybe the enumerators are supposed to return long values. But in that case the generated code is also wrong, it should probably be (added cast):
if (org.apache.calcite.runtime.SqlFunctions.internalToDate((Long) ((Object[]) inputEnumerator.current())[1]) != null) {...}
With the second sql query (greater than filter), the generated code actually does contain a cast to Integer (which fails):
final Integer inp1_ = (Integer) ((Object[]) inputEnumerator.current())[1]; if (inp1_ != null && inp1_.intValue() > 7305) {...}
The cast fails with java.sql.Date cannot be cast to java.lang.Integer
Attachments
Attachments
Issue Links
- duplicates
-
CALCITE-1054 NPE caused by wrong code generation for Timestamp fields
- Closed
- relates to
-
CALCITE-1673 Query with ORDER BY or GROUP BY on TIMESTAMP column throws CompileException
- Closed