Skip to content

Commit

Permalink
SNOW-950417 fix quoted name matching for new lines (#1125)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-mkeller authored Nov 13, 2023
1 parent 2e36e3c commit 3ca5f76
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/snowflake/snowpark/_internal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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$]*)$")


Expand Down
17 changes: 17 additions & 0 deletions tests/integ/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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)

0 comments on commit 3ca5f76

Please sign in to comment.