Skip to content

SNOW-4038269: Record Session.semantic_view as a dedicated AST node - #4503

Merged
sfc-gh-jzeng merged 1 commit into
mainfrom
jzeng/snow-4038269-semantic-view-ast
Nov 13, 2026
Merged

sfc-gh-jzeng merged 1 commit into
mainfrom
jzeng/snow-4038269-semantic-view-ast

Conversation

@sfc-gh-jzeng

@sfc-gh-jzeng sfc-gh-jzeng commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator
  1. Which Jira issue is this PR addressing?

    Fixes SNOW-4038269

  2. 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. Description

    Session.semantic_view went through the generic sql AST node, so the AST held only the rendered SELECT * FROM SEMANTIC_VIEW(...) string. It now records a dedicated SemanticView node:

    • name is recorded as the caller passed it (a string or a sequence of parts, via build_table_name).
    • dimensions, metrics, facts and where are each an ExprArgList: a single string is variadic, a sequence has one argument per member.
    • The node is built after validation and rendering, so a call that raises leaves no bind behind, and it is passed to Session.sql as _ast_stmt so it replaces the generic sql node.

    Server side is not updated. The Snowpark AST server side is no longer maintained, so SemanticView is added to ast.proto by hand, with the next free numbers in Expr (207) and HasSrcPosition (216), and no monorepo IR or unparser change is made. No existing tag moves. As a result tests/ast/data/session_semantic_view.test has no unparser section.

    Tests: the new session_semantic_view.test and two unit tests in tests/unit/test_semantic_view.py.

    No user-visible change, so no CHANGELOG entry (NO-CHANGELOG-UPDATES).

@sfc-gh-jzeng sfc-gh-jzeng added the NO-CHANGELOG-UPDATES This pull request does not need to update CHANGELOG.md label Nov 12, 2026
@codecov-commenter

codecov-commenter commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.47%. Comparing base (aad22f1) to head (dd6531c).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4503   +/-   ##
=======================================
  Coverage   95.47%   95.47%           
=======================================
  Files         179      179           
  Lines       46927    46937   +10     
  Branches     8110     8111    +1     
=======================================
+ Hits        44803    44815   +12     
+ Misses       1332     1331    -1     
+ Partials      792      791    -1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sfc-gh-jzeng
sfc-gh-jzeng force-pushed the jzeng/snow-4038269-semantic-view-ast branch from d0c90f6 to d33b964 Compare November 12, 2026 22:02
Session.semantic_view passed through the generic sql node, so the AST
held only the rendered SELECT * FROM SEMANTIC_VIEW(...) string and the
view name and clauses were lost.

Build a SemanticView node instead. The name is recorded as the caller
passed it (a string or a sequence of parts) through build_table_name,
and each clause as an ExprArgList: a single string is variadic, a
sequence has one argument per member. The node is built after
validation and rendering, so a call that raises leaves no bind behind,
and it is handed to Session.sql as _ast_stmt so it replaces the generic
sql node.

The SemanticView message is added to ast.proto by hand, with the next
free arm numbers in Expr (207) and HasSrcPosition (216), so no existing
tag changes. The golden file has no unparser section because no
unparser handles the new node.

The unit test fixture sets _ast_batch, which create_autospec(Session)
does not provide because Session.__init__ never runs.
@sfc-gh-jzeng
sfc-gh-jzeng force-pushed the jzeng/snow-4038269-semantic-view-ast branch from d33b964 to dd6531c Compare November 12, 2026 22:02
@sfc-gh-jzeng
sfc-gh-jzeng marked this pull request as ready for review November 12, 2026 22:04
@sfc-gh-jzeng
sfc-gh-jzeng requested a review from a team as a code owner November 12, 2026 22:04
Comment thread src/snowflake/snowpark/session.py Resolved

@sfc-gh-yixie sfc-gh-yixie left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. I checked that tags 207 and 216 are free on main, that the unit tests and the new AST golden test pass, and that the AST name builder accepts every name that validate_object_name accepts. One optional suggestion inline.

-- Sent by Claude


🤖 Posted by an AI agent (Claude Code · skill pr-review) on behalf of @sfc-gh-yixie.

assert [a.string_val.v for a in node.where.args] == ["a = 1", "b = 2"]


def test_no_ast_node_when_emit_ast_is_false(fake_session):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[suggestion] The description says a call that raises leaves no bind behind, but neither new test checks it. Could a small test lock that in? For example, call with an empty metrics and _emit_ast=True, then assert fake_session._ast_batch has no statements.

-- Sent by Claude


🤖 Posted by an AI agent (Claude Code · skill pr-review) on behalf of @sfc-gh-yixie.

@sfc-gh-jzeng
sfc-gh-jzeng merged commit 4316e45 into main Nov 13, 2026
36 of 37 checks passed
@sfc-gh-jzeng
sfc-gh-jzeng deleted the jzeng/snow-4038269-semantic-view-ast branch November 13, 2026 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NO-CHANGELOG-UPDATES This pull request does not need to update CHANGELOG.md

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants