Skip to content

Conversation

@m1so
Copy link
Member

@m1so m1so commented Nov 6, 2025

Summary by CodeRabbit

  • New Features

    • Automatic detection of SQL parameter styles for broader SQL engine compatibility and improved handling of parameter lists.
  • Documentation

    • Expanded docstrings and inline comments with examples clarifying parameter-style behavior.
  • Tests

    • Added unit and integration tests for connectivity, param-style auto-detection, templating, and SQL execution flows.
  • Chores

    • Ignore environment variant files (".env.*").
    • Added python-dotenv to development dependencies.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 6, 2025

📝 Walkthrough

Walkthrough

Adds auto-detection of SQL param_style from connection URL (maps Trino driver → qmark) when param_style is unset, and converts list bind_params to tuples for compatibility with qmark/format before calling pandas.read_sql_query. Expands docstrings/comments in Jinja SQL utilities. Adds python-dotenv to dev dependencies and updates .gitignore to ignore .env.*. Introduces new Trino integration tests and unit tests for param-style auto-detection (the unit tests include a duplicated test class in the diff).

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant execute_sql
    participant render_jinja_sql_template
    participant ParamStyleAutoDetect
    participant prepare_params
    participant pandas.read_sql_query

    Caller->>execute_sql: call execute_sql(sql, conn_url, bind_params?, param_style?)
    execute_sql->>render_jinja_sql_template: render templates (if any)
    render_jinja_sql_template-->>execute_sql: rendered_sql, rendered_bind_params

    execute_sql->>ParamStyleAutoDetect: was param_style provided?
    alt param_style is None
        ParamStyleAutoDetect->>ParamStyleAutoDetect: extract driver from URL
        ParamStyleAutoDetect-->>execute_sql: detected param_style (e.g., trino -> "qmark")
    else
        ParamStyleAutoDetect-->>execute_sql: use explicit param_style
    end

    execute_sql->>prepare_params: evaluate bind_params vs param_style
    alt param_style in ["qmark","format"] and bind_params is list
        prepare_params->>prepare_params: convert list -> tuple
        prepare_params-->>execute_sql: prepared_params (tuple)
    else
        prepare_params-->>execute_sql: prepared_params (unchanged)
    end

    execute_sql->>pandas.read_sql_query: call with rendered_sql and prepared_params
    pandas.read_sql_query-->>execute_sql: DataFrame
    execute_sql-->>Caller: return DataFrame
Loading

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 77.78% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: auto-detection of Trino SQL parameter styles and new integration tests for Trino connectivity and execution.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bf91615 and 3a71961.

📒 Files selected for processing (1)
  • tests/unit/test_sql_execution.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/unit/test_sql_execution.py (1)
deepnote_toolkit/sql/sql_execution.py (2)
  • execute_sql_with_connection_json (73-194)
  • _execute_sql_on_engine (405-451)
🪛 Ruff (0.14.3)
tests/unit/test_sql_execution.py

311-311: Use a regular assert instead of unittest-style assertEqual

Replace assertEqual(...) with assert ...

(PT009)


340-340: Use a regular assert instead of unittest-style assertIsNone

Replace assertIsNone(...) with assert ...

(PT009)


371-371: Use a regular assert instead of unittest-style assertEqual

Replace assertEqual(...) with assert ...

(PT009)


401-401: Use a regular assert instead of unittest-style assertIsNone

Replace assertIsNone(...) with assert ...

(PT009)


432-432: Use a regular assert instead of unittest-style assertEqual

Replace assertEqual(...) with assert ...

(PT009)


437-437: Use a regular assert instead of unittest-style assertIsInstance

Replace assertIsInstance(...) with assert ...

(PT009)


438-438: Use a regular assert instead of unittest-style assertEqual

Replace assertEqual(...) with assert ...

(PT009)


465-465: Use a regular assert instead of unittest-style assertTrue

Replace assertTrue(...) with assert ...

(PT009)


472-472: Use a regular assert instead of unittest-style assertIsInstance

Replace assertIsInstance(...) with assert ...

(PT009)


473-473: Use a regular assert instead of unittest-style assertEqual

Replace assertEqual(...) with assert ...

(PT009)


500-500: Use a regular assert instead of unittest-style assertTrue

Replace assertTrue(...) with assert ...

(PT009)


507-507: Use a regular assert instead of unittest-style assertIsInstance

Replace assertIsInstance(...) with assert ...

(PT009)


508-508: Use a regular assert instead of unittest-style assertEqual

Replace assertEqual(...) with assert ...

(PT009)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Test - Python 3.10
  • GitHub Check: Test - Python 3.13
  • GitHub Check: Test - Python 3.11
  • GitHub Check: Test - Python 3.9
  • GitHub Check: Build and push artifacts for Python 3.9
  • GitHub Check: Build and push artifacts for Python 3.10
  • GitHub Check: Build and push artifacts for Python 3.11
  • GitHub Check: Build and push artifacts for Python 3.13
  • GitHub Check: Build and push artifacts for Python 3.12
🔇 Additional comments (1)
tests/unit/test_sql_execution.py (1)

281-509: Comprehensive test coverage for Trino param_style auto-detection.

The test suite thoroughly covers:

  • Auto-detection of qmark for Trino URLs
  • Preservation of None for non-Trino databases
  • Explicit param_style not being overridden
  • URL variant exclusion (trino+rest doesn't match)
  • Jinja template integration with qmark
  • List→tuple conversion for pandas compatibility
  • Dict preservation for named parameters

Mocking and assertions are correct.

Note: Static analysis suggests replacing unittest-style assertions with regular assert, but the entire file consistently uses unittest.TestCase style. Changing only these tests would create inconsistency.


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

@github-actions
Copy link

github-actions bot commented Nov 6, 2025

📦 Python package built successfully!

  • Version: 1.1.0.dev5+09208c4
  • Wheel: deepnote_toolkit-1.1.0.dev5+09208c4-py3-none-any.whl
  • Install:
    pip install "deepnote-toolkit @ https://deepnote-staging-runtime-artifactory.s3.amazonaws.com/deepnote-toolkit-packages/1.1.0.dev5%2B09208c4/deepnote_toolkit-1.1.0.dev5%2B09208c4-py3-none-any.whl"

@codecov
Copy link

codecov bot commented Nov 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.36%. Comparing base (f5a2f7d) to head (3a71961).
⚠️ Report is 19 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #22      +/-   ##
==========================================
- Coverage   76.60%   75.36%   -1.25%     
==========================================
  Files          99       99              
  Lines        5476     5606     +130     
  Branches      748      783      +35     
==========================================
+ Hits         4195     4225      +30     
- Misses       1281     1381     +100     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 67a97b4 and 2629f87.

⛔ Files ignored due to path filters (1)
  • poetry.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • .gitignore (1 hunks)
  • deepnote_toolkit/sql/jinjasql_utils.py (1 hunks)
  • deepnote_toolkit/sql/sql_execution.py (2 hunks)
  • pyproject.toml (1 hunks)
  • tests/integration/test_trino.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/integration/test_trino.py (1)
deepnote_toolkit/sql/sql_execution.py (1)
  • execute_sql (197-233)
🪛 Ruff (0.14.3)
tests/integration/test_trino.py

156-156: Missing return type annotation for private function mock_get_variable_value

(ANN202)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
  • GitHub Check: Test - Python 3.11
  • GitHub Check: Test - Python 3.13
  • GitHub Check: Test - Python 3.9
  • GitHub Check: Test - Python 3.10
  • GitHub Check: Typecheck - 3.13
  • GitHub Check: Test - Python 3.12
  • GitHub Check: Typecheck - 3.9
  • GitHub Check: Typecheck - 3.12
  • GitHub Check: Build and push artifacts for Python 3.11
  • GitHub Check: Build and push artifacts for Python 3.12
  • GitHub Check: Build and push artifacts for Python 3.10
  • GitHub Check: Build and push artifacts for Python 3.13
  • GitHub Check: Build and push artifacts for Python 3.9
🔇 Additional comments (12)
deepnote_toolkit/sql/jinjasql_utils.py (1)

17-17: Good documentation improvements.

The added examples and clarifications about parameter styles help developers understand the default behavior and database-specific requirements.

Also applies to: 25-26

pyproject.toml (1)

179-180: LGTM.

The python-dotenv dev dependency supports environment-based credential loading in integration tests.

deepnote_toolkit/sql/sql_execution.py (2)

154-161: Auto-detection logic looks correct.

The mapping approach is extensible. Currently only Trino is mapped to qmark, which aligns with the PR objectives.


438-446: Correct handling of parameter types for pandas.

The tuple conversion ensures compatibility with qmark/format parameter styles while preserving dict params for pyformat style.

tests/integration/test_trino.py (8)

18-24: Clean context manager design.

Ensures environment variable cleanup via try/finally block.


27-56: Well-designed credential management.

Loads from .env, skips gracefully if unavailable, and provides sensible defaults. Credentials stay in gitignored .env file.


59-81: Proper connection lifecycle management.

Module-scoped fixture with optional authentication and guaranteed cleanup via try/finally.


110-135: Well-constructed toolkit connection fixture.

Properly URL-encodes credentials and explicitly sets qmark param_style for Trino.


84-107: Effective baseline connectivity tests.

Simple smoke tests validate connection and catalog access before proceeding to toolkit integration tests.


141-150: Solid baseline toolkit test.

Validates execute_sql with a simple query, checking DataFrame structure and content.


152-177: Good coverage of Jinja templating integration.

Mock-based test validates variable substitution for both string and numeric types.


179-227: Critical test for the auto-detection fix.

Validates the regression fix (BLU-5135) by omitting param_style and verifying auto-detection works correctly. This test directly validates the core PR functionality.

@deepnote-bot
Copy link

deepnote-bot commented Nov 6, 2025

🚀 Review App Deployment Started

📝 Description 🌐 Link / Info
🌍 Review application ra-22
🔑 Sign-in URL Click to sign-in
📊 Application logs View logs
🔄 Actions Click to redeploy
🚀 ArgoCD deployment View deployment
Last deployed 2025-11-06 22:45:25 (UTC)
📜 Deployed commit fee1f1ccc465d293b4175a83bab16c18cc5fd6ab
🛠️ Toolkit version 09208c4

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2629f87 and baf1f3e.

📒 Files selected for processing (2)
  • .gitignore (1 hunks)
  • tests/unit/test_sql_execution.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/unit/test_sql_execution.py (1)
deepnote_toolkit/sql/sql_execution.py (1)
  • execute_sql_with_connection_json (73-194)
🪛 Ruff (0.14.3)
tests/unit/test_sql_execution.py

313-313: Use a regular assert instead of unittest-style assertEqual

Replace assertEqual(...) with assert ...

(PT009)


344-344: Use a regular assert instead of unittest-style assertIsNone

Replace assertIsNone(...) with assert ...

(PT009)


377-377: Use a regular assert instead of unittest-style assertEqual

Replace assertEqual(...) with assert ...

(PT009)


409-409: Use a regular assert instead of unittest-style assertIsNone

Replace assertIsNone(...) with assert ...

(PT009)


432-432: Local variable result is assigned to but never used

Remove assignment to unused variable result

(F841)


440-440: Use a regular assert instead of unittest-style assertEqual

Replace assertEqual(...) with assert ...

(PT009)


445-445: Use a regular assert instead of unittest-style assertIsInstance

Replace assertIsInstance(...) with assert ...

(PT009)


446-446: Use a regular assert instead of unittest-style assertEqual

Replace assertEqual(...) with assert ...

(PT009)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Test - Python 3.10
  • GitHub Check: Test - Python 3.13
  • GitHub Check: Test - Python 3.11
  • GitHub Check: Test - Python 3.9
  • GitHub Check: Build and push artifacts for Python 3.13
  • GitHub Check: Build and push artifacts for Python 3.11
  • GitHub Check: Build and push artifacts for Python 3.12
  • GitHub Check: Build and push artifacts for Python 3.9
  • GitHub Check: Build and push artifacts for Python 3.10
🔇 Additional comments (2)
.gitignore (1)

135-136: Good addition for environment variant handling.

Adding .env.* alongside the existing .env entry appropriately ignores environment-specific config files (.env.local, .env.test, etc.) while keeping the base pattern intact. This aligns well with the PR's addition of python-dotenv and integration tests.

tests/unit/test_sql_execution.py (1)

281-447: Comprehensive test coverage for Trino param_style auto-detection.

The test suite thoroughly validates the auto-detection feature across multiple scenarios: default Trino behavior, non-Trino databases, explicit overrides, edge cases, and Jinja template integration. Well-structured and properly mocked.

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 6, 2025
@m1so m1so marked this pull request as ready for review November 6, 2025 22:30
@m1so m1so requested a review from a team as a code owner November 6, 2025 22:30
@m1so m1so merged commit 5eddb88 into main Nov 6, 2025
33 of 34 checks passed
@m1so m1so deleted the mb/fix-trino-sql branch November 6, 2025 22:45
@FilipPyrek
Copy link
Member

Approved 👍

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.

4 participants