Skip to content

Commit 06709ec

Browse files
authored
SNOW-1952256: Add support for create_dataframe with FILE data type (#3322)
1 parent 424bb0f commit 06709ec

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#### Improvements
88

99
- Invoking snowflake system procedures does not invoke an additional `describe procedure` call to check the return type of the procedure.
10+
- Added support for `Session.create_dataframe()` with the stage URL and FILE data type.
1011

1112
#### Bug Fixes
1213

docs/source/snowpark/types.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This package contains all Snowpark logical types.
2020
DateType
2121
DecimalType
2222
DoubleType
23+
FileType
2324
FloatType
2425
Geography
2526
GeographyType

src/snowflake/snowpark/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3549,6 +3549,7 @@ def convert_row_to_list(
35493549
TimestampType,
35503550
VariantType,
35513551
VectorType,
3552+
FileType,
35523553
),
35533554
)
35543555
else field.datatype
@@ -3675,7 +3676,6 @@ def convert_row_to_list(
36753676
project_columns.append(
36763677
parse_json(column(name)).cast(field.datatype).as_(name)
36773678
)
3678-
# TODO SNOW-1952256: Test file type in create_dataframe once it accepts full path
36793679
elif isinstance(field.datatype, FileType):
36803680
project_columns.append(to_file(column(name)).as_(name))
36813681
else:

tests/integ/test_dataframe.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
when,
6666
)
6767
from snowflake.snowpark.types import (
68+
FileType,
6869
ArrayType,
6970
BinaryType,
7071
BooleanType,
@@ -5180,3 +5181,30 @@ def test_create_dataframe_x_string_y_integer(session):
51805181
Row(X="b", Y=2),
51815182
]
51825183
assert result == expected_rows
5184+
5185+
5186+
@pytest.mark.skipif(
5187+
"config.getoption('local_testing_mode', default=False)",
5188+
reason="File data type is not supported in Local Testing",
5189+
)
5190+
def test_create_dataframe_file_type(session, resources_path):
5191+
stage_name = Utils.random_name_for_temp_object(TempObjectType.STAGE)
5192+
session.sql(f"create or replace temp stage {stage_name}").collect()
5193+
test_files = TestFiles(resources_path)
5194+
session.file.put(
5195+
test_files.test_file_csv, f"@{stage_name}", auto_compress=False, overwrite=True
5196+
)
5197+
session.file.put(
5198+
test_files.test_dog_image, f"@{stage_name}", auto_compress=False, overwrite=True
5199+
)
5200+
csv_url = f"@{stage_name}/testCSV.csv"
5201+
image_url = f"@{stage_name}/dog.jpg"
5202+
df = session.create_dataframe(
5203+
[csv_url, image_url],
5204+
schema=StructType([StructField("col", FileType(), nullable=True)]),
5205+
)
5206+
result = df.collect()
5207+
csv_row = json.loads(result[0][0])
5208+
assert csv_row["CONTENT_TYPE"] == "text/csv"
5209+
image_row = json.loads(result[1][0])
5210+
assert image_row["CONTENT_TYPE"] == "image/jpeg"

tests/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,10 @@ def test_xxe_xml(self):
15541554
def test_nested_xml(self):
15551555
return os.path.join(self.resources_path, "nested.xml")
15561556

1557+
@property
1558+
def test_dog_image(self):
1559+
return os.path.join(self.resources_path, "dog.jpg")
1560+
15571561

15581562
class TypeMap(NamedTuple):
15591563
col_name: str

0 commit comments

Comments
 (0)