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
Introduce new Keyword FETCH FIRST N ROWS ONLY in Presto Query #18968
Conversation
Issue details : #18935 We are introducing a new keyword FETCH FIRST N ROWS ONLY which can be used in presto queries. The keyword will work in sql queries just like LIMIT keyword to limit the number of rows returned from an sql select query. For Example : select * from table FETCH FIRST 3 ROWS ONLY will return only 3 rows as a result of the sql query. == RELEASE NOTES == General Changes Introducing a new Keyword FETCH FIRST N ROWS ONLY to the Presto Query
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.
Thanks for the contribution! I didn't realize until now that "LIMIT" wasn't in the sql standard.
FYI @jainxrohit @elharo - this will need to be added to crux as well.
@@ -223,6 +223,7 @@ externalRoutineName | |||
queryNoWith: | |||
queryTerm | |||
(ORDER BY sortItem (',' sortItem)*)? | |||
(FETCH FIRST fetchFirstNRows=INTEGER_VALUE ROWS ONLY)? | |||
(OFFSET offset=INTEGER_VALUE (ROW | ROWS)?)? |
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.
offset comes before "FETCH FIRST"
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.
This is addressed
@@ -223,6 +223,7 @@ externalRoutineName | |||
queryNoWith: | |||
queryTerm | |||
(ORDER BY sortItem (',' sortItem)*)? | |||
(FETCH FIRST fetchFirstNRows=INTEGER_VALUE ROWS ONLY)? | |||
(OFFSET offset=INTEGER_VALUE (ROW | ROWS)?)? | |||
(LIMIT limit=(INTEGER_VALUE | ALL))? |
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.
we shouldn't allow queries to have both LIMIT and FETCH FIRST
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.
This is handled and necessary conditions are in place
Why do we want this and LIMIT? Where does the syntax come from? This seems quite verbose compared to LIMIT and is more than one keyword, or perhaps not a keyword at all. I'd like a much more complete rationale for this change before accepting it. |
Syntax comes from the SQL Spec, which is why I think we should support it. It turns out LIMIT isn't actually in the SQL Spec even though i assume it's way more widely used. From 2016 sql spec
|
You can read more about the all the various ways of limiting result rows across DBs here: https://en.wikipedia.org/wiki/Select_(SQL)#Limiting_result_rows. |
Or you could just get the whole SQL 2016 spec using my awesome SQL 16 parser :) |
I think this needs a broader discussion amongst the interested parties before committing. Standard or otherwise, we already have LIMIT. Adding a new way of doing the same thing is worth a second look. I don't think Presto anyone else have ever promised to implement the full ISO spec. |
We don't promise to implement the full ISO spec, but for features we have, we strive to implement them in a way that is ISO SQL compliant. As a general principle, I agree it's good to have just one way of doing things. But in this case, the cost of this change is very minimal (very limited in scope), and it brings us better SQL compliance. I don't see a big downside here. |
@rschlussel Exactly, While fetch and limit have the same functionality, the fetch clause is an SQL standard while limit is not. Fetch was included in the SQL standard in 2008 which makes it the go to option if you want your query to be portable across several RDBMS. So this is a MUST needed in terms of SQL compatibility standpoint for all presto consumers |
Review Changes
@rschlussel Please see that your comments are addressed. |
@prestobot kick off tests |
Had offline discussion with @elharo, and he no longer has concerns about this change. |
@skairali sorry, i merged this without noticing, but in the future, commits should be self contained, so squash all the "address comments" type of commits in to the original, and also always rebase changes on latest rather than merging. We don't like to have merge commits |
@rschlussel Sure |
Introduce new Keyword FETCH FIRST N ROWS ONLY in Presto Query
Issue details : #18935
We are introducing a new keyword FETCH FIRST N ROWS ONLY which can be used in presto queries. The keyword will work in sql queries just like LIMIT keyword to limit the number of rows returned from an sql select query.
For Example : select * from table FETCH FIRST 3 ROWS ONLY will return only 3 rows as a result of the sql query.
== RELEASE NOTES ==
General Changes
Introducing a new Keyword FETCH FIRST N ROWS ONLY to the Presto Query