danny0405 commented on a change in pull request #1338: [CALCITE-3210] Fix the
bug that RelToSqlConverter converts "cast(null as $type)" just as null
URL: https://github.com/apache/calcite/pull/1338#discussion_r312784393
##########
File path:
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
##########
@@ -3694,6 +3694,51 @@ private void checkLiteral2(String expression, String
expected) {
assertTrue(postgresqlDialect.supportsDataType(integerDataType));
}
+ @Test public void testSelectNull() {
+ String query = "SELECT CAST(NULL AS INT)";
+ final String expected = "SELECT CAST(NULL AS INTEGER)\n"
+ + "FROM (VALUES (0)) AS \"t\" (\"ZERO\")";
+ sql(query).ok(expected);
+ // validate
+ sql(expected).exec();
+ }
+
+ @Test public void testSelectNullWithCount() {
+ String query = "SELECT COUNT(CAST(NULL AS INT))";
+ final String expected = "SELECT COUNT(CAST(NULL AS INTEGER))\n"
+ + "FROM (VALUES (0)) AS \"t\" (\"ZERO\")";
+ sql(query).ok(expected);
+ // validate
+ sql(expected).exec();
+ }
+
+ @Test public void testSelectNullWithGroupBy() {
+ String query = "SELECT COUNT(CAST(NULL AS INT)) FROM (VALUES (0)) "
+ + "AS \"t\" GROUP BY CAST(NULL AS VARCHAR CHARACTER SET
\"ISO-8859-1\")";
Review comment:
Grouping by constant means there is only one group globally so we can do
some promotion of plan for some aggregate calls.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services