Skip to content

Commit 5d104b9

Browse files
sfc-gh-zlisfc-gh-pczajka
authored andcommitted
SNOW-1934035 add support for file (#2177)
1 parent 0fd4150 commit 5d104b9

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

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
@@ -722,6 +722,46 @@ def test_geometry(conn_cnx):
722722
assert row in expected_data
723723

724724

725+
@pytest.mark.skipolddriver
726+
def test_file(conn_cnx):
727+
"""Variant including JSON object."""
728+
name_file = random_string(5, "test_file_")
729+
with conn_cnx(
730+
session_parameters={
731+
"ENABLE_FILE_DATA_TYPE": True,
732+
},
733+
) as cnx:
734+
with cnx.cursor() as cur:
735+
cur.execute(
736+
f"create temporary table {name_file} as select "
737+
f"TO_FILE(OBJECT_CONSTRUCT('RELATIVE_PATH', 'some_new_file.jpeg', 'STAGE', '@myStage', "
738+
f"'STAGE_FILE_URL', 'some_new_file.jpeg', 'SIZE', 123, 'ETAG', 'xxx', 'CONTENT_TYPE', 'image/jpeg', "
739+
f"'LAST_MODIFIED', '2025-01-01')) as file_col"
740+
)
741+
742+
expected_data = [
743+
{
744+
"RELATIVE_PATH": "some_new_file.jpeg",
745+
"STAGE": "@myStage",
746+
"STAGE_FILE_URL": "some_new_file.jpeg",
747+
"SIZE": 123,
748+
"ETAG": "xxx",
749+
"CONTENT_TYPE": "image/jpeg",
750+
"LAST_MODIFIED": "2025-01-01",
751+
}
752+
]
753+
754+
with cnx.cursor() as cur:
755+
# Test with FILE return type
756+
result = cur.execute(f"select * from {name_file}")
757+
for metadata in [cur.description, cur._description_internal]:
758+
assert FIELD_ID_TO_NAME[metadata[0].type_code] == "FILE"
759+
data = result.fetchall()
760+
for raw_data in data:
761+
row = json.loads(raw_data[0])
762+
assert row in expected_data
763+
764+
725765
@pytest.mark.skipolddriver
726766
def test_vector(conn_cnx, is_public_test):
727767
if is_public_test:

0 commit comments

Comments
 (0)