Skip to content

Add support for FETCH clause and FETCH FIRST WITH TIES clause#14871

Closed
fgwang7w wants to merge 5 commits intoprestodb:masterfrom
fgwang7w:14837
Closed

Add support for FETCH clause and FETCH FIRST WITH TIES clause#14871
fgwang7w wants to merge 5 commits intoprestodb:masterfrom
fgwang7w:14837

Conversation

@fgwang7w
Copy link
Member

@fgwang7w fgwang7w commented Jul 22, 2020

Syntax:

<query expression> ::=
  [ <with clause> ] <query expression body>
      [ <order by clause> ] [ <fetch first clause> ]

<fetch first clause> ::=
  FETCH { FIRST | NEXT } [ <fetch first quantity> ] { ROW | ROWS } { ONLY | WITH TIES }

<fetch first quantity> ::=
    <fetch first row count>
  | <fetch first percentage>

<fetch first row count> ::=
  <simple value specification>

<fetch first percentage> ::=
  <simple value specification> PERCENT

Extracted-From:
trinodb/trino#666
trinodb/trino#832

Test plan - Add UT and test locally

== RELEASE NOTES ==

General Changes
* Add support for FETCH syntax 
* Add support for FETCH FIRST WITH TIES syntax

@rongrong rongrong requested a review from kaikalur July 22, 2020 22:45
@lucaskim1233
Copy link

Is this feature scheduled for next release?

Copy link
Contributor

@kaikalur kaikalur left a comment

Choose a reason for hiding this comment

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

LGTM

@fgwang7w
Copy link
Member Author

LGTM

Thanks for reviewing. However, current commit only suppport FETCH syntax and OFFSET syntax. Add support for FETCH FIRST WITH TIES clause has not yet been committed. OFFSET implementation is still being worked on.
The code base is quite complicated and direct backporting is not possible which now results in many handy maneuvers. Is it acceptable to include suppport for FETCH syntax and OFFSET syntax only in the next release and another commit in the subsequent release? @kaikalur fyi @rongrong

@fgwang7w fgwang7w force-pushed the 14837 branch 2 times, most recently from 9a1cbfd to 12f8494 Compare July 24, 2020 21:49
@fgwang7w
Copy link
Member Author

@kaikalur I added the implementation for OFFSET and add support for FETCH FIRST WITH TIES clause. Could you please review again. I'd like to retain 2 commits as the 2nd commit contains the support for FETCH FIRST WITH TIES clause. Thanks.

@fgwang7w fgwang7w changed the title Add support for FETCH syntax and OFFSET syntax Add support for FETCH, OFFSET, and TIES syntax to an enhanced LIMIT capability Jul 25, 2020
@rongrong
Copy link
Contributor

LGTM

Thanks for reviewing. However, current commit only suppport FETCH syntax and OFFSET syntax. Add support for FETCH FIRST WITH TIES clause has not yet been committed. OFFSET implementation is still being worked on.
The code base is quite complicated and direct backporting is not possible which now results in many handy maneuvers. Is it acceptable to include suppport for FETCH syntax and OFFSET syntax only in the next release and another commit in the subsequent release? @kaikalur fyi @rongrong

I'm OK with leaving FETCH FIRST WITH TIES into a different PR if it's quite complicated. Please update the description accordingly if you decided to do so. The test failures seem to be related. Please fix them. Thanks!

@fgwang7w
Copy link
Member Author

LGTM

Thanks for reviewing. However, current commit only suppport FETCH syntax and OFFSET syntax. Add support for FETCH FIRST WITH TIES clause has not yet been committed. OFFSET implementation is still being worked on.
The code base is quite complicated and direct backporting is not possible which now results in many handy maneuvers. Is it acceptable to include suppport for FETCH syntax and OFFSET syntax only in the next release and another commit in the subsequent release? @kaikalur fyi @rongrong

I'm OK with leaving FETCH FIRST WITH TIES into a different PR if it's quite complicated. Please update the description accordingly if you decided to do so. The test failures seem to be related. Please fix them. Thanks!

Acutually FETCH FIRST TIES support is included in the same PR now. I am working on fixing the test failures now.

@fgwang7w fgwang7w force-pushed the 14837 branch 2 times, most recently from d266b0e to ec5bb8f Compare July 29, 2020 22:09
@fgwang7w fgwang7w force-pushed the 14837 branch 11 times, most recently from 30bd260 to 476dae2 Compare August 4, 2020 04:26
@fgwang7w
Copy link
Member Author

fgwang7w commented Aug 5, 2020

All tests fixed. Please help review the code for next release. Thanks!

@aweisberg
Copy link
Contributor

Was there code in this PR copied from another project? If so please follow the attribution guidelines.

@aweisberg
Copy link
Contributor

Just FYI it seems like 3/4 of the commits don't have a co-author tag. Thanks!

@fgwang7w
Copy link
Member Author

fgwang7w commented Oct 7, 2020

Just FYI it seems like 3/4 of the commits don't have a co-author tag. Thanks!

commit msg is fixed

@fgwang7w
Copy link
Member Author

fgwang7w commented Oct 7, 2020

@kaikalur had an LGTM on Jul 23, please review again. @tdcmeehan please help move forward for this PR. this has been waiting for too long to get merged since Jul 23

@fgwang7w fgwang7w requested a review from tdcmeehan October 7, 2020 23:32
@kaikalur
Copy link
Contributor

kaikalur commented Oct 8, 2020

So I'm still confused - can we create 4 separate PRs? That'll be easier to review/track.

@fgwang7w
Copy link
Member Author

fgwang7w commented Oct 8, 2020

So I'm still confused - can we create 4 separate PRs? That'll be easier to review/track.

I think it's already splitted into 4 commits which can be reviewed individually as Tim did. are you suggesting to split those 4 commits into 4 PRs now?

@kaikalur
Copy link
Contributor

kaikalur commented Oct 8, 2020

So I'm still confused - can we create 4 separate PRs? That'll be easier to review/track.

I think it's already splitted into 4 commits which can be reviewed individually as Tim did. are you suggesting to split those 4 commits into 4 PRs now?

I think that will be better.

@kaikalur
Copy link
Contributor

kaikalur commented Oct 8, 2020

So I'm still confused - can we create 4 separate PRs? That'll be easier to review/track.

I think it's already splitted into 4 commits which can be reviewed individually as Tim did. are you suggesting to split those 4 commits into 4 PRs now?

I think that will be better.

So chatted with Rongrong offline and it's ok to have just one PR with 4 commits. I will review them before Monday.

Copy link
Contributor

@kaikalur kaikalur left a comment

Choose a reason for hiding this comment

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

For the fist commit.

@NikhilCollooru
Copy link
Contributor

Hi @fgwang7w can you please address the comments and update the PR ?

We need OFFSET feature and hence we need this PR . Can you please fix the PR ?

@fgwang7w fgwang7w force-pushed the 14837 branch 2 times, most recently from 551906c to 9f8cd43 Compare May 2, 2021 02:45
@fgwang7w fgwang7w changed the title Enhance LIMIT capability: add support for FETCH, OFFSET, FETCH FIRST WITH TIES syntax Add support for FETCH clause and FETCH FIRST WITH TIES clause May 2, 2021
@fgwang7w
Copy link
Member Author

fgwang7w commented May 2, 2021

Hi @fgwang7w can you please address the comments and update the PR ?

We need OFFSET feature and hence we need this PR . Can you please fix the PR ?

Supoprt for OFFSET clause is now implemented via this PR #16035

@fgwang7w fgwang7w force-pushed the 14837 branch 2 times, most recently from 38247b8 to da42dcb Compare May 4, 2021 16:57
@fgwang7w fgwang7w requested a review from kaikalur May 5, 2021 21:56
@fgwang7w fgwang7w force-pushed the 14837 branch 3 times, most recently from d3b4a75 to 97b8737 Compare May 21, 2021 00:29
fgwang7w and others added 5 commits June 26, 2021 22:02
Cherry-pick of trinodb/trino@a9e7145

Co-authored-by: kasiafi <30203062+kasiafi@users.noreply.github.com>
Cherry-pick of trinodb/trino315

Co-authored-by: kasiafi <30203062+kasiafi@users.noreply.github.com>
Cherry-pick of trinodb/trino315

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

@kaikalur kaikalur left a comment

Choose a reason for hiding this comment

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

I put a couple of comments. But my high level comment would be to keep this PR non-intrusive. I see a lot of core planner changes. I'm not sure why those are needed.

new ImplementBernoulliSampleAsFilter(),
new ImplementOffset())),
new ImplementOffset(),
new ImplementLimitWithTies(metadata))),
Copy link
Contributor

Choose a reason for hiding this comment

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

We need this to be controlled by a session param/feature config. In fact, I would like the whole feature to be optional.

{
if (!orderBy.isPresent() || (isSkipRedundantSort(session)) && analysis.isOrderByRedundant(orderBy.get())) {
return subPlan;
return Optional.empty();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this change?

@stale
Copy link

stale bot commented Mar 2, 2022

This pull request has been automatically marked as stale because it has not had recent activity. If you'd still like this PR merged, please comment on the task, make sure you've addressed reviewer comments, and rebase on the latest master. Thank you for your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants