[
https://issues.apache.org/jira/browse/CALCITE-6566?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17883052#comment-17883052
]
Julian Hyde commented on CALCITE-6566:
--------------------------------------
[~nobigo], You're right. I hadn't thought of that.
How about this: Change PI's syntax from FUNCTION_ID to FUNCTION, and add a
conformance method requireParenthesesForNilaryFunction() (default false,
consistent with Calcite's current behavior), and use that method when resolving
the operator. So, when resolving there would be all of the true FUNCTION_ID
operators plus PI. (We can fix the criteria later to include other functions
than PI.)
That fix would deal with the incoming SQL. The outgoing SQL should then be
straightforward.
> JDBC adapter should generate PI function with parentheses in most dialects
> --------------------------------------------------------------------------
>
> Key: CALCITE-6566
> URL: https://issues.apache.org/jira/browse/CALCITE-6566
> Project: Calcite
> Issue Type: Improvement
> Reporter: xiong duan
> Priority: Major
> Labels: pull-request-available
> Fix For: 1.38.0
>
>
> Now In Calcite, support the PI function:
> {code:java}
> select PI;
> return 3.141592653589793
> {code}
> Jdbc will generate:
> {code:java}
> SELECT PI AS "PI" FROM (VALUES (0)) AS "t" ("ZERO");{code}
> However, they always need parentheses when I test in different data sources.
> Spark:
> {code:java}
> select PI();
> return 3.141592653589793
> select PI;
> Error in query: cannot resolve '`PI`' given input columns: []; line 1 pos
> 7;{code}
> Hive:
> {code:java}
> select PI();
> return 3.141592653589793
> select PI;
> SemanticException [Error 10004]: Line 1:7 Invalid table alias or column
> reference 'PI': (possible column names are: ) (state=42000,code=10004){code}
> Postgresql:
> {code:java}
> select PI();
> return 3.141592653589793
> select PI;
> ERROR: column "pi" does not exist{code}
> MySQL:
> {code:java}
> select PI();
> return 3.141593
> select PI;
> ERROR 1054 (42S22) at line 1: Unknown column 'PI' in 'field list'{code}
> SQLServer:
> {code:java}
> select PI();
> 3.1415926535897931
> select PI;{code}
> So I will generate PI() in Jdbc Dialect.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)