snowflake.snowpark.functions.to_file

snowflake.snowpark.functions.to_file(stage_file_uri: str) Column[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.29.1/snowpark-python/src/snowflake/snowpark/functions.py#L11575-L11612)

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["STAGE"]
'MYSTAGE'
>>> result["RELATIVE_PATH"]
'testCSV.csv'
>>> result["SIZE"]
32
>>> result["CONTENT_TYPE"]
'application/octet-stream'


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