Skip to content

Commit 3f6a973

Browse files
authored
SNOW-2362488: Improve the error message of XSD validation when mode=failfast (#3810)
1 parent 3db0617 commit 3f6a973

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

CHANGELOG.md

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

8989
- Improved `DataFrameReader.dbapi` (PuPr) reading performance by setting the default `fetch_size` parameter value to 100000.
90+
- Improved error message for XSD validation failure when reading XML files using `session.read.option('rowValidationXSDPath', <xsd_path>).xml(<stage_file_path>)`.
9091

9192
### Snowpark pandas API Updates
9293

src/snowflake/snowpark/_internal/xml_reader.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,8 @@ def process_xml_range(
503503
yield {column_name_of_corrupt_record: record_str}
504504
elif mode == "FAILFAST":
505505
raise RuntimeError(
506-
f"Malformed XML record at bytes {record_start}-{record_end}: {e}"
506+
f"Malformed XML record at bytes {record_start}-{record_end}: {e}\n"
507+
f"XML record string: {record_str}"
507508
)
508509

509510
if record_end > approx_end:

tests/integ/test_xml_reader_row_tag.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,3 +416,11 @@ def test_read_xml_row_validation_xsd_path(session):
416416
assert result[0]["'price'"] == '"44.95"'
417417
assert result[0]["'publish_date'"] == '"2000-10-01"'
418418
assert result[0]["'_id'"] == '"bk101"'
419+
420+
421+
def test_read_xml_row_validation_xsd_path_failfast(session):
422+
row_tag = "book"
423+
with pytest.raises(SnowparkSQLException, match="XML record string:"):
424+
session.read.option("rowTag", row_tag).option(
425+
"rowValidationXSDPath", f"@{tmp_stage_name}/{test_file_books_xsd}"
426+
).option("mode", "failfast").xml(f"@{tmp_stage_name}/{test_file_books_xml}")

0 commit comments

Comments
 (0)