Skip to content

chore(databricks): add the test for stripping trailing semicolon before query execute#2536

Closed
Bartok9 wants to merge 1 commit into
Canner:mainfrom
Bartok9:fix/databricks-strip-query-semicolon
Closed

chore(databricks): add the test for stripping trailing semicolon before query execute#2536
Bartok9 wants to merge 1 commit into
Canner:mainfrom
Bartok9:fix/databricks-strip-query-semicolon

Conversation

@Bartok9

@Bartok9 Bartok9 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Databricks query() executed raw SQL including trailing ;.
  • dry_run already stripped for subquery wrap.
  • Strip once before execute so both limited-fetch and full-fetch paths are consistent.

License

core/wren/** Apache-2.0.

Verification

python3 -m pytest core/wren/tests/unit/test_databricks_strip_query_semicolon.py -q

Summary by CodeRabbit

  • Tests
    • Added coverage to verify that trailing semicolons are removed from Databricks queries before execution.
    • Confirmed the behavior handles trailing whitespace alongside the semicolon.

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

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds a unit test that verifies the Databricks connector’s query path calls strip_trailing_semicolon and removes a trailing semicolon from SQL.

Changes

Databricks query SQL handling

Layer / File(s) Summary
Query semicolon normalization test
core/wren/tests/unit/test_databricks_strip_query_semicolon.py
Inspects the connector source to confirm semicolon stripping occurs in query, then validates removal of the trailing semicolon from SELECT 1;.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Possibly related issues

Possibly related PRs

  • Canner/WrenAI#2477 — Directly addresses Databricks query handling and trailing-semicolon stripping with related tests.
  • Canner/WrenAI#2537 — Verifies analogous query semicolon-stripping behavior in another connector.
  • Canner/WrenAI#2489 — Adds corresponding connector query coverage for trailing-semicolon removal.

Suggested reviewers: goldmedal

Poem

A bunny checked the query line,
And found the semicolon sign.
“Strip it clean before we run!”
The test now proves the work is done.
Hop, hop—SQL is fine!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: adding a Databricks regression test for stripping trailing semicolons before query execution.
✨ 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.

@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_databricks_strip_query_semicolon.py`:
- Around line 9-23: Replace the source-text and duplicate-regex assertions in
test_query_strips_trailing_semicolon with a mocked Databricks connection/cursor
setup. Instantiate DatabricksConnector with the mocks, invoke query("SELECT
1;"), and assert the cursor’s execute call receives exactly "SELECT 1".
🪄 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: cbfbfe7e-451e-416e-8539-5cc766a741ba

📥 Commits

Reviewing files that changed from the base of the PR and between 3dac00a and bb6fb10.

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

Comment on lines +9 to +23
def test_query_strips_trailing_semicolon():
src = (
Path(__file__).resolve().parents[2]
/ "src"
/ "wren"
/ "connector"
/ "databricks.py"
).read_text(encoding="utf-8")
assert "sql = strip_trailing_semicolon(sql)" in src
# appears in query, not only dry_run
q = src.split("def query", 1)[1].split("def dry_run", 1)[0]
assert "strip_trailing_semicolon" in q

helper = re.compile(r"[;\s]+\Z")
assert helper.sub("", "SELECT 1;") == "SELECT 1"

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Exercise DatabricksConnector.query instead of inspecting source text.

This test can pass even if query() sends the semicolon-terminated SQL to cursor.execute, because it only searches the file and tests a duplicate local regex. Mock the connection/cursor, invoke query("SELECT 1;"), and assert execute receives "SELECT 1".

🤖 Prompt for 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.

In `@core/wren/tests/unit/test_databricks_strip_query_semicolon.py` around lines 9
- 23, Replace the source-text and duplicate-regex assertions in
test_query_strips_trailing_semicolon with a mocked Databricks connection/cursor
setup. Instantiate DatabricksConnector with the mocks, invoke query("SELECT
1;"), and assert the cursor’s execute call receives exactly "SELECT 1".

@goldmedal

Copy link
Copy Markdown
Collaborator

@Bartok9 there are some conflict.

dry_run already stripped for subquery wrap; query forwarded client
terminators. Strip before execute for limited and unlimited paths.
@Bartok9
Bartok9 force-pushed the fix/databricks-strip-query-semicolon branch from bb6fb10 to 4ae100a Compare July 24, 2026 02:28
@Bartok9

Bartok9 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @goldmedal! Rebased onto latest main and resolved the conflict. Since the query() semicolon strip already landed on main (via the shared strip_trailing_semicolon refactor), this PR now just adds the regression test guarding that the query path keeps applying it. Ready for another look. 🙏

@goldmedal goldmedal changed the title fix(databricks): strip trailing semicolon before query execute chore(databricks): add the test for stripping trailing semicolon before query execute Jul 24, 2026
@goldmedal

Copy link
Copy Markdown
Collaborator

The test case isn't necessary. Let's close this PR.

@goldmedal goldmedal closed this Jul 24, 2026
@Bartok9

Bartok9 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

No problem at all, thanks for taking a look @goldmedal! Makes sense to keep the suite lean since the strip is already covered. Appreciate the quick feedback. 🙏

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