Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test 342 #346

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/snowflake/sqlalchemy/snowdialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ def _has_object(self, connection, object_type, object_name, schema=None):
def normalize_name(self, name):
if name is None:
return None
if name == "":
return ""
if name.upper() == name and not self.identifier_preparer._requires_quotes(
name.lower()
):
Expand All @@ -264,6 +266,8 @@ def normalize_name(self, name):
def denormalize_name(self, name):
if name is None:
return None
if name == "":
return ""
elif name.lower() == name and not self.identifier_preparer._requires_quotes(
name.lower()
):
Expand Down
42 changes: 42 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1718,3 +1718,45 @@ def test_result_type_and_value(engine_testaccount):
assert data is not None
data = json.loads(results[-1][29])
assert data[1]["k"] == 2


def test_normalize_and_denormalize_empty_string_column_name(engine_testaccount):
with engine_testaccount.connect() as conn:
table_name = random_string(5)
conn.exec_driver_sql(
f"""
CREATE OR REPLACE TEMP TABLE {table_name}
(EMPID INT, DEPT TEXT, JAN INT, FEB INT)
"""
)
conn.exec_driver_sql(
f"""
INSERT INTO {table_name} VALUES
(1, 'ELECTRONICS', 100, 200),
(2, 'CLOTHES', 100, 300)
"""
)
results = conn.exec_driver_sql(
f"""
SELECT * FROM {table_name} UNPIVOT(SALES FOR "" IN (JAN, FEB)) ORDER BY EMPID;"""
).fetchall() # normalize_name will be called
assert results == [
(1, "electronics", "JAN", 100),
(1, "electronics", "FEB", 200),
(2, "clothes", "JAN", 100),
(2, "clothes", "FEB", 300),
]

conn.exec_driver_sql(
f"""
CREATE OR REPLACE TEMP TABLE {table_name}
(COL INT, "" INT)
"""
)
inspector = inspect(conn)
columns = inspector.get_columns(table_name) # denormalize_name will be called
assert (
len(columns) == 2
and columns[0]["name"] == "col"
and columns[1]["name"] == ""
)