You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Danny Chan (JIRA)" <ji...@apache.org> on 2019/08/01 01:46:00 UTC

[jira] [Comment Edited] (CALCITE-3081) Literal NULL should be generated in SqlDialect

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

Danny Chan edited comment on CALCITE-3081 at 8/1/19 1:45 AM:
-------------------------------------------------------------

It solves partially, if this select statement union with another one, for example:
{code:sql}
select null from t1
union
select a from t2 -- a is int type
{code}
with implicit type cast, we would finally got query:
{code:sql}
select cast(null as int) from t1
union
select a from t2 -- a is int type
{code}
For single select statement, we did have no way to deduce the intended type. There is only one case we actually can do, for "select null from EMP" we can deduce the null type if the EMP has only one column, but i think this is a special case.


was (Author: danny0405):
It solves partially, if this select statement union with another one, for example:
{code:sql}
select null from t1
union
select a from t2 -- a is int type
{code}
with implicit type cast, we would finally got query:
{code:sql}
select cast(null as int) from t1
union
select a from t2 -- a is int type
{code}
For single select statement, we did have no way to deduce the intended type.

> Literal NULL should be generated in SqlDialect
> ----------------------------------------------
>
>                 Key: CALCITE-3081
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3081
>             Project: Calcite
>          Issue Type: Bug
>    Affects Versions: 1.19.0
>            Reporter: Feng Zhu
>            Priority: Minor
>
> In Calcite, this simple query will throw exception during validation, even it is ok in many databases.
> {code:java}
> Query:
> final String query = "select NULL as col "
>     + "from \"foodmart\".\"product\"";
> Exception
> org.apache.calcite.tools.ValidationException: org.apache.calcite.runtime.CalciteContextException: From line 1, column 8 to line 1, column 11: Illegal use of 'NULL'
> {code}
> The right way to use 'NULL' in Calcite is:
> {code:java}
> final String query = "select cast(NULL as integer) as col "
>     + "from \"foodmart\".\"product\"";
> {code}
> However,  the converted query by *RelToSqlConverter* is illegal in Calcite.
> {code:java}
> SELECT NULL AS \"COL\"
> FROM \"foodmart\".\"product\"
> {code}
> The issue is trivial, but it is against to general sense. Maybe we can generate NULL literal in SqlDialect?



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)