[ https://issues.apache.org/jira/browse/CALCITE-3210?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Danny Chan resolved CALCITE-3210. --------------------------------- Fix Version/s: (was: next) 1.21.0 Resolution: Fixed Fixed in [e863294|https://github.com/apache/calcite/commit/e863294ccfbed9dd520c999f75ed0bbe03f9fb1d], thanks for your PR, [~wangweidong] ! > 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: 1.21.0 > > Time Spent: 9h 40m > 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 (v8.3.2#803003)