You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (Jira)" <ji...@apache.org> on 2023/03/13 05:59:00 UTC

[jira] [Commented] (CALCITE-5569) Functions with 'SPECIAL' SqlSyntax could not be created in SqlLibraryOperators

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

Julian Hyde commented on CALCITE-5569:
--------------------------------------

I may have been hasty in declaring this not-a-bug. But I would like to understand why these fairly normal functions are being created with SPECIAL syntax. Maybe we need to rethink that 'special syntax' means.

> Functions with 'SPECIAL'  SqlSyntax could not be created in SqlLibraryOperators
> -------------------------------------------------------------------------------
>
>                 Key: CALCITE-5569
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5569
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Zou
>            Priority: Major
>             Fix For: 1.34.0
>
>
> I want to add a function with 'SPECIAL'  SqlSyntax in SqlLibraryOperators, but I get a function not found exception
> {code:java}
> org.apache.calcite.runtime.CalciteContextException: From line 1, column 9 to line 1, column 35: No match found for function signature TRY_CAST(<CHARACTER>, <NUMERIC>)
> 	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> 	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
> 	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
> 	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
> 	at org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:505)
> 	at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:945)
> 	at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:930)
> 	at org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(SqlValidatorImpl.java:5464)
> 	at org.apache.calcite.sql.validate.SqlValidatorImpl.handleUnresolvedFunction(SqlValidatorImpl.java:1983)
> 	at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:329)
> 	at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:231)
> 	at org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:6521)
> 	at org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:6508)
> 	at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:161)
> 	at org.apache.calcite.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1897)
> 	at org.apache.calcite.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1882)
> 	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:6171)
> 	at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:138)
> 	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:6171)
> 	at org.apache.calcite.sql.SqlCall.validate(SqlCall.java:138)
> 	at org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:1081)
> 	at org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:787)
> 	at org.apache.calcite.sql.test.AbstractSqlTester.parseAndValidate(AbstractSqlTester.java:160)
> 	at org.apache.calcite.sql.test.AbstractSqlTester.validateAndApply(AbstractSqlTester.java:256)
> 	at org.apache.calcite.sql.test.AbstractSqlTester.getColumnType(AbstractSqlTester.java:134)
> 	at org.apache.calcite.sql.test.AbstractSqlTester.check(AbstractSqlTester.java:234)
> 	at org.apache.calcite.test.SqlOperatorTest$TesterImpl.check(SqlOperatorTest.java:10091)
> 	at org.apache.calcite.sql.test.SqlTester.check(SqlTester.java:159)
> 	at org.apache.calcite.test.SqlOperatorFixtureImpl.lambda$checkScalarExact$3(SqlOperatorFixtureImpl.java:232)
> 	at org.apache.calcite.sql.test.AbstractSqlTester.forEachQuery(AbstractSqlTester.java:444)
> 	at org.apache.calcite.test.SqlOperatorFixtureImpl.checkScalarExact(SqlOperatorFixtureImpl.java:231)
> 	at org.apache.calcite.sql.test.SqlOperatorFixture.checkScalarExact(SqlOperatorFixture.java:275)
> 	at org.apache.calcite.test.CalciteSqlOperatorTest.testTryCastToInt(CalciteSqlOperatorTest.java:39)
> {code}
> I found the direct cause is that the SqlFunction#deriveType only lookup function with SqlSyntax.FUNCTION kind. The reason that functions with SqlSyntax.SPECIAL in SqlStdOperatorTable work well is these functions are normalized by `CaseSensitiveKey#normalize`, which will convert SqlSyntax.SPECIAL to SqlSyntax.FUNCTION. But functions are not normalized in SqlLibraryOperatorTableFactory.



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