[CALCITE-7662] Add expression support for OFFSET#5113
Conversation
|
@xiedeyantu Can you take a look? I'm unable to add you to the "Reviewers" section for the review. |
|
You could refine the PR title first. |
| # | ||
|
|
||
| !use post | ||
| !set outputformat mysql |
There was a problem hiding this comment.
Is there any relevant MySQL validation?
You can explain that the accuracy of the results has been verified against relevant databases.
There was a problem hiding this comment.
Is there any relevant MySQL validation?
I modeled it after the neighboring files.
As far as I understand, this only affects the output style or am I mistaken?
You can explain that the accuracy of the results has been verified against relevant databases.
I checked here: https://onecompiler.com/postgresql
There was a problem hiding this comment.
You might need to add all the test cases here to the link so that the reviewer can easily view them, like this: https://onecompiler.com/postgresql/44veytn3y
There was a problem hiding this comment.
| new HrSchemaBig(), | ||
| "select * from (select empid, name from emps where name like 'G%' union select empid, name from emps where name like '%l') order by name limit 3") | ||
| .explainContains("EnumerableLimit(fetch=[3])\n" | ||
| .explainContains("EnumerableLimitSort(sort0=[$1], dir0=[ASC], fetch=[3])\n" |
There was a problem hiding this comment.
When modifying a large number of existing tests, it is best to provide a summary of the reasons to help other reviewers understand the situation more easily.
There was a problem hiding this comment.
I noticed an issue at UNION DISTINCT and decided to fix it right away. I suppose that wasn't the right move, as it resulted in too many changes and is confusing. I think I'll fix it later in a separate ticket.
| + "FROM `FOO`\n" | ||
| + "OFFSET ? ROWS\n" | ||
| + "FETCH NEXT ? ROWS ONLY"); | ||
| // CALCITE-7592: Arithmetic and scalar expressions are allowed within parentheses. |
There was a problem hiding this comment.
Why is this comment being modified? Is it related to the associated Jira ticket?
There was a problem hiding this comment.
The idea is this: previously, expressions with parenthesized were available only for FETCH, but now they are supported for OFFSET as well. To avoid adding another reference to the proposal, I decided simply to remove it.
| } | ||
| } | ||
|
|
||
| private static void unparseOffsetFetchExpression(SqlWriter writer, SqlNode node) { |
There was a problem hiding this comment.
Could unparseOffsetExpression and unparseOffsetFetchExpression be consolidated into a single method? Or perhaps unparseFetchUsingAnsi could be refactored? It seems like there is a lot of similar logic involved.
There was a problem hiding this comment.
I didn't manage to merge everything completely, but I did refactor it a bit.
| .fails("(?s).*Encountered \"-\".*"); | ||
| sql("select name from dept order by name offset ^-^1") | ||
| .fails("(?s).*Encountered \"-\".*"); | ||
| sql("select name from dept order by name offset -1").ok(); |
There was a problem hiding this comment.
Because I changed the validation for OFFSET. But I fixed that and added a check for negative values for literals.
| # | ||
|
|
||
| !use post | ||
| !set outputformat mysql |
There was a problem hiding this comment.
You might need to add all the test cases here to the link so that the reviewer can easily view them, like this: https://onecompiler.com/postgresql/44veytn3y
|



Jira Link
CALCITE-7662
Changes Proposed
This PR introduces support for arithmetic and scalar expressions for "OFFSET", enabling queries to execute similarly to those in other popular DBMSs (PostgreSQL, Oracle, H2, and MS SQL):