diff --git a/CHANGELOG.md b/CHANGELOG.md index ef849d043db..212d4403392 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ #### Bug Fixes - Fixed a bug that caused NaT and NaN values to not be recognized. +- Fixed a bug when inferring schema, single quotes are added to stage files already have single quotes. + ## 1.15.0 (2024-04-24) diff --git a/src/snowflake/snowpark/_internal/analyzer/analyzer_utils.py b/src/snowflake/snowpark/_internal/analyzer/analyzer_utils.py index bff9921439d..7c08fd634e3 100644 --- a/src/snowflake/snowpark/_internal/analyzer/analyzer_utils.py +++ b/src/snowflake/snowpark/_internal/analyzer/analyzer_utils.py @@ -871,9 +871,7 @@ def infer_schema_statement(path: str, file_format_name: str) -> str: + LEFT_PARENTHESIS + LOCATION + RIGHT_ARROW - + SINGLE_QUOTE - + path - + SINGLE_QUOTE + + (path if is_single_quoted(path) else SINGLE_QUOTE + path + SINGLE_QUOTE) + COMMA + FILE_FORMAT + RIGHT_ARROW diff --git a/tests/integ/scala/test_dataframe_reader_suite.py b/tests/integ/scala/test_dataframe_reader_suite.py index ca1c17ca962..791dba2bcad 100644 --- a/tests/integ/scala/test_dataframe_reader_suite.py +++ b/tests/integ/scala/test_dataframe_reader_suite.py @@ -1412,3 +1412,18 @@ def test_filepath_not_exist_or_empty(session): f"Given path: '{not_exist_file_path}' could not be found or is empty." in str(ex_info) ) + + +def test_filepath_with_single_quote(session): + test_file_on_stage_with_quote = f"'@{tmp_stage_name1}/{test_file_csv}'" + test_file_on_stage = f"@{tmp_stage_name1}/{test_file_csv}" + result1 = ( + session.read.option("INFER_SCHEMA", True).csv(test_file_on_stage).collect() + ) + result2 = ( + session.read.option("INFER_SCHEMA", True) + .csv(test_file_on_stage_with_quote) + .collect() + ) + + assert result1 == result2