I think the biggest difference is I am calling toSql on SqlNode whereas the test case calls toSql on RelNode here <https://github.com/apache/calcite/blob/main/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java#L6724> - SqlCall for the FLOOR function in the RelNode contains YEAR as SqlLiteral in operandList so it passes. This means its failing in unparsing the parsed SqlCall which contains "YEAR" as SqlIntervalQualifier. Let me know if you need more information. Thanks
On Thu, Sep 1, 2022 at 8:57 PM Benchao Li <libenc...@apache.org> wrote: > Hi Parag, > > I added this test to `RelToSqlConverterTest`: > ```java > @Test void testTest() { > final String sql = "select FLOOR(TIMESTAMP '2022-08-01' TO Year)"; > final String expected = "SELECT DATE_TRUNC('YEAR', TIMESTAMP '2022-08-01 > 00:00:00')\nFROM " + > "(VALUES (0)) AS \"t\" (\"ZERO\")"; > sql(sql) > .withPostgresql() > .ok(expected); > } > ``` > And it passed both on the latest main branch and 1.30.0 tag. > > I don't know what I'm missing, could you give us an example which could > reproduce this? > > > Parag Jain <pja...@apache.org> 于2022年9月1日周四 19:34写道: > > > Using Calcite(1.30.0) to parse this query - select FLOOR(TIMESTAMP > > '2022-08-01' TO Year) > > > > Parsing is successful but while doing > > `toSqlString(PostgresqlSqlDialect.DEFAULT).getSql()`. on the parsed > SqlNode > > I am getting following exception - > > > > Request failed: java.lang.ClassCastException: class > > org.apache.calcite.sql.SqlIntervalQualifier cannot be cast to class > > org.apache.calcite.sql.SqlLiteral > > at > > > > > org.apache.calcite.sql.dialect.PostgresqlSqlDialect.unparseCall(PostgresqlSqlDialect.java:128) > > at org.apache.calcite.sql.SqlCall.unparse(SqlCall.java:126) > > at > > > > > org.apache.calcite.sql.pretty.SqlPrettyWriter$FrameImpl.list2(SqlPrettyWriter.java:1303) > > at > > > > > org.apache.calcite.sql.pretty.SqlPrettyWriter$FrameImpl.list(SqlPrettyWriter.java:1283) > > at > > > > > org.apache.calcite.sql.pretty.SqlPrettyWriter.list(SqlPrettyWriter.java:1080) > > at > > > > > org.apache.calcite.sql.SqlSelectOperator.unparse(SqlSelectOperator.java:154) > > at org.apache.calcite.sql.SqlDialect.unparseCall(SqlDialect.java:460) > > at > > > > > org.apache.calcite.sql.dialect.PostgresqlSqlDialect.unparseCall(PostgresqlSqlDialect.java:137) > > at org.apache.calcite.sql.SqlSelect.unparse(SqlSelect.java:261) > > at org.apache.calcite.sql.SqlNode.toSqlString(SqlNode.java:156) > > at org.apache.calcite.sql.SqlNode.toSqlString(SqlNode.java:178) > > at org.apache.calcite.sql.SqlNode.toSqlString(SqlNode.java:187) > > > > Looks like a bug as the "Year" token gets parsed to SqlIntervalQualifier > > but expectation is of SqlLiteral ? > > > > > -- > > Best, > Benchao Li >