Skip to content

Commit

Permalink
fix(snowflake): use as_posix instead of as_uri to avoid escaping …
Browse files Browse the repository at this point in the history
…special characters (#10792)
  • Loading branch information
cpcloud authored Feb 5, 2025
1 parent fa4d958 commit ec41d4c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ibis/backends/clickhouse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def do_connect(
Examples
--------
>>> import ibis
>>> client = ibis.clickhouse.connect()
>>> client = ibis.clickhouse.connect(user="ibis")
>>> client
<ibis.backends.clickhouse.Backend object at 0x...>
"""
Expand Down
15 changes: 6 additions & 9 deletions ibis/backends/snowflake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,6 @@
}


def as_uri(path: str | Path) -> str:
"""Convert a path to a file URI."""
return Path(path).absolute().as_uri()


class Backend(SQLBackend, CanCreateCatalog, CanCreateDatabase):
name = "snowflake"
compiler = sc.snowflake.compiler
Expand Down Expand Up @@ -926,10 +921,12 @@ def read_csv(
urlretrieve(path, filename=tmpname) # noqa: S310
tmp.flush()
cur.execute(
f"PUT '{as_uri(tmpname)}' @{stage} PARALLEL = {threads:d}"
f"PUT 'file://{Path(tmpname).absolute().as_posix()}' @{stage} PARALLEL = {threads:d}"
)
else:
cur.execute(f"PUT '{as_uri(path)}' @{stage} PARALLEL = {threads:d}")
cur.execute(
f"PUT 'file://{Path(path).absolute().as_posix()}' @{stage} PARALLEL = {threads:d}"
)

# handle setting up the schema in python because snowflake is
# broken for csv globs: it cannot parse the result of the following
Expand Down Expand Up @@ -1055,7 +1052,7 @@ def read_json(
)
with self._safe_raw_sql(";\n".join(stmts)) as cur:
cur.execute(
f"PUT 'file://{Path(path).absolute()}' @{stage} PARALLEL = {threads:d}"
f"PUT 'file://{Path(path).absolute().as_posix()}' @{stage} PARALLEL = {threads:d}"
)
cur.execute(
";\n".join(
Expand Down Expand Up @@ -1104,7 +1101,7 @@ def read_parquet(

from ibis.formats.pyarrow import PyArrowSchema

abspath = Path(path).absolute()
abspath = Path(path).absolute().as_posix()
schema = PyArrowSchema.to_ibis(
ds.dataset(glob.glob(str(abspath)), format="parquet").schema
)
Expand Down

0 comments on commit ec41d4c

Please sign in to comment.