[
https://issues.apache.org/jira/browse/CALCITE-3019?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
fangyc updated CALCITE-3019:
----------------------------
Description:
I've defined a user defined function that returns a date or timestamp and
register it on root schema :
{{ public static java.sql.Date test(long value) {}}
{{ return new java.sql.Date(value);}}
{{ }}}
{{ rootSchema.add("my_test", ScalarFunctionImpl.create(CalciteTest.class,
"test")); }}
If I use this function in the select part of a query as the only column, the
result works fine:
{{ select my_test(1) from northwind.product}}
However, if I add an additional column in the select part, the error occurs:
{{ select my_test(1), 2 from northwind.product}}
Error message:
{quote}{{ 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)}}{quote}
I tried with calcite.debug=true, and the difference seems as follows:
* 1 column
{{/* 51 */ public Object current() {}}
{{/* 52 */ return
org.apache.calcite.runtime.SqlFunctions.toIntOptional(CalciteTest.test(1));}}
{{/* 53 */ }}}
* 2 columns
{{/* 51 */ public Object current() {}}
{{/* 52 */ return new Object[] {}}
{{/* 53 */ CalciteTest.test(1),}}
{{/* 54 */ 2};}}
{{/* 55 */ }}}
was:
I've defined a user defined function that returns a date or timestamp and
register it on root schema :
{{ public static java.sql.Date test(long value) {}}
{{ return new java.sql.Date(value);}}
{{ }}}
{{ rootSchema.add("my_test", ScalarFunctionImpl.create(CalciteTest.class,
"test")); }}
If I use this function in the select part of a query as the only column, the
result works fine:
{{ select my_test(1) from northwind.product}}
However, if I add an additional column in the select part, the error occurs:
{{ select my_test(1), 2 from northwind.product}}
Error message:
{quote}{{ 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)}}{quote}
I tried with calcite.debug=true, and the difference seems as follows:
* 1 column
{quote}{{/* 51 */ public Object current() {}}
{{/* 52 */ return
org.apache.calcite.runtime.SqlFunctions.toIntOptional(CalciteTest.test(1));}}
{{/* 53 */ }}}{quote} * 2 columns
{quote}{{/* 51 */ public Object current() {}}
{{/* 52 */ return new Object[] {}}
{{/* 53 */ CalciteTest.test(1),}}
{{/* 54 */ 2};}}
{{/* 55 */ }}}{quote}
> User defined scalar function which returns a Date/Timestamp value causes
> error.
> -------------------------------------------------------------------------------
>
> Key: CALCITE-3019
> URL: https://issues.apache.org/jira/browse/CALCITE-3019
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.19.0
> Reporter: fangyc
> Priority: Major
>
> I've defined a user defined function that returns a date or timestamp and
> register it on root schema :
> {{ public static java.sql.Date test(long value) {}}
> {{ return new java.sql.Date(value);}}
> {{ }}}
>
> {{ rootSchema.add("my_test", ScalarFunctionImpl.create(CalciteTest.class,
> "test")); }}
>
> If I use this function in the select part of a query as the only column, the
> result works fine:
> {{ select my_test(1) from northwind.product}}
> However, if I add an additional column in the select part, the error occurs:
> {{ select my_test(1), 2 from northwind.product}}
> Error message:
> {quote}{{ 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)}}{quote}
>
> I tried with calcite.debug=true, and the difference seems as follows:
> * 1 column
> {{/* 51 */ public Object current() {}}
> {{/* 52 */ return
> org.apache.calcite.runtime.SqlFunctions.toIntOptional(CalciteTest.test(1));}}
> {{/* 53 */ }}}
> * 2 columns
> {{/* 51 */ public Object current() {}}
> {{/* 52 */ return new Object[] {}}
> {{/* 53 */ CalciteTest.test(1),}}
> {{/* 54 */ 2};}}
> {{/* 55 */ }}}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)