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

hongyu guo edited comment on CALCITE-6645 at 12/20/24 9:19 AM:
---------------------------------------------------------------

This PR has changed the default behavior of calcite. The default SqlConformance 
does not allow Niladic Parenthethes, so the syntax of UDF will be 
`Syntax.FUNCTION_ID`. Before this PR, it is `Syntax.FUNCTION`。 Our program will 
encounter errors after upgrading to the current version

[~duanzhengqiang] [~mbudiu] 


was (Author: JIRAUSER300840):
This PR has changed the default behavior of calcite. The default SqlConformance 
does not allow Niladic Parenthethes, so the syntax of UDF will be 
`Syntax.FUNCTION_ID`。 Before this PR, it is `Syntax.FUNCTION`。 Our program will 
encounter errors after upgrading to the current version

[~duanzhengqiang] [~mbudiu] 

> Support user-defined function without parentheses when db dialect's 
> allowNiladicParentheses property is false
> -------------------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-6645
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6645
>             Project: Calcite
>          Issue Type: Improvement
>    Affects Versions: 1.38.0
>            Reporter: Zhengqiang Duan
>            Assignee: Zhengqiang Duan
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.39.0
>
>
> Hi community, When I implement a user defined function without parameters for 
> Oracle database, I get a `Column 'SYS_DATE' not found in any table` exception 
> when I execute the `SELECT SYS_DATE FROM DUAL` statement. I did some research 
> and found that the default SqlSyntax used by the SqlUserDefinedFunction is 
> SqlSyntax.FUNCTION, and its corresponding function syntax is SYS_DATE() 
> instead of SYS_DATE. SqlSyntax.FUNCTION will cause an exception during SQL 
> validation. The implementation logic of makeNullaryCall in SqlValidatorImpl 
> is as follows, since makeNullaryCall checks if operator.getSyntax() == 
> SqlSyntax.FUNCTION_ID, user defined function cannot be converted to 
> SqlBasicCall.
> {code:java}
> @Override
> public @Nullable SqlCall makeNullaryCall(SqlIdentifier id) {
>     if (id.names.size() == 1 && !id.isComponentQuoted(0)) {
>         final List<SqlOperator> list = new ArrayList<>();
>         opTab.lookupOperatorOverloads(id, null, SqlSyntax.FUNCTION, list, 
> catalogReader.nameMatcher());
>         for (SqlOperator operator : list) {
>             if (operator.getSyntax() == SqlSyntax.FUNCTION_ID) {
>                 // Even though this looks like an identifier, it is a
>                 // actually a call to a function. Construct a fake
>                 // call to this function, so we can use the regular
>                 // operator validation.
>                 return new SqlBasicCall(operator, ImmutableList.of(), 
> id.getParserPosition(), null).withExpanded(true);
>             }
>         }
>     }
>     return null;
> }{code}
> In order to support user defined functions without parameters, we need to 
> modify the logic of the CalciteCatalogReader#toOp method. If the current user 
> defined function has no parameters and allowNiladicParentheses is set to 
> false, SqlSyntax.FUNCTION_ID should be passed in for SqlUserDefinedFunction.
> {code:java}
> SqlSyntax syntax = function.getParameters().isEmpty()
>     && !config.conformance().allowNiladicParentheses()
>     ? SqlSyntax.FUNCTION_ID
>     : SqlSyntax.FUNCTION;
> return new SqlUserDefinedFunction(name, kind, returnTypeInference,
>     operandTypeInference, operandMetadata, function, syntax);{code}
> I will submit a PR to support this usage. if anyone can provide some 
> suggestions I would appreciate it.



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

Reply via email to