Skip to content

IGNITE-28739 SQL Calcite: Add expression support for FETCH - #13464

Open
tkalkirill wants to merge 13 commits into
masterfrom
ignite-28739-new
Open

IGNITE-28739 SQL Calcite: Add expression support for FETCH#13464
tkalkirill wants to merge 13 commits into
masterfrom
ignite-28739-new

Conversation

@tkalkirill

Copy link
Copy Markdown
Contributor

@tkalkirill
tkalkirill requested a review from zstan August 12, 2026 07:43
long fetch = validateAndGetFetch(rel.fetch, SortNode.FETCH_DEFAULT);

// Zero FETCH is enforced by the outer IgniteLimit, while SortNode accepts only positive FETCH values.
if (fetch == 0)

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.

why do we need this change ? I run limited set of tests and it`s all ok, plz clarify ?
Also if this fix is helpful for smth. it looks hacky

  1. run validateAndGetFetch with SortNode.FETCH_DEFAULT
  2. additional check and additional set : fetch = SortNode.FETCH_DEFAULT;

@tkalkirill tkalkirill Aug 14, 2026

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.

You're right, I overdid it a bit, I got rid of it.

super.validateSelect(select, targetRowType);

validateFetchOffset(select.getFetch(), "fetch / limit");
validateFetch(select, "fetch / limit");

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.

now we have 2 functions: one - for 'validateFetch' and other for 'validateFetchOffset' ? looks weird

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.

Agree, it looks weird. This is temporary because the current ticket adds expression support only for FETCH/LIMIT, while OFFSET still uses the existing validation path. We will align OFFSET behavior and consolidate these methods in the follow-up ticket.

if (call.isA(SqlKind.QUERY))
throw newValidationError(call, IgniteResource.INSTANCE.illegalFetchLimit(clauseName));

if (call.getKind() == SqlKind.OVER)

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.

I don`t think that this is a good approach:

  1. comment this line : if (call.getKind() == SqlKind.OVER)
    and run 'testInvalidFetchExpression' - you obtain aggregate related error, i mean - if you miss some operands comparison here - you will obtain confusing exception.
  2. I don`t like an idea to handle each stupid oparation here, you will always miss smth, check :
    'SELECT * FROM TEST_REPL FETCH FIRST (1=1) ROWS ONLY' but if you want - you can do it with extended tests for all such a cases

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.

I partially agree that covering every possible invalid expression and keeping all related errors consistent may be quite cumbersome. For now, I’ll remove these specific checks and rely on the general validation. If a concrete need arises, we can restore them together with focused tests.

@zstan zstan 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.

one minor, plz append this check - help TC with time economy plz )


/** */
@Test
public void testFetchExpression() throws Exception {

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.

let simplify these tests a bit, plz append "assumeNoTransactions();"

/** */
private void assumeNoTransactions() {
    assumeTrue("Test use queries that doesn't touch any data. Skip for tx modes", sqlTxMode == SqlTransactionMode.NONE);
}

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants