[
https://issues.apache.org/jira/browse/CALCITE-5271?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17601425#comment-17601425
]
Parag Jain commented on CALCITE-5271:
-------------------------------------
I think you are right, postgres does not support Floor with timestamp and
supports only date_trunc. My bad here, I guess I got confused by the
unparseCall method in PostgresqlSqlDialect method here
<https://github.com/apache/calcite/blob/main/core/src/main/java/org/apache/calcite/sql/dialect/PostgresqlSqlDialect.java#L122>
and
the fact that duckdb is postgres dialect compatible and Floor(Timestamp to
TIMEUNIT) is supported by it. I am using calcite lib in front of duckdb.
But in any case since the PostgresqlSqlDialect unparseCall method is
specifically handling this syntax, shouldn't the unparsing of this call
just work ?
> Error while unparsing FLOOR function using Postgres dialect
> -----------------------------------------------------------
>
> Key: CALCITE-5271
> URL: https://issues.apache.org/jira/browse/CALCITE-5271
> Project: Calcite
> Issue Type: Bug
> Reporter: Parag Jain
> Assignee: Mou Wu
> Priority: Minor
>
> 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*
> getting following exception -
>
> {code:java}
> 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){code}
> Looks like a bug as the "Year" token gets parsed to SqlIntervalQualifier but
> expectation is of SqlLiteral. Here's a
> [PR|https://github.com/apache/calcite/pull/2897] with test case to reproduce
> the issue.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)