[ 
https://issues.apache.org/jira/browse/CALCITE-5569?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Julian Hyde resolved CALCITE-5569.
----------------------------------
    Resolution: Not A Bug

Functions with SPECIAL syntax don't have normal function syntax, therefore you 
can't look them up by name. They need to be created by the parser.

The Postgres-style '%'  operator (a synonym for the standard MOD function) is 
similar to this. It is defined in SqlStdOperatorTable (as PERCENT_REMAINDER), 
calls are created directly by the parser, and if you don't have the right 
conformance setting the validator will reject them.

Closing as not-a-bug.

> 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
>
> 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)

Reply via email to