Skip to content

fix(cli): do not split BEGIN...END script blocks on inner semicolons#786

Merged
youngsofun merged 1 commit into
databendlabs:mainfrom
youngsofun:fix-task-begin-end-split
Jul 8, 2026
Merged

fix(cli): do not split BEGIN...END script blocks on inner semicolons#786
youngsofun merged 1 commit into
databendlabs:mainfrom
youngsofun:fix-task-begin-end-split

Conversation

@youngsofun

Copy link
Copy Markdown
Member

Summary

Fix multi-statement CREATE TASK ... AS BEGIN ... END blocks being incorrectly split on inner semicolons.

Closes #785

Motivation

When a user runs a CREATE TASK with a BEGIN...END script block in bendsql, the client-side statement splitter treats every ; as a statement boundary. This causes only the fragment up to the first inner semicolon to be sent to the server, resulting in a parse error. The same SQL works fine in Databend Cloud worksheet.

Changes

  • Track AS BEGIN...END block depth in parse_statements(). Only enter block mode when BEGIN is immediately preceded by AS (distinguishing script blocks from transaction BEGIN).
  • Inside a block, semicolons are skipped unless the previous token is a bare END (i.e. END;), which closes the block. END IF;, END FOR;, etc. do not close the block.
  • Enable unit tests on the CLI binary target (test = true).

Testing

Added 9 unit tests covering:

  • CREATE TASK ... AS BEGIN ... END; treated as single statement
  • Block followed by another statement splits correctly
  • Normal statements still split on ;
  • BEGIN; (transaction) still splits correctly
  • BEGIN TRANSACTION; still splits correctly
  • REPL line-by-line input accumulates correctly
  • Nested control flow (END IF;) does not close the block
  • CREATE PROCEDURE with $$ quoting works correctly
  • CREATE PROCEDURE followed by another statement splits correctly

All 13 tests in cargo test -p bendsql pass.

@youngsofun youngsofun force-pushed the fix-task-begin-end-split branch 5 times, most recently from 34e43ea to 2f45409 Compare July 7, 2026 04:09

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e23f509851

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@youngsofun youngsofun force-pushed the fix-task-begin-end-split branch 4 times, most recently from 0b2b62a to 1985fa8 Compare July 7, 2026 04:17
@youngsofun youngsofun marked this pull request as draft July 7, 2026 04:19
@databendlabs databendlabs deleted a comment from chatgpt-codex-connector Bot Jul 7, 2026
@youngsofun youngsofun force-pushed the fix-task-begin-end-split branch 3 times, most recently from cf050c6 to 8caf8a3 Compare July 7, 2026 04:31
@databendlabs databendlabs deleted a comment from chatgpt-codex-connector Bot Jul 7, 2026
@databendlabs databendlabs deleted a comment from chatgpt-codex-connector Bot Jul 7, 2026
@databendlabs databendlabs deleted a comment from chatgpt-codex-connector Bot Jul 7, 2026
@youngsofun youngsofun force-pushed the fix-task-begin-end-split branch 2 times, most recently from 45e71d4 to f46489a Compare July 7, 2026 04:36
@youngsofun

Copy link
Copy Markdown
Member Author

@codex review

@youngsofun youngsofun force-pushed the fix-task-begin-end-split branch 2 times, most recently from 65bafc2 to d39c263 Compare July 7, 2026 04:44

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 65bafc2627

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@youngsofun youngsofun force-pushed the fix-task-begin-end-split branch 3 times, most recently from da33a78 to e04e55f Compare July 7, 2026 07:10
@databendlabs databendlabs deleted a comment from chatgpt-codex-connector Bot Jul 7, 2026
@databendlabs databendlabs deleted a comment from chatgpt-codex-connector Bot Jul 7, 2026
@youngsofun youngsofun force-pushed the fix-task-begin-end-split branch from e04e55f to 523cfe6 Compare July 7, 2026 07:13
@youngsofun youngsofun force-pushed the fix-task-begin-end-split branch 7 times, most recently from dbee801 to e583210 Compare July 7, 2026 08:01
@youngsofun

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e583210670

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@youngsofun youngsofun force-pushed the fix-task-begin-end-split branch from e583210 to 1c87e7b Compare July 7, 2026 09:12
@databendlabs databendlabs deleted a comment from chatgpt-codex-connector Bot Jul 7, 2026
@databendlabs databendlabs deleted a comment from chatgpt-codex-connector Bot Jul 7, 2026
@youngsofun youngsofun force-pushed the fix-task-begin-end-split branch from 1c87e7b to 899b036 Compare July 7, 2026 09:15
@youngsofun

Copy link
Copy Markdown
Member Author

@codex review

@youngsofun youngsofun marked this pull request as ready for review July 7, 2026 09:16
@youngsofun youngsofun marked this pull request as draft July 7, 2026 09:17
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 899b03630c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@youngsofun youngsofun marked this pull request as ready for review July 7, 2026 09:24
@youngsofun youngsofun force-pushed the fix-task-begin-end-split branch from 899b036 to a0d0387 Compare July 7, 2026 09:24
@youngsofun youngsofun requested a review from sundy-li July 7, 2026 09:24
The SQL statement splitter treated every semicolon as a statement
boundary, which broke multi-statement CREATE TASK blocks:

  CREATE TASK t1 AS
  BEGIN
      select 1;
      select 2;
  END;

The splitter would send only 'CREATE TASK t1 AS BEGIN select 1' to the
server, causing a parse error.

Fix: track AS BEGIN...END block depth. Only a semicolon immediately
after a bare END token (not END IF, END FOR, etc.) closes the block.
Transaction BEGIN statements are unaffected because they are not
preceded by AS.

Closes databendlabs#785
@youngsofun youngsofun force-pushed the fix-task-begin-end-split branch from a0d0387 to 3f351a1 Compare July 7, 2026 09:26
@youngsofun youngsofun requested a review from KKould July 7, 2026 11:43
@youngsofun youngsofun merged commit 1d26df9 into databendlabs:main Jul 8, 2026
42 checks passed
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.

Multi-statement CREATE TASK (BEGIN...END) fails in bendsql but works in worksheet

2 participants