Skip to content

TVF Part 1/X: Support table function invocation in grammar and AST#25781

Merged
mohsaka merged 1 commit into
prestodb:masterfrom
mohsaka:tvf-grammar-ast
Aug 17, 2025
Merged

TVF Part 1/X: Support table function invocation in grammar and AST#25781
mohsaka merged 1 commit into
prestodb:masterfrom
mohsaka:tvf-grammar-ast

Conversation

@mohsaka

@mohsaka mohsaka commented Aug 14, 2025

Copy link
Copy Markdown
Contributor

Description

This PR is the first part of many PR's to add in the TVF implementation into Presto. It is based off the Trino implementation for compatibility. It is a split, of a split of the original entire PR which is located here:
#25032

This is a split of this split PR located here:
#25484

Changes adapted from trino/PR#11336, 12910
Original commit:
2e00c8e64c32d6fdd813999b2e04b3b3415235c8
f0508a7ab420449c6e2960ecf1d0a8d7058242da
Author: kasiafi

Modifications were made to adapt to Presto including:
Addition of KEEP in the parser.
Adjustment of the TestSqlParser.java to apply to Presto concepts. Switch from Trino's DataType based datatypes to Presto's String based datatypes.

Motivation and Context

Impact

Test Plan

Parser tests cases added in TestSqlParser and TestSqlParserErrorHandling.

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

If release note is NOT required, use:

== NO RELEASE NOTE ==

@mohsaka mohsaka requested a review from a team as a code owner August 14, 2025 00:07
@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Aug 14, 2025
@prestodb-ci prestodb-ci requested review from a team, BryanCutler and aaneja and removed request for a team August 14, 2025 00:07
@github-actions

github-actions Bot commented Aug 14, 2025

Copy link
Copy Markdown

Codenotify: Notifying subscribers in CODENOTIFY files for diff 17aa98c...b8ab62a.

Notify File(s)
@aditi-pandit presto-parser/src/main/antlr4/com/facebook/presto/sql/parser/SqlBase.g4
@elharo presto-parser/src/main/antlr4/com/facebook/presto/sql/parser/SqlBase.g4
@kaikalur presto-parser/src/main/antlr4/com/facebook/presto/sql/parser/SqlBase.g4
@rschlussel presto-parser/src/main/antlr4/com/facebook/presto/sql/parser/SqlBase.g4

}

@Test
public void testTableFunctionInvocation()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add more complex test cases + edge cases which fail parsing?

}

@Override
public boolean shallowEquals(Node o)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shallowEquals
Why do we need this shallowEquals function only for this use case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. In Trino, it is used for scope aware comparisons. Removed it as it doesn't seem like we have the same structure in Presto.

private final Relation table;
private final Optional<List<Expression>> partitionBy; // it is allowed to partition by empty list
private final Optional<OrderBy> orderBy;
private final Optional<EmptyTableTreatment> emptyTableTreatment;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is EmptyTableTreatment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EmptyTableTreatment holds the property that decides what to do when a table argument is empty. There are two possibilities, PRUNE or KEEP, which can be specified via PRUNE WHEN EMPTY or KEEP WHEN EMPTY.

Prune means return an empty result set when the table argument is empty. Keep means still execute the table function even though the table argument is empty.

More details can be seen in the RFC ##### Prune or keep when empty section.

aditi-pandit
aditi-pandit previously approved these changes Aug 14, 2025

@aditi-pandit aditi-pandit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mohsaka : Changes look good to me.

jaystarshot
jaystarshot previously approved these changes Aug 15, 2025
tdcmeehan
tdcmeehan previously approved these changes Aug 15, 2025
Changes adapted from trino/PR#11336, 12910
Original commit:
2e00c8e64c32d6fdd813999b2e04b3b3415235c8
f0508a7ab420449c6e2960ecf1d0a8d7058242da
Author: kasiafi

Modifications were made to adapt to Presto including:
Addition of KEEP in the parser.
Adjustment of the TestSqlParser.java to apply to Presto concepts.
Switch from Trino's DataType based datatypes to Presto's String based datatypes.

Co-authored-by: kasiafi <30203062+kasiafi@users.noreply.github.com>

@aditi-pandit aditi-pandit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mohsaka

@hantangwangd hantangwangd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mohsaka

@mohsaka mohsaka merged commit 956978a into prestodb:master Aug 17, 2025
126 of 129 checks passed
steveburnett added a commit that referenced this pull request Mar 17, 2026
## Description
Building on the work in #25781 and several other PRs, this PR adds
documentation for table value functions (TVF) based on the Trino
documentation [Table
Functions](https://trino.io/docs/current/functions/table.html).

## Motivation and Context
Presto features should be documented in Presto. 

## Impact
Documentation.

## Test Plan
Local doc builds. 

## Contributor checklist

- [x] Please make sure your submission complies with our [contributing
guide](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md),
in particular [code
style](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#code-style)
and [commit
standards](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#commit-standards).
- [x] PR description addresses the issue accurately and concisely. If
the change is non-trivial, a GitHub Issue is referenced.
- [x] Documented new properties (with its default value), SQL syntax,
functions, or other functionality.
- [x] If release notes are required, they follow the [release notes
guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines).
- [x] Adequate tests were added if applicable.
- [ ] CI passed.
- [x] If adding new dependencies, verified they have an [OpenSSF
Scorecard](https://securityscorecards.dev/#the-checks) score of 5.0 or
higher (or obtained explicit TSC approval for lower scores).

## Release Notes
Please follow [release notes
guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines)
and fill in the release notes below.

```
== RELEASE NOTES ==

General Changes
* Add documentation for :doc:`/functions/table`. 
```

## Summary by Sourcery

Documentation:
- Introduce a new functions/table documentation page describing table
value functions and how to use them.
msmygit pushed a commit to msmygit/presto that referenced this pull request Jun 3, 2026
## Description
Building on the work in prestodb#25781 and several other PRs, this PR adds
documentation for table value functions (TVF) based on the Trino
documentation [Table
Functions](https://trino.io/docs/current/functions/table.html).

## Motivation and Context
Presto features should be documented in Presto. 

## Impact
Documentation.

## Test Plan
Local doc builds. 

## Contributor checklist

- [x] Please make sure your submission complies with our [contributing
guide](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md),
in particular [code
style](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#code-style)
and [commit
standards](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#commit-standards).
- [x] PR description addresses the issue accurately and concisely. If
the change is non-trivial, a GitHub Issue is referenced.
- [x] Documented new properties (with its default value), SQL syntax,
functions, or other functionality.
- [x] If release notes are required, they follow the [release notes
guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines).
- [x] Adequate tests were added if applicable.
- [ ] CI passed.
- [x] If adding new dependencies, verified they have an [OpenSSF
Scorecard](https://securityscorecards.dev/#the-checks) score of 5.0 or
higher (or obtained explicit TSC approval for lower scores).

## Release Notes
Please follow [release notes
guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines)
and fill in the release notes below.

```
== RELEASE NOTES ==

General Changes
* Add documentation for :doc:`/functions/table`. 
```

## Summary by Sourcery

Documentation:
- Introduce a new functions/table documentation page describing table
value functions and how to use them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:IBM PR from IBM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants