You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (JIRA)" <ji...@apache.org> on 2019/07/29 17:42:00 UTC

[jira] [Updated] (CALCITE-3210) JDBC adapter should generate "CAST(NULL AS type)" rather than "NULL"

     [ https://issues.apache.org/jira/browse/CALCITE-3210?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Julian Hyde updated CALCITE-3210:
---------------------------------
    Summary: JDBC adapter should generate "CAST(NULL AS type)" rather than "NULL"  (was: RelToSqlConverter convert "cast(null as $type)" just as  null )

> JDBC adapter should generate "CAST(NULL AS type)" rather than "NULL"
> --------------------------------------------------------------------
>
>                 Key: CALCITE-3210
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3210
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.21.0
>         Environment: mac os
>            Reporter: Wang Weidong
>            Assignee: Wang Weidong
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: next
>
>          Time Spent: 4h
>  Remaining Estimate: 0h
>
> I have as sql as follows: 
> {code:java}
> select cast(null as varchar) as a{code}
> The process step is : 
>  # parse sql to SqlNode;
>  # convert SqlNode to RelNode;
>  # convert RelNode to SqlNode;
>  # convert SqlNode to string.
> The result string is:
> {code:java}
> "SELECT NULL AS `A`\n"
>             + "FROM (VALUES  (0)) AS `t` (`ZERO`)"{code}
> Finally, I found that the result string is absent of cast statement for  "null" which causes the result sql to be invalid.
> Actually, the result I expect is like:
> {code:java}
> "SELECT CAST(NULL AS VARCHAR) AS `A`\n"
>             + "FROM (VALUES  (0)) AS `t` (`ZERO`)"{code}
>  
> Testing code is as follows
> {code:java}
> // code placeholder
> @Test
> public void testSeletNull() throws SqlParseException {
>     String sql = "select cast(null as varchar) as a";
>     SqlNode sqlNode = parserContext.parseStmt(sql);
>     RelNode relNode = parserContext.getSqlToRelConverter().convertQuery(sqlNode, true, true).rel;
>     SqlNode sqlNodeNew = toSqlNode(relNode);
>     Assert.assertEquals(sqlNodeNew.toString(), "SELECT NULL AS `A`\n"
>             + "FROM (VALUES  (0)) AS `t` (`ZERO`)");
> }
> private static SqlNode toSqlNode(RelNode root) {
>   SqlDialect dialect = MysqlSqlDialect.DEFAULT;
>   RelToSqlConverter converter = new RelToSqlConverter(dialect == null ? dialect : dialect);
>   return converter.visitChild(0, root).asStatement();
> }
> {code}



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