Skip to content

Commit ba31301

Browse files
authored
SNOW-981562: Expose is_temp_table_for_cleanup to Session.table (#2784)
1 parent 69c41a2 commit ba31301

File tree

2 files changed

+188
-2
lines changed

2 files changed

+188
-2
lines changed

src/snowflake/snowpark/session.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,7 +2268,12 @@ def update_query_tag(self, tag: dict) -> None:
22682268
)
22692269

22702270
@publicapi
2271-
def table(self, name: Union[str, Iterable[str]], _emit_ast: bool = True) -> Table:
2271+
def table(
2272+
self,
2273+
name: Union[str, Iterable[str]],
2274+
is_temp_table_for_cleanup: bool = False,
2275+
_emit_ast: bool = True,
2276+
) -> Table:
22722277
"""
22732278
Returns a Table that points the specified table.
22742279
@@ -2302,13 +2307,20 @@ def table(self, name: Union[str, Iterable[str]], _emit_ast: bool = True) -> Tabl
23022307
elif isinstance(name, Iterable):
23032308
ast.name.sp_table_name_structured.name.extend(name)
23042309
ast.variant.sp_session_table = True
2310+
ast.is_temp_table_for_cleanup = is_temp_table_for_cleanup
23052311
else:
23062312
stmt = None
23072313

23082314
if not isinstance(name, str) and isinstance(name, Iterable):
23092315
name = ".".join(name)
23102316
validate_object_name(name)
2311-
t = Table(name, session=self, _ast_stmt=stmt, _emit_ast=_emit_ast)
2317+
t = Table(
2318+
name,
2319+
session=self,
2320+
is_temp_table_for_cleanup=is_temp_table_for_cleanup,
2321+
_ast_stmt=stmt,
2322+
_emit_ast=_emit_ast,
2323+
)
23122324
# Replace API call origin for table
23132325
set_api_call_source(t, "Session.table")
23142326
return t
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
## TEST CASE
2+
3+
df1 = session.table(f"mock_schema.{tables.table1}", is_temp_table_for_cleanup=True)
4+
df2 = session.table(f"mock_schema.{tables.table1}", is_temp_table_for_cleanup=False)
5+
df = df1.union_all(df2).select("num")
6+
7+
## EXPECTED UNPARSER OUTPUT
8+
9+
df1 = session.table("mock_schema.table1", is_temp_table_for_cleanup=True)
10+
11+
df2 = session.table("mock_schema.table1")
12+
13+
df = df1.union_all(df2)
14+
15+
df = df.select(col("num"))
16+
17+
## EXPECTED ENCODED AST
18+
19+
body {
20+
assign {
21+
expr {
22+
sp_table {
23+
is_temp_table_for_cleanup: true
24+
name {
25+
sp_table_name_flat {
26+
name: "mock_schema.table1"
27+
}
28+
}
29+
src {
30+
file: "SRC_POSITION_TEST_MODE"
31+
start_line: 25
32+
}
33+
variant {
34+
sp_session_table: true
35+
}
36+
}
37+
}
38+
symbol {
39+
value: "df1"
40+
}
41+
uid: 1
42+
var_id {
43+
bitfield1: 1
44+
}
45+
}
46+
}
47+
body {
48+
assign {
49+
expr {
50+
sp_table {
51+
name {
52+
sp_table_name_flat {
53+
name: "mock_schema.table1"
54+
}
55+
}
56+
src {
57+
file: "SRC_POSITION_TEST_MODE"
58+
start_line: 26
59+
}
60+
variant {
61+
sp_session_table: true
62+
}
63+
}
64+
}
65+
symbol {
66+
value: "df2"
67+
}
68+
uid: 2
69+
var_id {
70+
bitfield1: 2
71+
}
72+
}
73+
}
74+
body {
75+
assign {
76+
expr {
77+
sp_dataframe_union_all {
78+
df {
79+
sp_dataframe_ref {
80+
id {
81+
bitfield1: 1
82+
}
83+
}
84+
}
85+
other {
86+
sp_dataframe_ref {
87+
id {
88+
bitfield1: 2
89+
}
90+
}
91+
}
92+
src {
93+
file: "SRC_POSITION_TEST_MODE"
94+
start_line: 27
95+
}
96+
}
97+
}
98+
symbol {
99+
value: "df"
100+
}
101+
uid: 3
102+
var_id {
103+
bitfield1: 3
104+
}
105+
}
106+
}
107+
body {
108+
assign {
109+
expr {
110+
sp_dataframe_select__columns {
111+
cols {
112+
apply_expr {
113+
fn {
114+
builtin_fn {
115+
name {
116+
fn_name_flat {
117+
name: "col"
118+
}
119+
}
120+
}
121+
}
122+
pos_args {
123+
string_val {
124+
src {
125+
file: "SRC_POSITION_TEST_MODE"
126+
start_line: 27
127+
}
128+
v: "num"
129+
}
130+
}
131+
src {
132+
file: "SRC_POSITION_TEST_MODE"
133+
start_line: 27
134+
}
135+
}
136+
}
137+
df {
138+
sp_dataframe_ref {
139+
id {
140+
bitfield1: 3
141+
}
142+
}
143+
}
144+
src {
145+
file: "SRC_POSITION_TEST_MODE"
146+
start_line: 27
147+
}
148+
variadic: true
149+
}
150+
}
151+
symbol {
152+
value: "df"
153+
}
154+
uid: 4
155+
var_id {
156+
bitfield1: 4
157+
}
158+
}
159+
}
160+
client_ast_version: 1
161+
client_language {
162+
python_language {
163+
version {
164+
label: "final"
165+
major: 3
166+
minor: 9
167+
patch: 1
168+
}
169+
}
170+
}
171+
client_version {
172+
major: 1
173+
minor: 26
174+
}

0 commit comments

Comments
 (0)