Skip to content

Commit 25dd36a

Browse files
sfc-gh-joshiclaude
andcommitted
SNOW-3489991: block flattening of dropped NEW columns in connect mode
In can_select_statement_be_flattened, the existing guard only refused to flatten when a dropped NEW column was also is_referenced_by_same_level_column. This missed the case where a future filter/sort (not yet added at select() time) references the dropped column, generating invalid SQL. In connect mode, extend the guard to block flattening unconditionally when a NEW column is dropped. This preserves the defining subquery and keeps the column visible to subsequent WHERE/ORDER BY clauses. Non-connect behavior is unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9975596 commit 25dd36a

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/snowflake/snowpark/_internal/analyzer/select_statement.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2219,7 +2219,12 @@ def can_select_statement_be_flattened(
22192219
state.change_state == ColumnChangeState.DROPPED
22202220
and (subquery_state := subquery_column_states.get(col))
22212221
and subquery_state.change_state == ColumnChangeState.NEW
2222-
and subquery_state.is_referenced_by_same_level_column
2222+
and (
2223+
subquery_state.is_referenced_by_same_level_column
2224+
# In connect mode, preserve the subquery so that future
2225+
# filter/sort clauses can still reference the dropped NEW column.
2226+
or context._is_snowpark_connect_compatible_mode
2227+
)
22232228
):
22242229
return False
22252230
return True

0 commit comments

Comments
 (0)