From 3ca5f7654e333cb9611cc1a23357fa3d5257c3f2 Mon Sep 17 00:00:00 2001 From: Mark Keller Date: Mon, 13 Nov 2023 17:17:05 +0000 Subject: [PATCH] SNOW-950417 fix quoted name matching for new lines (#1125) --- CHANGELOG.md | 6 ++++++ src/snowflake/snowpark/_internal/utils.py | 3 ++- tests/integ/test_dataframe.py | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9231212f625..eea76a2ca68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 1.10.1 (TBD) + +### Bug Fixes + +- DataFrame column names qouting check now supports newline characters. + ## 1.10.0 (2023-11-03) ### New Features diff --git a/src/snowflake/snowpark/_internal/utils.py b/src/snowflake/snowpark/_internal/utils.py index 6105a633254..a104181acaf 100644 --- a/src/snowflake/snowpark/_internal/utils.py +++ b/src/snowflake/snowpark/_internal/utils.py @@ -795,7 +795,8 @@ def parse_table_name(table_name: str) -> List[str]: EMPTY_STRING = "" DOUBLE_QUOTE = '"' -ALREADY_QUOTED = re.compile('^(".+")$') +# Quoted values may also include newlines, so '.' must match _everything_ within quotes +ALREADY_QUOTED = re.compile('^(".+")$', re.DOTALL) UNQUOTED_CASE_INSENSITIVE = re.compile("^([_A-Za-z]+[_A-Za-z0-9$]*)$") diff --git a/tests/integ/test_dataframe.py b/tests/integ/test_dataframe.py index d9c9dae725e..bf746e66258 100644 --- a/tests/integ/test_dataframe.py +++ b/tests/integ/test_dataframe.py @@ -1958,6 +1958,7 @@ def test_case_insensitive_collect(session): assert row["p@$$w0rd"] == "test" assert row["P@$$W0RD"] == "test" + def test_case_insensitive_local_iterator(session): df = session.create_dataframe( [["Gordon", 153]], schema=["firstname", "matches_won"] @@ -3322,3 +3323,19 @@ def test_select_star_and_more_columns(session): Utils.check_answer(df2, [Row(1, 2, 3)]) df3 = df2.select("a", "b", "c") Utils.check_answer(df3, [Row(1, 2, 3)]) + + +def test_drop_columns_special_names(session): + """Test whether columns with newlines can be dropped.""" + table_name = Utils.random_table_name() + Utils.create_table( + session, table_name, '"a\nb" string, id number', is_temporary=True + ) + session._conn.run_query(f"insert into {table_name} values ('a', 1), ('b', 2)") + df = session.table(table_name) + try: + Utils.check_answer(df, [Row("a", 1), Row("b", 2)]) + df2 = df.drop('"a\nb"') + Utils.check_answer(df2, [Row(1), Row(2)]) + finally: + Utils.drop_table(session, table_name)