Skip to content

Commit 83aa01c

Browse files
committed
test coverage
1 parent 8d9a4f1 commit 83aa01c

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -916,13 +916,10 @@ def _process_partition_by_in_iceberg_config(
916916
Process partition_by expressions from iceberg_config, converting Column objects to SQL strings.
917917
Returns a new iceberg_config dict with partition_by as a list of SQL strings, or the original config if no processing needed.
918918
"""
919-
if not iceberg_config:
919+
if iceberg_config is None or iceberg_config.get("partition_by") is None:
920920
return iceberg_config
921921

922922
iceberg_config = {k.lower(): v for k, v in iceberg_config.items()}
923-
924-
if not iceberg_config.get("partition_by"):
925-
return iceberg_config
926923
pb = iceberg_config["partition_by"]
927924

928925
# Convert to list and filter out empty expressions

tests/integ/scala/test_dataframe_writer_suite.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ def test_iceberg_partition_by(session, local_testing_mode):
295295
),
296296
)
297297

298+
# Test 1: Single string value
298299
table_name_1 = Utils.random_table_name()
299300
df.write.save_as_table(
300301
table_name_1,
@@ -316,6 +317,7 @@ def test_iceberg_partition_by(session, local_testing_mode):
316317
finally:
317318
session.table(table_name_1).drop_table()
318319

320+
# Test 2: Empty list
319321
table_name_2 = Utils.random_table_name()
320322
df.write.save_as_table(
321323
table_name_2,
@@ -331,6 +333,53 @@ def test_iceberg_partition_by(session, local_testing_mode):
331333
finally:
332334
session.table(table_name_2).drop_table()
333335

336+
# Test 3: Single Column object
337+
table_name_3 = Utils.random_table_name()
338+
df.write.save_as_table(
339+
table_name_3,
340+
iceberg_config={
341+
"external_volume": "PYTHON_CONNECTOR_ICEBERG_EXVOL",
342+
"catalog": "SNOWFLAKE",
343+
"partition_by": col("b"),
344+
},
345+
)
346+
try:
347+
ddl = session._run_query(f"select get_ddl('table', '{table_name_3}')")
348+
assert "PARTITION BY (B)" in ddl[0][0]
349+
finally:
350+
session.table(table_name_3).drop_table()
351+
352+
# Test 4: Mix of strings and Column objects with empty strings
353+
table_name_4 = Utils.random_table_name()
354+
df.write.save_as_table(
355+
table_name_4,
356+
iceberg_config={
357+
"external_volume": "PYTHON_CONNECTOR_ICEBERG_EXVOL",
358+
"catalog": "SNOWFLAKE",
359+
"partition_by": ["a", "", col("b")],
360+
},
361+
)
362+
try:
363+
ddl = session._run_query(f"select get_ddl('table', '{table_name_4}')")
364+
assert "PARTITION BY (A, B)" in ddl[0][0]
365+
finally:
366+
session.table(table_name_4).drop_table()
367+
368+
# Test 5: No partition_by
369+
table_name_5 = Utils.random_table_name()
370+
df.write.save_as_table(
371+
table_name_5,
372+
iceberg_config={
373+
"external_volume": "PYTHON_CONNECTOR_ICEBERG_EXVOL",
374+
"catalog": "SNOWFLAKE",
375+
},
376+
)
377+
try:
378+
ddl = session._run_query(f"select get_ddl('table', '{table_name_5}')")
379+
assert "PARTITION BY" not in ddl[0][0]
380+
finally:
381+
session.table(table_name_5).drop_table()
382+
334383

335384
@pytest.mark.skipif(
336385
"config.getoption('local_testing_mode', default=False)",

0 commit comments

Comments
 (0)