Skip to content

fix(trino): strip multi trailing semicolons before subquery wrap - #2474

Closed
Bartok9 wants to merge 3 commits into
Canner:mainfrom
Bartok9:fix/trino-multi-trailing-semicolon
Closed

Bartok9 wants to merge 3 commits into
Canner:mainfrom
Bartok9:fix/trino-multi-trailing-semicolon

Conversation

@Bartok9

@Bartok9 Bartok9 commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Strengthen Trino _strip_trailing_semicolon to drop the full terminating run of ; / whitespace (not just one removesuffix(";")).
  • SELECT 1;; / ; ;\n no longer break limit/dry_run subquery wraps.

Motivation

Limit/dry_run wrap user SQL as SELECT * FROM ({sql}) AS _sub LIMIT N. A single trailing semicolon was handled, but double terminators (common from copy-paste / client dsn tooling) still left ;) in the wrapped SQL. Aligns with postgres/canner/clickhouse.

Apache-2.0 path: core/wren/** only.

Verification

........                                                                 [100%]
8 passed in 0.23s

Python check on main (behavior proof):

  • before: "SELECT 1;;".rstrip().removesuffix(";").rstrip() → "SELECT 1;" (still broken)
  • after: helper → "SELECT 1"

Duplicates

No open issue/PR solely for multi-semicolon Trino strip (semicolon work historically landed one-terminator helpers). Focused non-shim fix.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Trino SQL handling by stripping only a terminating run of trailing semicolons (including surrounding whitespace), while preserving semicolons elsewhere (including within string literals).
  • Tests
    • Expanded unit test coverage with additional edge cases for multiple trailing semicolons and semicolons followed by spaces/newlines.

@github-actions github-actions Bot added python Pull requests that update Python code core labels Jul 11, 2026
@coderabbitai

coderabbitai Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 912f6046-a879-49fa-aa96-b95f2c4b6981

📥 Commits

Reviewing files that changed from the base of the PR and between 5334780 and ed0a506.

📒 Files selected for processing (2)
  • core/wren/src/wren/connector/trino.py
  • core/wren/tests/unit/test_trino_parser.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • core/wren/src/wren/connector/trino.py
  • core/wren/tests/unit/test_trino_parser.py

Walkthrough

Trino SQL cleanup now removes terminating semicolon runs and surrounding whitespace while preserving semicolons inside string literals. Unit tests cover repeated trailing semicolons and whitespace-separated terminators.

Changes

Trino SQL cleanup

Layer / File(s) Summary
Regex cleanup and test coverage
core/wren/src/wren/connector/trino.py, core/wren/tests/unit/test_trino_parser.py
The helper strips terminating semicolon runs with regex-based logic, while tests cover repeated semicolons and trailing whitespace/newlines.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

Possibly related PRs

  • Canner/WrenAI#2420 — Applies equivalent terminating-semicolon cleanup with edge-case coverage.
  • Canner/WrenAI#2421 — Updates SQL-wrapping cleanup and tests for trailing-semicolon cases.
  • Canner/WrenAI#2430 — Updates connector-specific regex handling and related trailing-semicolon tests.

Suggested reviewers: goldmedal

Poem

A rabbit hops through SQL’s bright stream,
Trimming tail semicolons from the dream.
Inner strings keep every mark,
Tests now shine from dusk till dark.
; ; fades away—
Clean queries greet the day!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main Trino change: stripping multiple trailing semicolons before wrapping queries.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Bartok9
Bartok9 force-pushed the fix/trino-multi-trailing-semicolon branch from 37cf98a to d10f093 Compare July 11, 2026 06:04

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/wren/tests/unit/test_trino_parser.py`:
- Around line 148-151: The test cases for trailing semicolon stripping need
direct coverage for semicolons inside string literals. In the relevant parser
test cases, add an assertion such as SELECT 'hello;'; transforming to SELECT
'hello;', ensuring _strip_trailing_semicolon() removes only the terminating
separator and preserves the literal content.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: fd1fdf29-2ce9-42d8-b508-53f000649943

📥 Commits

Reviewing files that changed from the base of the PR and between bdaefa9 and d10f093.

📒 Files selected for processing (2)
  • core/wren/src/wren/connector/trino.py
  • core/wren/tests/unit/test_trino_parser.py

@goldmedal

Copy link
Copy Markdown
Collaborator

The shared CI failure here (maturin failed → cannot update the lock file core/wren-core-py/Cargo.lock because --locked was passed) came from the Rust core 0.2.0 bump in #2467 leaving core/wren-core-py/Cargo.lock out of sync. That's now fixed on main by #2478 — please rebase onto latest main to pick up the lockfile fix and turn CI green. 🙏

@Bartok9
Bartok9 force-pushed the fix/trino-multi-trailing-semicolon branch from ca69f6a to 5334780 Compare July 13, 2026 02:32
@Bartok9

Bartok9 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Done — rebased onto latest main to pick up the core/wren-core-py/Cargo.lock fix from #2478. CI should go green now. Thanks @goldmedal! 🙏

Bartok9 added 3 commits July 13, 2026 08:11
removesuffix(";") only dropped a single trailing semicolon, so
SELECT 1;; still produced invalid subquery SQL. Match postgres/canner
and strip the full terminating ;/whitespace run.
@Bartok9
Bartok9 force-pushed the fix/trino-multi-trailing-semicolon branch from 5334780 to ed0a506 Compare July 13, 2026 12:11
@goldmedal

Copy link
Copy Markdown
Collaborator

This overlaps with #2480 — I think we can consolidate on that one.

Both make the same functional change at the same call sites:

  • Here: the local _strip_trailing_semicolon body goes from sql.rstrip().removesuffix(";").rstrip() (strips a single trailing ;) to _TRAILING_SEMICOLONS_RE.sub("", sql) (strips the whole terminating run).
  • refactor(connector): share strip_trailing_semicolon in base #2480: deletes trino's local helper and imports the shared strip_trailing_semicolon from connector/base.py, which is the same [;\s]+\Z regex, at the same call sites.

So the outcome is identical (SELECT 1;; / SELECT 1 ; ; now strip fully), but #2480 also removes the per-connector copy instead of keeping one — which is the whole point of the consolidation (#2441). The multi-semicolon fix from this PR is fully preserved by #2480, so nothing is lost.

Plan is to keep #2480 and close this one once it lands. Thanks for the fix — it's carried over intact.

@Bartok9

Bartok9 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Agreed — #2480 folding both call sites into the shared strip_trailing_semicolon is the right move over keeping trino's local copy (#2441). Behavior's identical and the multi-semicolon fix is preserved, so nothing lost. Feel free to close this in favor of #2480. Thanks @goldmedal! 🙏

@goldmedal

Copy link
Copy Markdown
Collaborator

@Bartok9, there are some conflicts. I think the PR should also use the shared trailing function.

@Bartok9

Bartok9 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @goldmedal! Since #2480 has now merged and carries this multi-semicolon fix intact via the shared strip_trailing_semicolon, this PR is fully superseded — closing in favor of #2480 as we agreed. Nothing lost. 🙏

@Bartok9 Bartok9 closed this Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants