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

fix(snowflake): use get instead of get_path; get_path does not support columns with spaces #10836

Merged
merged 2 commits into from
Feb 13, 2025
Merged
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
13 changes: 5 additions & 8 deletions ibis/backends/snowflake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,15 +1126,14 @@

type_mapper = self.compiler.type_mapper

dialect = self.dialect

Check warning on line 1129 in ibis/backends/snowflake/__init__.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/snowflake/__init__.py#L1129

Added line #L1129 was not covered by tests
stmts = [
f"CREATE TEMP STAGE {stage} FILE_FORMAT = (TYPE = PARQUET {options})",
sge.Create(
kind="TABLE",
this=sge.Schema(
this=qtable, expressions=schema.to_sqlglot(self.dialect)
),
this=sge.Schema(this=qtable, expressions=schema.to_sqlglot(dialect)),
properties=sge.Properties(expressions=[sge.TemporaryProperty()]),
).sql(self.dialect),
).sql(dialect),
]

query = ";\n".join(stmts)
Expand All @@ -1144,7 +1143,7 @@
sg.select(
*(
sg.cast(
self.compiler.f.get_path(param, sge.convert(col)),
self.compiler.f.get(param, sge.convert(col)),
type_mapper.from_ibis(typ),
)
for col, typ in schema.items()
Expand All @@ -1153,9 +1152,7 @@
.from_(sge.Table(this=sge.Var(this=f"@{stage}")))
.subquery()
)
copy_query = sge.Copy(this=qtable, kind=True, files=[copy_select]).sql(
self.dialect
)
copy_query = sge.Copy(this=qtable, kind=True, files=[copy_select]).sql(dialect)

Check warning on line 1155 in ibis/backends/snowflake/__init__.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/snowflake/__init__.py#L1155

Added line #L1155 was not covered by tests
with self._safe_raw_sql(query) as cur:
cur.execute(f"PUT 'file://{abspath}' @{stage} PARALLEL = {threads:d}")
cur.execute(copy_query)
Expand Down
15 changes: 15 additions & 0 deletions ibis/backends/snowflake/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import os
from collections import Counter

import hypothesis as h
import hypothesis.strategies as st
import pandas as pd
import pandas.testing as tm
import pyarrow as pa
Expand Down Expand Up @@ -436,3 +438,16 @@ def test_insert_dict_variants(con):

con.insert(name, ibis.memtable(data))
assert len(t.execute()) == 4


@h.given(
column_name=st.text(
st.characters(exclude_characters="\x00"), min_size=1, max_size=255
)
)
def test_fancy_column_names(con, column_name):
name = gen_name("test_fancy_column_names")
testdf = pd.DataFrame({column_name: [1, 2, 3]})
t = con.create_table(name, obj=testdf, temp=True)
assert t.columns == (column_name,)
assert t.count().execute() == 3