You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Mihai Budiu (Jira)" <ji...@apache.org> on 2025/05/14 19:17:00 UTC
[jira] [Resolved] (CALCITE-6991) Validator cannot infer type for COALESCE when call is not expanded
[ https://issues.apache.org/jira/browse/CALCITE-6991?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Mihai Budiu resolved CALCITE-6991.
----------------------------------
Resolution: Fixed
Fixed in [https://github.com/apache/calcite/commit/e9f7dfc318b15198df617a9cdb0f477d30997517]
Thank you for the fix [~juntaozhang]
Thank you for the review [~jensen]
> Validator cannot infer type for COALESCE when call is not expanded
> ------------------------------------------------------------------
>
> Key: CALCITE-6991
> URL: https://issues.apache.org/jira/browse/CALCITE-6991
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.39.0
> Reporter: Mihai Budiu
> Priority: Minor
> Labels: pull-request-available
>
> By default the validator rewrites calls such as COALESCE into CASE.
> This is controlled by the callRewrite() flag of SqlValidator.Config.
> When this flag is turned off, the validator will throw on an expression such as the following:
> {code:sql}
> SELECT COALESCE(DATE '2020-01-01', '2020-01-01')
> {code}
> This is the stack trace:
> {code}
> java.lang.IllegalArgumentException: Cannot infer return type for COALESCE; operand types: [DATE, CHAR(10)]
> at org.apache.calcite.sql.SqlOperator.inferReturnType(SqlOperator.java:566)
> at org.apache.calcite.sql.SqlOperator.validateOperands(SqlOperator.java:531)
> at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:350)
> at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:232)
> at org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:7100)
> at org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:7087)
> at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:168)
> at org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:2034)
> at org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:2021)
> {code}
> COALESCE should insert the same implicit casts that the expansion does if the two expressions are truly equivalent.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)