snowflake.snowpark.functions.to_file¶

snowflake.snowpark.functions.to_file(stage_file_uri: Union[Column, None, bool, int, float, str, bytearray, Decimal, date, datetime, time, bytes, NaTType, float64, list, tuple, dict]) → Column[source]¶

Converts a stage file URI to a FILE value or NULL (if input is NULL), with the metadata related to the file.

Parameters:

stage_file_uri – The stage file URI to convert to a FILE value, e.g., @mystage/myfile.txt. It has to be a constant instead of a column expression.

Example:

>>> import json
>>> # Create a temp stage.
>>> _ = session.sql("create or replace temp stage mystage").collect()
>>> # Upload a file to a stage.
>>> r = session.file.put("tests/resources/testCSV.csv", "@mystage", auto_compress=False, overwrite=True)
>>> df = session.range(1).select(to_file("@mystage/testCSV.csv").alias("file"))
>>> result = json.loads(df.collect()[0][0])
>>> result["RELATIVE_PATH"]
'testCSV.csv'
>>> result["CONTENT_TYPE"]
'text/csv'


This function or method is in private preview since 1.29.0.
Copy