[ 
https://issues.apache.org/jira/browse/CALCITE-6518?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17871437#comment-17871437
 ] 

Mihai Budiu commented on CALCITE-6518:
--------------------------------------

Maybe an unrelated bug: the substr function is available in multiple libraries.
Loading one library leads to the function being resolved correctly by the 
validator.
Loading two libraries leads the validator to produce an error "No match found 
for function signature".

I never knew what the rules are for resolving a function that has signatures 
that match multiple libraries. 

> ClassCastException during validation when loading multiple libraries
> --------------------------------------------------------------------
>
>                 Key: CALCITE-6518
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6518
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.37.0
>            Reporter: Mihai Budiu
>            Priority: Minor
>
> The following test added to CalciteSqlOperatorTest will cause a 
> ClassCastException:
> {code:java}
>   @Test void testLibraries() {
>     SqlOperatorFixture sqlOperatorFixture = fixture();
>     final SqlOperatorFixture f = sqlOperatorFixture.withOperatorTable(
>             SqlLibraryOperatorTableFactory.INSTANCE
>                 .getOperatorTable(
>                     SqlLibrary.STANDARD,
>                     SqlLibrary.MYSQL,
>                     SqlLibrary.POSTGRESQL
>                 ));
>     f.checkScalar("substr('a', 1, 2)", "a", "VARCHAR(1) NOT NULL");
>   }
> {code}
> Here is the top of the stack trace:
> {code}
> class org.apache.calcite.sql.type.FamilyOperandTypeChecker cannot be cast to 
> class org.apache.calcite.sql.type.SqlOperandMetadata 
> (org.apache.calcite.sql.type.FamilyOperandTypeChecker and 
> org.apache.calcite.sql.type.SqlOperandMetadata are in unnamed module of 
> loader 'app')
> java.lang.ClassCastException: class 
> org.apache.calcite.sql.type.FamilyOperandTypeChecker cannot be cast to class 
> org.apache.calcite.sql.type.SqlOperandMetadata 
> (org.apache.calcite.sql.type.FamilyOperandTypeChecker and 
> org.apache.calcite.sql.type.SqlOperandMetadata are in unnamed module of 
> loader 'app')
>       at 
> org.apache.calcite.sql.validate.implicit.TypeCoercionImpl.userDefinedFunctionCoercion(TypeCoercionImpl.java:601)
>       at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:313)
>       at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:231)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:6789)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:6776)
>       at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:167)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:2006)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1993)
>       at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:276)
>       at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:474)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:6446)
>       at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:144)
>       at org.apache.calcite.sql.SqlNode.validateExpr(SqlNode.java:275)
>       at org.apache.calcite.sql.SqlOperator.validateCall(SqlOperator.java:474)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateCall(SqlValidatorImpl.java:6446)
>       at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:144)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:1143)
>       at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:849)
>       at 
> org.apache.calcite.sql.test.AbstractSqlTester.parseAndValidate(AbstractSqlTester.java:162)
>       at 
> org.apache.calcite.sql.test.AbstractSqlTester.validateAndThen(AbstractSqlTester.java:250)
> {code}
> Calcite behaves correctly if either the MYSQL or the POSTGRES libraries are 
> not supplied.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to