Skip to content

Commit 2e44cc0

Browse files
authored
SNOW-2364008: Remove unnecessary warning for XML reader and xpath function (#3812)
1 parent d14f99e commit 2e44cc0

11 files changed

Lines changed: 94 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787

8888
#### Improvements
8989

90+
- Removed unnecessary warnings about local package version mismatch when using `session.read.option('rowTag', <tag_name>).xml(<stage_file_path>)` or `xpath` functions.
9091
- Improved `DataFrameReader.dbapi` (PuPr) reading performance by setting the default `fetch_size` parameter value to 100000.
9192
- Improved error message for XSD validation failure when reading XML files using `session.read.option('rowValidationXSDPath', <xsd_path>).xml(<stage_file_path>)`.
9293

src/snowflake/snowpark/_internal/udf_utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@ def resolve_imports_and_packages(
11341134
skip_upload_on_content_match: bool = False,
11351135
is_permanent: bool = False,
11361136
force_inline_code: bool = False,
1137+
**kwargs,
11371138
) -> Tuple[
11381139
Optional[str],
11391140
Optional[str],
@@ -1167,6 +1168,9 @@ def resolve_imports_and_packages(
11671168
packages,
11681169
include_pandas=is_pandas_udf,
11691170
statement_params=statement_params,
1171+
_suppress_local_package_warnings=kwargs.get(
1172+
"_suppress_local_package_warnings", False
1173+
),
11701174
)
11711175
if packages is not None
11721176
else session._resolve_packages(
@@ -1175,6 +1179,9 @@ def resolve_imports_and_packages(
11751179
validate_package=False,
11761180
include_pandas=is_pandas_udf,
11771181
statement_params=statement_params,
1182+
_suppress_local_package_warnings=kwargs.get(
1183+
"_suppress_local_package_warnings", False
1184+
),
11781185
)
11791186
)
11801187

src/snowflake/snowpark/dataframe_reader.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,11 +1407,6 @@ def _read_semi_structured_file(self, path: str, format: str) -> DataFrame:
14071407
metadata_project, metadata_schema = self._get_metadata_project_and_schema()
14081408

14091409
if format == "XML" and XML_ROW_TAG_STRING in self._cur_options:
1410-
warning(
1411-
"rowTag",
1412-
"rowTag for reading XML file is in private preview since 1.31.0. Do not use it in production.",
1413-
)
1414-
14151410
if is_in_stored_procedure(): # pragma: no cover
14161411
# create a temp stage for udtf import files
14171412
# we have to use "temp" object instead of "scoped temp" object in stored procedure
@@ -1447,6 +1442,7 @@ def _read_semi_structured_file(self, path: str, format: str) -> DataFrame:
14471442
input_types=input_types,
14481443
packages=["snowflake-snowpark-python", "lxml<6"],
14491444
replace=True,
1445+
_suppress_local_package_warnings=True,
14501446
)
14511447
else:
14521448
xml_reader_udtf = None

src/snowflake/snowpark/session.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,7 @@ def _get_dependency_packages(
18841884
package_table: str,
18851885
current_packages: Dict[str, str],
18861886
statement_params: Optional[Dict[str, str]] = None,
1887+
suppress_local_package_warnings: bool = False,
18871888
) -> List[Requirement]:
18881889
# Keep track of any package errors
18891890
errors = []
@@ -1979,24 +1980,27 @@ def is_valid_version(
19791980
if not is_valid_version(
19801981
package_name, package_client_version, valid_packages
19811982
):
1983+
if not suppress_local_package_warnings:
1984+
_logger.warning(
1985+
f"The version of package '{package_name}' in the local environment is "
1986+
f"{package_client_version}, which does not fit the criteria for the "
1987+
f"requirement '{package}'. Your UDF might not work when the package version "
1988+
f"is different between the server and your local environment."
1989+
)
1990+
except importlib.metadata.PackageNotFoundError:
1991+
if not suppress_local_package_warnings:
19821992
_logger.warning(
1983-
f"The version of package '{package_name}' in the local environment is "
1984-
f"{package_client_version}, which does not fit the criteria for the "
1985-
f"requirement '{package}'. Your UDF might not work when the package version "
1986-
f"is different between the server and your local environment."
1993+
f"Package '{package_name}' is not installed in the local environment. "
1994+
f"Your UDF might not work when the package is installed on the server "
1995+
f"but not on your local environment."
19871996
)
1988-
except importlib.metadata.PackageNotFoundError:
1989-
_logger.warning(
1990-
f"Package '{package_name}' is not installed in the local environment. "
1991-
f"Your UDF might not work when the package is installed on the server "
1992-
f"but not on your local environment."
1993-
)
19941997
except Exception as ex: # pragma: no cover
1995-
_logger.warning(
1996-
"Failed to get the local distribution of package %s: %s",
1997-
package_name,
1998-
ex,
1999-
)
1998+
if not suppress_local_package_warnings:
1999+
_logger.warning(
2000+
"Failed to get the local distribution of package %s: %s",
2001+
package_name,
2002+
ex,
2003+
)
20002004

20012005
if package_name in current_packages:
20022006
if current_packages[package_name] != package:
@@ -2071,6 +2075,7 @@ def _resolve_packages(
20712075
include_pandas: bool = False,
20722076
statement_params: Optional[Dict[str, str]] = None,
20732077
artifact_repository: Optional[str] = None,
2078+
**kwargs,
20742079
) -> List[str]:
20752080
"""
20762081
Given a list of packages to add, this method will
@@ -2154,6 +2159,9 @@ def _resolve_packages(
21542159
package_table,
21552160
result_dict,
21562161
statement_params=statement_params,
2162+
suppress_local_package_warnings=kwargs.get(
2163+
"_suppress_local_package_warnings", False
2164+
),
21572165
)
21582166

21592167
# Add dependency packages
@@ -4802,6 +4810,7 @@ def _get_or_register_xpath_udf(
48024810
packages=["snowflake-snowpark-python", "lxml<6"],
48034811
replace=True,
48044812
_emit_ast=False,
4813+
_suppress_local_package_warnings=True,
48054814
)
48064815

48074816
self._xpath_udf_cache[cache_key] = xpath_udf

src/snowflake/snowpark/stored_procedure.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,7 @@ def _do_register_sp(
955955
is_permanent=is_permanent,
956956
force_inline_code=force_inline_code,
957957
artifact_repository=artifact_repository,
958+
**kwargs,
958959
)
959960

960961
runtime_version_from_requirement = None

src/snowflake/snowpark/udaf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,7 @@ def _do_register_udaf(
799799
skip_upload_on_content_match=skip_upload_on_content_match,
800800
is_permanent=is_permanent,
801801
artifact_repository=artifact_repository,
802+
**kwargs,
802803
)
803804

804805
runtime_version_from_requirement = None

src/snowflake/snowpark/udf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,7 @@ def _do_register_udf(
994994
skip_upload_on_content_match=skip_upload_on_content_match,
995995
is_permanent=is_permanent,
996996
artifact_repository=artifact_repository,
997+
**kwargs,
997998
)
998999

9991000
runtime_version_from_requirement = None

src/snowflake/snowpark/udtf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,7 @@ def _do_register_udtf(
10561056
skip_upload_on_content_match=skip_upload_on_content_match,
10571057
is_permanent=is_permanent,
10581058
artifact_repository=artifact_repository,
1059+
**kwargs,
10591060
)
10601061

10611062
runtime_version_from_requirement = None

tests/integ/test_xml_reader_row_tag.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) 2012-2025 Snowflake Computing Inc. All rights reserved.
33
#
44

5+
import logging
56
import json
67
import pytest
78

@@ -398,6 +399,19 @@ def test_read_xml_ignore_surrounding_whitespace(
398399
Utils.check_answer(df, [expected_row])
399400

400401

402+
def test_read_xml_warning_local_package(session, caplog):
403+
row_tag = "book"
404+
caplog.clear()
405+
with caplog.at_level(logging.WARNING):
406+
session.read.option("rowTag", row_tag).xml(
407+
f"@{tmp_stage_name}/{test_file_books_xml}"
408+
)
409+
assert (
410+
"Your UDF might not work when the package version is different between the server and your local environment"
411+
not in caplog.text
412+
)
413+
414+
401415
def test_read_xml_row_validation_xsd_path(session):
402416
row_tag = "book"
403417
df = (

tests/integ/test_xpath.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Copyright (c) 2012-2025 Snowflake Computing Inc. All rights reserved.
44
#
55

6+
import logging
67
import json
78
import pytest
89

@@ -329,3 +330,16 @@ def test_xpath_return_types(session):
329330
assert isinstance(schema["BOOL_COL"].datatype, BooleanType)
330331
assert isinstance(schema["FLOAT_COL"].datatype, DoubleType)
331332
assert isinstance(schema["INT_COL"].datatype, LongType)
333+
334+
335+
def test_xpath_warning_local_package(session, caplog):
336+
caplog.clear()
337+
with caplog.at_level(logging.WARNING):
338+
df = session.create_dataframe(
339+
[["<root><a>1</a><a>2</a><a>3</a></root>"]], schema=["xml"]
340+
)
341+
df.select(xpath("xml", "//a/text()").alias("values")).collect()
342+
assert (
343+
"Your UDF might not work when the package version is different between the server and your local environment"
344+
not in caplog.text
345+
)

0 commit comments

Comments
 (0)