Skip to content

Commit 7f5c5de

Browse files
committed
No flatten if dropped columns after order by / sort
1 parent d72a47b commit 7f5c5de

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,18 @@ def select(self, cols: List[Expression]) -> "SelectStatement":
13761376
subquery_dependent_columns & new_column_states.active_columns
13771377
)
13781378
)
1379+
or (
1380+
new_column_states.dropped_columns
1381+
and any(
1382+
new_column_states[_col].change_state == ColumnChangeState.DROPPED
1383+
and self.column_states[_col].change_state
1384+
in (ColumnChangeState.NEW, ColumnChangeState.CHANGED_EXP)
1385+
and _col in subquery_dependent_columns
1386+
for _col in (new_column_states.dropped_columns)
1387+
)
1388+
)
13791389
):
1390+
# or (new_column_states[_col].change_state == ColumnChangeState.DROPPED and self.column_states[_col].change_state in (ColumnChangeState.NEW, ColumnChangeState.CHANGED_EXP))
13801391
can_be_flattened = False
13811392
elif self.order_by and (
13821393
(subquery_dependent_columns := derive_dependent_columns(*self.order_by))
@@ -1388,6 +1399,16 @@ def select(self, cols: List[Expression]) -> "SelectStatement":
13881399
subquery_dependent_columns & new_column_states.active_columns
13891400
)
13901401
)
1402+
or (
1403+
new_column_states.dropped_columns
1404+
and any(
1405+
new_column_states[_col].change_state == ColumnChangeState.DROPPED
1406+
and self.column_states[_col].change_state
1407+
in (ColumnChangeState.NEW, ColumnChangeState.CHANGED_EXP)
1408+
and _col in subquery_dependent_columns
1409+
for _col in (new_column_states.dropped_columns)
1410+
)
1411+
)
13911412
):
13921413
can_be_flattened = False
13931414
elif self.distinct_:

0 commit comments

Comments
 (0)