Skip to content

Commit 7ed7682

Browse files
authored
SNOW-1934035 add support for file (#2177)
1 parent ba15553 commit 7ed7682

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

DESCRIPTION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne
1717
- Fixed base64 encoded private key tests.
1818
- Added Wiremock tests.
1919
- Fixed a bug where file permission check happened on Windows
20+
- Added support for File types.
2021

2122
- v3.13.2(January 29, 2025)
2223
- Changed not to use scoped temporary objects.

src/snowflake/connector/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ def struct_pa_type(metadata: ResultMetadataV2) -> DataType:
182182
),
183183
FieldType(name="VECTOR", dbapi_type=[DBAPI_TYPE_BINARY], pa_type=vector_pa_type),
184184
FieldType(name="MAP", dbapi_type=[DBAPI_TYPE_BINARY], pa_type=map_pa_type),
185+
FieldType(
186+
name="FILE", dbapi_type=[DBAPI_TYPE_STRING], pa_type=lambda _: pa.string()
187+
),
185188
)
186189

187190
FIELD_NAME_TO_ID: DefaultDict[Any, int] = defaultdict(int)

test/integ/test_cursor.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,46 @@ def test_geometry(conn_cnx):
699699
assert row in expected_data
700700

701701

702+
@pytest.mark.skipolddriver
703+
def test_file(conn_cnx):
704+
"""Variant including JSON object."""
705+
name_file = random_string(5, "test_file_")
706+
with conn_cnx(
707+
session_parameters={
708+
"ENABLE_FILE_DATA_TYPE": True,
709+
},
710+
) as cnx:
711+
with cnx.cursor() as cur:
712+
cur.execute(
713+
f"create temporary table {name_file} as select "
714+
f"TO_FILE(OBJECT_CONSTRUCT('RELATIVE_PATH', 'some_new_file.jpeg', 'STAGE', '@myStage', "
715+
f"'STAGE_FILE_URL', 'some_new_file.jpeg', 'SIZE', 123, 'ETAG', 'xxx', 'CONTENT_TYPE', 'image/jpeg', "
716+
f"'LAST_MODIFIED', '2025-01-01')) as file_col"
717+
)
718+
719+
expected_data = [
720+
{
721+
"RELATIVE_PATH": "some_new_file.jpeg",
722+
"STAGE": "@myStage",
723+
"STAGE_FILE_URL": "some_new_file.jpeg",
724+
"SIZE": 123,
725+
"ETAG": "xxx",
726+
"CONTENT_TYPE": "image/jpeg",
727+
"LAST_MODIFIED": "2025-01-01",
728+
}
729+
]
730+
731+
with cnx.cursor() as cur:
732+
# Test with FILE return type
733+
result = cur.execute(f"select * from {name_file}")
734+
for metadata in [cur.description, cur._description_internal]:
735+
assert FIELD_ID_TO_NAME[metadata[0].type_code] == "FILE"
736+
data = result.fetchall()
737+
for raw_data in data:
738+
row = json.loads(raw_data[0])
739+
assert row in expected_data
740+
741+
702742
@pytest.mark.skipolddriver
703743
def test_vector(conn_cnx, is_public_test):
704744
if is_public_test:

0 commit comments

Comments
 (0)