Skip to content

Fix presto_unnest() CTE handling and mark as experimental#313

Merged
jarodmeng merged 1 commit intoprestodb:masterfrom
jarodmeng:master
Nov 10, 2025
Merged

Fix presto_unnest() CTE handling and mark as experimental#313
jarodmeng merged 1 commit intoprestodb:masterfrom
jarodmeng:master

Conversation

@jarodmeng
Copy link
Copy Markdown
Contributor

  • Fix SQL generation to not wrap simple table/CTE names in parentheses when presto_unnest() is called on a CTE. This was causing CTE detection to fail in nested CTE scenarios.
  • Mark presto_unnest() as experimental using lifecycle badge due to recent bug reports and fixes.
  • Add test case for operation -> CTE -> presto_unnest -> CTE scenario to ensure the fix is covered by the test suite.

The debugging was mainly done by the package author, but the fix is implemented by the Cursor AI.

- Fix SQL generation to not wrap simple table/CTE names in parentheses
  when presto_unnest() is called on a CTE. This was causing CTE detection
  to fail in nested CTE scenarios.
- Mark presto_unnest() as experimental using lifecycle badge due to
  recent bug reports and fixes.
- Add test case for operation -> CTE -> presto_unnest -> CTE scenario
  to ensure the fix is covered by the test suite.
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Nov 10, 2025

Reviewer's Guide

This PR refines the SQL rendering in presto_unnest to skip wrapping simple table/CTE names, annotates presto_unnest() as experimental, and adds a targeted test for an operation→CTE→presto_unnest→CTE workflow.

Sequence diagram for SQL rendering in presto_unnest() with CTE handling

sequenceDiagram
    participant Caller
    participant presto_unnest
    participant sql_render_unnest_query
    participant dbplyr_build_sql
    Caller->>presto_unnest: Call with table or CTE
    presto_unnest->>sql_render_unnest_query: Render SQL
    sql_render_unnest_query->>dbplyr_build_sql: If input starts with SELECT (complex subquery)
    dbplyr_build_sql-->>sql_render_unnest_query: Return SQL with parentheses
    sql_render_unnest_query->>dbplyr_build_sql: If input is simple table/CTE name
    dbplyr_build_sql-->>sql_render_unnest_query: Return SQL without parentheses
    sql_render_unnest_query-->>presto_unnest: Return final SQL
    presto_unnest-->>Caller: Return result
Loading

File-Level Changes

Change Details Files
Conditional wrapping of source SQL in parentheses when generating CROSS JOIN UNNEST
  • Extract from_sql into string and trim whitespace
  • Check if trimmed SQL starts with "SELECT" to identify complex subqueries
  • Wrap only complex subqueries in parentheses, leave simple table/CTE names unwrapped
R/presto_unnest.R
Mark presto_unnest() as experimental
  • Add lifecycle::badge("experimental") to function description
  • Include @importFrom lifecycle badge in R code
  • Embed experimental badge markup in man/presto_unnest.Rd
R/presto_unnest.R
man/presto_unnest.Rd
Add test covering operation→CTE→presto_unnest→CTE scenario
  • Create temporary test table and insert array data
  • Build first CTE via filter, apply presto_unnest to produce second CTE
  • Collect results and assert row count, column names, and values
tests/testthat/test-presto_unnest.R

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • The string-based check for wrapping subqueries (looking for a leading “SELECT”) may misclassify more complex query sources—consider using dbplyr’s query AST to robustly distinguish simple table/CTE names from subqueries.
  • I didn’t see an importFrom(lifecycle, badge) entry in the NAMESPACE diff—double-check that the lifecycle badge is actually imported so the experimental tag renders correctly.
  • The new CTE integration test has a lot of setup/teardown boilerplate—consider extracting common connection and CTE management into a helper to reduce duplication and improve readability.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The string-based check for wrapping subqueries (looking for a leading “SELECT”) may misclassify more complex query sources—consider using dbplyr’s query AST to robustly distinguish simple table/CTE names from subqueries.
- I didn’t see an importFrom(lifecycle, badge) entry in the NAMESPACE diff—double-check that the lifecycle badge is actually imported so the experimental tag renders correctly.
- The new CTE integration test has a lot of setup/teardown boilerplate—consider extracting common connection and CTE management into a helper to reduce duplication and improve readability.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@jarodmeng jarodmeng merged commit 3859b8e into prestodb:master Nov 10, 2025
8 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.

1 participant