Skip to content

SNOW-3265360: Wrap SQL text UnresolvedAttribute with parenthesis#4141

Merged
sfc-gh-mayliu merged 2 commits intomainfrom
SNOW-3265360-wrap-sql-str-expr-parenthesis
Mar 26, 2026
Merged

SNOW-3265360: Wrap SQL text UnresolvedAttribute with parenthesis#4141
sfc-gh-mayliu merged 2 commits intomainfrom
SNOW-3265360-wrap-sql-str-expr-parenthesis

Conversation

@sfc-gh-mayliu
Copy link
Copy Markdown
Collaborator

@sfc-gh-mayliu sfc-gh-mayliu commented Mar 26, 2026

  1. Which Jira issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Fixes SNOW-3265360

  2. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
      • If this test skips Local Testing mode, I'm requesting review from @snowflakedb/local-testing
    • I am adding new logging messages
    • I am adding a new telemetry message
    • I am adding new credentials
    • I am adding a new dependency
    • If this is a new feature/behavior, I'm adding the Local Testing parity changes.
    • I acknowledge that I have ensured my changes to be thread-safe. Follow the link for more information: Thread-safe Developer Guidelines
    • If adding any arguments to public Snowpark APIs or creating new public Snowpark APIs, I acknowledge that I have ensured my changes include AST support. Follow the link for more information: AST Support Guidelines
  3. Please describe how your code solves the related issue.

    Please write a short description of how your code change solves the related issue.

When chaining DataFrame.filter() calls with raw SQL text strings, the SQL simplifier combines the conditions without parenthesizing the raw SQL operands. This produces wrong query results.

Repro:
buggy_df = df.filter("col1 = 'X' or col2 = 'Y'").filter("col3 = 'Z'")
Originally produced
WHERE (col1 = 'X' OR col2 = 'Y' AND col3 = 'Z')

However, AND binds tighter than OR, which produces wrong result. The correct behavior should be
WHERE ((col1 = 'X' OR col2 = 'Y') AND (col3 = 'Z'))

@sfc-gh-mayliu sfc-gh-mayliu requested review from a team and sfc-gh-helmeleegy March 26, 2026 21:13
Copy link
Copy Markdown
Contributor

@sfc-gh-helmeleegy sfc-gh-helmeleegy left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@sfc-gh-mayliu sfc-gh-mayliu merged commit b917623 into main Mar 26, 2026
33 of 37 checks passed
@sfc-gh-mayliu sfc-gh-mayliu deleted the SNOW-3265360-wrap-sql-str-expr-parenthesis branch March 26, 2026 23:12
@github-actions github-actions bot locked and limited conversation to collaborators Mar 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants