You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Zhengqiang Duan (Jira)" <ji...@apache.org> on 2021/06/11 07:27:00 UTC

[jira] [Commented] (CALCITE-3018) User defined scalar function which returns a Date/Timestamp value causes error.

    [ https://issues.apache.org/jira/browse/CALCITE-3018?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17361486#comment-17361486 ] 

Zhengqiang Duan commented on CALCITE-3018:
------------------------------------------

[~pzw2018] Hello, have you solved it? I also encountered the same problem with version `1.26.0`. 

> User defined scalar function which returns a Date/Timestamp value causes error.
> -------------------------------------------------------------------------------
>
>                 Key: CALCITE-3018
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3018
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.19.0
>            Reporter: Yincheng Fang
>            Priority: Major
>
> I've defined a user defined function that returns a date or timestamp and register it on root schema :
> {code:java}
>     public static java.sql.Date test(long value) {
>         return new java.sql.Date(value);
>     }{code}
>  
> {code:java}
>     rootSchema.add("my_test", ScalarFunctionImpl.create(CalciteTest.class, "test")); {code}
>  
> If I use this function in the select part of a query as the only column, the result works fine:
> {code:java}
>     select my_test(1)  from northwind.product{code}
> However, if I add an additional column in the select part, the error occurs:
> {code:java}
>     select my_test(1), 2  from northwind.product{code}
> Error message:
>  
> {code:java}
>  Exception in thread "main" java.lang.ClassCastException: java.sql.Date cannot be cast to java.lang.Number
>     at org.apache.calcite.avatica.util.AbstractCursor$NumberAccessor.getNumber(AbstractCursor.java:726)
>     at org.apache.calcite.avatica.util.AbstractCursor$DateFromNumberAccessor.getDate(AbstractCursor.java:915)
>     at org.apache.calcite.avatica.AvaticaSite.get(AvaticaSite.java:326)
>     at org.apache.calcite.avatica.AvaticaResultSet.getObject(AvaticaResultSet.java:393){code}
>  
>  I tried with calcite.debug=true, and the difference seems as follows:
>  * 1 column
>  
> {code:java}
> /*  51 */             public Object current() {
> /*  52 */               return org.apache.calcite.runtime.SqlFunctions.toIntOptional(CalciteTest.test(1));
> /*  53 */             }{code}
>  
>  * 2 columns
> {code:java}
> /*  51 */             public Object current() {
> /*  52 */               return new Object[] {
> /*  53 */                   CalciteTest.test(1),
> /*  54 */                   2};
> /*  55 */             }{code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)