Repository navigation
SNOW-4038269: Record Session.semantic_view as a dedicated AST node - #4503
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
d0c90f6 to
d33b964
Compare
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.
d33b964 to
dd6531c
Compare
sfc-gh-yixie
left a comment
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
[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.
Which Jira issue is this PR addressing?
Fixes SNOW-4038269
Pre-review checklist:
Description
Session.semantic_viewwent through the genericsqlAST node, so the AST held only the renderedSELECT * FROM SEMANTIC_VIEW(...)string. It now records a dedicatedSemanticViewnode:nameis recorded as the caller passed it (a string or a sequence of parts, viabuild_table_name).dimensions,metrics,factsandwhereare each anExprArgList: a single string is variadic, a sequence has one argument per member.Session.sqlas_ast_stmtso it replaces the genericsqlnode.Server side is not updated. The Snowpark AST server side is no longer maintained, so
SemanticViewis added toast.protoby hand, with the next free numbers inExpr(207) andHasSrcPosition(216), and no monorepo IR or unparser change is made. No existing tag moves. As a resulttests/ast/data/session_semantic_view.testhas no unparser section.Tests: the new
session_semantic_view.testand two unit tests intests/unit/test_semantic_view.py.No user-visible change, so no CHANGELOG entry (
NO-CHANGELOG-UPDATES).