-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add support for chained function calls #26841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
76a957d
to
9ebb391
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for chained function calls to Trino SQL parser, allowing expressions like ('hello').upper().concat(' world!')
instead of nested function calls. This improves readability for deeply nested function expressions similar to BigQuery and DuckDB implementations.
- Adds grammar support for dot notation chained function calls
- Implements AST building logic to transform chained calls into nested FunctionCall objects
- Updates parser error messages to reflect new grammar tokens
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
SqlBase.g4 | Adds grammar rules for chained function calls and refactors function call parsing |
AstBuilder.java | Implements visitChainedFunctionCalls method to build nested FunctionCall AST nodes |
TestSqlParser.java | Adds unit tests for chained function call parsing |
TestChainedFunctionCalls.java | Adds comprehensive integration tests for chained function call execution |
TestSqlParserErrorHandling.java | Updates expected error message to include new grammar tokens |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
For the expression
For an expression like |
Are these the only ones which support this syntax sugar?
So do "lateral column aliases". Coming from object-oriented languages, I very much like the idea of SQL values having methods, but I am not convinced |
A function require
Yes, as far as I confirmed.
I don't think LCA and chained function calls actually solve any "problems". Those syntaxes exists to improve user experience. |
Function names are
In In fact, field names can contain even more than 3 parts. |
But if we use other syntax (ie :: instead of a dot) it shouldn't be ambiguous anymore, right? |
Yes. |
Can we resolve the ambiguity by requiring That's the BigQuery's syntax: SELECT (name).lower() FROM tpch.region; The below query throws "Function not found: name.lower": SELECT name.lower() FROM tpch.region; |
We could require |
There's a whole section in the SQL spec for instance method invocations. We don't need to reinvent any wheels. However, as @findepi pointed out above, we can't blindly interpret every function as a method invocation. |
Description
This is a proposal to add support for chained function calls, similar to BigQuery, DuckDB.
It improves the readability of deeply nested expressions. Also, it eliminates the need to move the cursor backward when writing functions.
↓
Release notes