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

Chris Baynes commented on CALCITE-1793:
---------------------------------------

After taking another look at this I've realised it could be a problem with the 
jdbc adapter for the extract function.
Direct execution of the `select extract(year from date '2008-2-23') from 
"foodmart"."employee"` fails with:

{code}
Caused by: java.lang.UnsupportedOperationException: class 
org.apache.calcite.sql.SqlSyntax$6: SPECIAL
        at org.apache.calcite.util.Util.needToImplement(Util.java:925)
        at org.apache.calcite.sql.SqlSyntax$6.unparse(SqlSyntax.java:116)
{code}

>From my understanding EXTRACT is converted to an EXTRACT_DATE containing a 
>literal and a reinterpret.
EXTRACT has an unparse method which is called in the preparation & validation 
phases and works fine.
EXTRACT_DATE.unparse is eventually called by 
JdbcToEnumerableConverter.generateSql which raises the above exception.

What's the reason for converting the extract -> extract_date? Seems like this 
should be an extract op before converting to sql which gets fired off against 
the physical db.

JdbcTest.testExtract passes right now since it doesn't use a FROM clause and so 
doesn't go through the jdbc converter.

Fixing the EXTRACT_DATE unparse method seems like the wrong thing to do. Do you 
have any ideas for the right way to go about fixing this?

> Allow RelBuilder to make calls to EXTRACT
> -----------------------------------------
>
>                 Key: CALCITE-1793
>                 URL: https://issues.apache.org/jira/browse/CALCITE-1793
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.11.0, 1.12.0
>            Reporter: Chris Baynes
>            Assignee: Julian Hyde
>            Priority: Minor
>
> EXTRACT_DATE was originally intended to be an internal function, always 
> created by translating a call to EXTRACT.
> Currently this makes the EXTRACT_DATE function rather awkward to use:
> {code}
> SqlOperator op = new SqlSpecialOperator("EXTRACT_DATE", SqlKind.EXTRACT, 2, 
> true, ReturnTypes.INTEGER, null, null);
> builder.call(op, builder.getRexBuilder().makeFlag(TimeUnitRange.YEAR), 
> builder.field(1, 0, "my_date"));
> {code}
> [~julianhyde] suggests calling EXTRACT directly and then have RelBuilder 
> invoke a convertlet to translate into calls to EXTRACT_DATE or date-time 
> arithmetic.
> Mailing list discussion:
> [http://mail-archives.apache.org/mod_mbox/calcite-dev/201705.mbox/%3CCAPSgeET9OVWkvGsGXAezqhqP3Zd2dmXxs0k-J92WZM32%2BMq3kw%40mail.gmail.com%3E]



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to