Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.21.0
-
mac os
Description
I have as sql as follows:
select cast(null as varchar) as a
The process step is :
- parse sql to SqlNode;
- convert SqlNode to RelNode;
- convert RelNode to SqlNode;
- convert SqlNode to string.
The result string is:
"SELECT NULL AS `A`\n" + "FROM (VALUES (0)) AS `t` (`ZERO`)"
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:
"SELECT CAST(NULL AS VARCHAR) AS `A`\n" + "FROM (VALUES (0)) AS `t` (`ZERO`)"
Testing code is as follows
// 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(); }
Attachments
Issue Links
- relates to
-
CALCITE-3081 Literal NULL should be generated in SqlDialect
- Open
-
CALCITE-4165 RelToSqlConverter fails on literal, untyped nulls
- Closed
- links to