Skip to content

Commit 72752eb

Browse files
IndexSeekcpcloud
authored andcommitted
feat(snowflake): read_csv with https
1 parent 233dce1 commit 72752eb

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

ibis/backends/snowflake/__init__.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import warnings
1818
from pathlib import Path
1919
from typing import TYPE_CHECKING, Any
20+
from urllib.request import urlretrieve
2021

2122
import pyarrow as pa
2223
import pyarrow_hotfix # noqa: F401
@@ -777,10 +778,17 @@ def read_csv(
777778
)
778779
con.exec_driver_sql(create_infer_fmt)
779780

780-
# copy the local file to the stage
781-
con.exec_driver_sql(
782-
f"PUT 'file://{Path(path).absolute()}' @{stage} PARALLEL = {threads:d}"
783-
)
781+
if path.startswith("https://"):
782+
with tempfile.NamedTemporaryFile() as tmp:
783+
urlretrieve(path, filename=tmp.name)
784+
tmp.flush()
785+
con.exec_driver_sql(
786+
f"PUT 'file://{tmp.name}' @{stage} PARALLEL = {threads:d} AUTO_COMPRESS = TRUE"
787+
)
788+
else:
789+
con.exec_driver_sql(
790+
f"PUT 'file://{Path(path).absolute()}' @{stage} PARALLEL = {threads:d} AUTO_COMPRESS = TRUE"
791+
)
784792

785793
# handle setting up the schema in python because snowflake is
786794
# broken for csv globs: it cannot parse the result of the following

ibis/backends/snowflake/tests/test_client.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,22 @@ def test_read_csv_options(con, tmp_path):
197197
assert t.schema() == ibis.schema(dict(a="int64", b="int64"))
198198

199199

200+
def test_read_csv_https(con):
201+
t = con.read_csv(
202+
"https://storage.googleapis.com/ibis-tutorial-data/wowah_data/locations.csv",
203+
field_optionally_enclosed_by='"',
204+
)
205+
assert t.schema() == ibis.schema(
206+
{
207+
"Map_ID": "int64",
208+
"Location_Type": "string",
209+
"Location_Name": "string",
210+
"Game_Version": "string",
211+
}
212+
)
213+
assert t.count().execute() == 151
214+
215+
200216
@pytest.fixture(scope="module")
201217
def json_data():
202218
return [

0 commit comments

Comments
 (0)