Mihai Budiu created CALCITE-6991:
------------------------------------

             Summary: 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


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)

Reply via email to